full project: admin panel, backend modules, docs
This commit is contained in:
@@ -16,7 +16,7 @@ export class AuthService {
|
||||
|
||||
const password_hash = await bcrypt.hash(password, 10);
|
||||
const user = await this.prisma.users.create({
|
||||
data: { email, password_hash, name, is_email_verified: true },
|
||||
data: { email, password_hash, name },
|
||||
});
|
||||
|
||||
return this.generateToken(user);
|
||||
@@ -36,14 +36,36 @@ export class AuthService {
|
||||
let user = await this.prisma.users.findUnique({ where: { phone } });
|
||||
if (!user) {
|
||||
user = await this.prisma.users.create({
|
||||
data: { phone, name: name || phone, is_phone_verified: true },
|
||||
data: { phone, name: name || phone },
|
||||
});
|
||||
}
|
||||
return this.generateToken(user);
|
||||
}
|
||||
|
||||
async verifyOtpAndLinkPhone(userId: string, phone: string) {
|
||||
const existing = await this.prisma.users.findUnique({ where: { phone } });
|
||||
if (existing && existing.id !== userId) {
|
||||
throw new ConflictException('Teléfono ya registrado por otro usuario');
|
||||
}
|
||||
return this.prisma.users.update({
|
||||
where: { id: userId },
|
||||
data: { phone, is_phone_verified: true },
|
||||
});
|
||||
}
|
||||
|
||||
async linkEmail(userId: string, email: string, password: string) {
|
||||
const existing = await this.prisma.users.findUnique({ where: { email } });
|
||||
if (existing) throw new ConflictException('Email ya registrado');
|
||||
|
||||
const password_hash = await bcrypt.hash(password, 10);
|
||||
return this.prisma.users.update({
|
||||
where: { id: userId },
|
||||
data: { email, password_hash },
|
||||
});
|
||||
}
|
||||
|
||||
async me(userId: string) {
|
||||
return this.prisma.users.findUnique({
|
||||
const user = await this.prisma.users.findUnique({
|
||||
where: { id: userId },
|
||||
include: {
|
||||
professionals: {
|
||||
@@ -52,6 +74,13 @@ export class AuthService {
|
||||
reputations: true,
|
||||
},
|
||||
});
|
||||
if (!user) throw new UnauthorizedException('Usuario no encontrado');
|
||||
return user;
|
||||
}
|
||||
|
||||
async getProfessionalId(userId: string): Promise<string | null> {
|
||||
const prof = await this.prisma.professionals.findUnique({ where: { user_id: userId } });
|
||||
return prof?.id || null;
|
||||
}
|
||||
|
||||
private generateToken(user: any) {
|
||||
|
||||
Reference in New Issue
Block a user