Files
scoreodonto.com/backend/dist/modules/auth/auth.repository.js
T

53 lines
1.6 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AuthRepository = void 0;
const prisma_1 = require("../../infra/database/prisma");
class AuthRepository {
async findByEmail(email) {
return prisma_1.prisma.user.findUnique({ where: { email } });
}
async findById(id) {
return prisma_1.prisma.user.findUnique({
where: { id },
select: {
id: true,
name: true,
email: true,
role: true,
isActive: true,
planId: true,
trialEndsAt: true,
createdAt: true,
},
});
}
async create(data) {
return prisma_1.prisma.user.create({
data: {
name: data.name,
email: data.email,
passwordHash: data.passwordHash,
role: data.role ?? 'USER',
planId: data.planId,
trialEndsAt: new Date(Date.now() + 14 * 24 * 60 * 60 * 1000), // 14 dias de trial
},
select: {
id: true,
name: true,
email: true,
role: true,
planId: true,
trialEndsAt: true,
createdAt: true,
},
});
}
async updatePassword(id, passwordHash) {
return prisma_1.prisma.user.update({ where: { id }, data: { passwordHash } });
}
async setActive(id, isActive) {
return prisma_1.prisma.user.update({ where: { id }, data: { isActive } });
}
}
exports.AuthRepository = AuthRepository;