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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
d7a0769b46
commit
b4857dbc75
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user