59 lines
1.3 KiB
TypeScript
59 lines
1.3 KiB
TypeScript
/**
|
|
* auth.repository.impl.ts
|
|
* AuthRepositoryImpl: implementación real del AuthRepository.
|
|
* Aquí es donde hablamos con la base de datos usando Prisma.
|
|
*/
|
|
|
|
import { AuthRepository } from "../../domain/repositories/auth.repository.js";
|
|
import { prisma } from "../postgres/index.js";
|
|
|
|
export class AuthRepositoryImpl implements AuthRepository {
|
|
async findByEmail(email: string) {
|
|
return prisma.user.findUnique({
|
|
where: { email },
|
|
select: {
|
|
id: true,
|
|
email: true,
|
|
password: true,
|
|
name: true,
|
|
role: true,
|
|
},
|
|
});
|
|
}
|
|
|
|
async create(data: {
|
|
name: string;
|
|
email: string;
|
|
password: string;
|
|
role?: string;
|
|
}) {
|
|
return prisma.user.create({
|
|
data: {
|
|
name: data.name,
|
|
email: data.email,
|
|
password: data.password,
|
|
// role solo si fue pasado explícitamente; default = USER (en Prisma)
|
|
...(data.role ? { role: data.role as "USER" | "ADMIN" } : {}),
|
|
},
|
|
select: {
|
|
id: true,
|
|
email: true,
|
|
name: true,
|
|
role: true,
|
|
},
|
|
});
|
|
}
|
|
|
|
async findById(id: number) {
|
|
return prisma.user.findUnique({
|
|
where: { id },
|
|
select: {
|
|
id: true,
|
|
email: true,
|
|
name: true,
|
|
role: true,
|
|
},
|
|
});
|
|
}
|
|
}
|