feat: backend API NestJS + Prisma + JWT auth + todos los módulos

This commit is contained in:
Lizandro Guarnizo
2026-06-01 21:23:04 -05:00
parent b31f778b3b
commit 3c5d81603a
69 changed files with 35734 additions and 0 deletions
@@ -0,0 +1,80 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
@Injectable()
export class ProfessionalsService {
constructor(private prisma: PrismaService) {}
findAllActive() {
return this.prisma.professionals.findMany({
where: { is_active: true },
include: {
users: { select: { id: true, name: true, picture: true, city: true } },
schedules: true,
specializations: true,
payment_methods: true,
},
});
}
findById(id: string) {
return this.prisma.professionals.findUnique({
where: { id },
include: {
users: { select: { id: true, name: true, picture: true, city: true } },
schedules: { orderBy: { day_of_week: 'asc' } },
specializations: true,
payment_methods: true,
},
});
}
findByUserId(userId: string) {
return this.prisma.professionals.findUnique({
where: { user_id: userId },
include: { schedules: true, specializations: true, payment_methods: true },
});
}
async upsert(userId: string, data: any) {
const existing = await this.prisma.professionals.findUnique({ where: { user_id: userId } });
if (existing) {
return this.prisma.professionals.update({ where: { user_id: userId }, data });
}
return this.prisma.professionals.create({ data: { ...data, user_id: userId } });
}
async updateSchedules(professionalId: string, schedules: any[]) {
await this.prisma.schedules.deleteMany({ where: { professional_id: professionalId } });
return this.prisma.schedules.createMany({
data: schedules.map((s: any) => ({
professional_id: professionalId,
day_of_week: s.day_of_week,
enabled: s.enabled,
continuous_day: s.continuous_day,
range1_hour1: s.range1_hour1,
range1_hour2: s.range1_hour2,
range2_hour1: s.range2_hour1,
range2_hour2: s.range2_hour2,
})),
});
}
async requestProfessional(userId: string, data: any) {
const existing = await this.prisma.professionals.findUnique({ where: { user_id: userId } });
if (existing) throw new Error('Ya tienes una solicitud de profesional');
await this.prisma.users.update({ where: { id: userId }, data: { pro_state: 1 } });
return this.prisma.professionals.create({
data: {
user_id: userId,
identification: data.identification,
profession: data.profession,
address: data.address,
identification_picture: data.identification_picture,
certificate_picture: data.certificate_picture,
},
});
}
}