aboutsummaryrefslogtreecommitdiff
path: root/api/src/modules/auth/auth.repository.ts
diff options
context:
space:
mode:
authorzwlucas <lucas.fariamo08@gmail.com>2026-07-25 21:23:29 +0000
committerzwlucas <lucas.fariamo08@gmail.com>2026-07-25 21:23:29 +0000
commitef55d9bb24430610b60c1b77821307cd72c08c55 (patch)
treee6935a810b34370b0a4c821e55f6397aac50c832 /api/src/modules/auth/auth.repository.ts
downloadhelpdesk-master.tar.gz
helpdesk-master.zip
feat: upload of the projectHEADmaster
Signed-off-by: zwlucas <lucas.fariamo08@gmail.com>
Diffstat (limited to 'api/src/modules/auth/auth.repository.ts')
-rw-r--r--api/src/modules/auth/auth.repository.ts68
1 files changed, 68 insertions, 0 deletions
diff --git a/api/src/modules/auth/auth.repository.ts b/api/src/modules/auth/auth.repository.ts
new file mode 100644
index 0000000..25a931b
--- /dev/null
+++ b/api/src/modules/auth/auth.repository.ts
@@ -0,0 +1,68 @@
+/**
+ * auth.repository.ts
+ * Queries de banco exclusivas do módulo de autenticação.
+ */
+
+import { eq } from 'drizzle-orm';
+import type { Database } from '@/db/connection.js';
+import { users, type NewUser } from '@/db/schema.js';
+
+// ─── Busca com senha (apenas para verificação no login) ───────────────────────
+
+export async function findUserByEmail(db: Database, email: string) {
+ const [user] = await db
+ .select()
+ .from(users)
+ .where(eq(users.email, email))
+ .limit(1);
+
+ return user ?? null;
+}
+
+// ─── Busca segura (sem password) ──────────────────────────────────────────────
+
+export async function findUserById(db: Database, id: number) {
+ const [user] = await db
+ .select({
+ id: users.id,
+ name: users.name,
+ email: users.email,
+ role: users.role,
+ isActive: users.isActive,
+ createdAt: users.createdAt,
+ updatedAt: users.updatedAt,
+ })
+ .from(users)
+ .where(eq(users.id, id))
+ .limit(1);
+
+ return user ?? null;
+}
+
+// ─── Criação de usuário ───────────────────────────────────────────────────────
+
+export async function createUser(
+ db: Database,
+ data: Pick<NewUser, 'name' | 'email' | 'password' | 'role'>,
+) {
+ const now = new Date().toISOString();
+
+ const [user] = await db
+ .insert(users)
+ .values({
+ ...data,
+ isActive: true,
+ createdAt: now,
+ updatedAt: now,
+ })
+ .returning({
+ id: users.id,
+ name: users.name,
+ email: users.email,
+ role: users.role,
+ isActive: users.isActive,
+ createdAt: users.createdAt,
+ });
+
+ return user!;
+}