From b4857dbc751a7cecf4cb936f874fe355a1b4feaf Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Wed, 22 Jul 2026 09:33:38 -0500 Subject: [PATCH] fix: notify professional via FCM when service is created Backend create() now looks up the professional's fcm_token and sends a push notification after the service is persisted. This replaces the unreliable client-side notification in the Flutter app (which couldn't use the server FCM key). Co-Authored-By: Claude Sonnet 4.6 --- backend/src/services/services.service.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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) {