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
+94
View File
@@ -0,0 +1,94 @@
import { Injectable } from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
@Injectable()
export class ServicesService {
constructor(private prisma: PrismaService) {}
create(data: {
professional_id: string;
user_id: string;
day: string;
description?: string;
rate?: number;
range1_hour1?: string;
range1_hour2?: string;
address?: string;
latitude?: number;
longitude?: number;
location_preference?: 'office' | 'delivery';
}) {
return this.prisma.services.create({ data: { ...data, day: new Date(data.day) } as any });
}
findByUser(userId: string) {
return this.prisma.services.findMany({
where: { user_id: userId },
include: { professionals: { include: { users: true } } },
orderBy: { created_at: 'desc' },
});
}
findByProfessional(professionalId: string) {
return this.prisma.services.findMany({
where: { professional_id: professionalId },
include: { users: { select: { id: true, name: true, picture: true, phone: true } } },
orderBy: { created_at: 'desc' },
});
}
findRequestsByProfessional(professionalId: string) {
return this.prisma.services.findMany({
where: { professional_id: professionalId, status: 'pending' },
include: { users: { select: { id: true, name: true, picture: true, phone: true } } },
orderBy: { created_at: 'desc' },
});
}
updateStatus(id: string, status: string) {
return this.prisma.services.update({ where: { id }, data: { status: status as any } });
}
findById(id: string) {
return this.prisma.services.findUnique({
where: { id },
include: {
users: { select: { id: true, name: true, picture: true, phone: true } },
professionals: { include: { users: true } },
},
});
}
getHistoryByUser(userId: string) {
return this.prisma.services.findMany({
where: { user_id: userId, status: { in: ['completed', 'cancelled'] } },
include: { professionals: { include: { users: true } } },
orderBy: { day: 'desc' },
});
}
getHistoryByProfessional(professionalId: string) {
return this.prisma.services.findMany({
where: { professional_id: professionalId, status: { in: ['completed', 'cancelled'] } },
include: { users: { select: { id: true, name: true, picture: true } } },
orderBy: { day: 'desc' },
});
}
getCalendarByProfessional(professionalId: string) {
return this.prisma.services.findMany({
where: { professional_id: professionalId, status: { notIn: ['denied', 'cancelled'] } },
orderBy: { day: 'asc' },
});
}
async getPublicCalendar(professionalId: string) {
const schedules = await this.prisma.schedules.findMany({
where: { professional_id: professionalId, enabled: true },
});
const services = await this.prisma.services.findMany({
where: { professional_id: professionalId, status: { notIn: ['denied', 'cancelled'] } },
});
return { schedules, services };
}
}