diff --git a/backend/src/services/services.service.ts b/backend/src/services/services.service.ts index ed82b07..0bd9cec 100644 --- a/backend/src/services/services.service.ts +++ b/backend/src/services/services.service.ts @@ -80,7 +80,7 @@ export class ServicesService { if (!inRange) throw new BadRequestException('La hora seleccionada está fuera del horario del profesional'); } - return this.prisma.services.create({ + const created = await this.prisma.services.create({ data: { professional_id: prof.id, user_id: data.user_id, @@ -95,6 +95,21 @@ export class ServicesService { location_preference: data.location_preference as any, }, }); + + // Notify the professional of the new service request + const profUser = await this.prisma.users.findUnique({ + where: { id: prof.user_id }, + select: { fcm_token: true }, + }); + if (profUser?.fcm_token) { + this.notifications.send( + profUser.fcm_token, + 'Nueva solicitud de servicio', + 'Tienes una nueva solicitud pendiente de un cliente.', + ).catch(() => {}); + } + + return created; } async updateStatus(serviceId: string, newStatus: ServiceStatus, userId: string) {