From c4ed887727ea5fabb2cee150b7e13a700f47e6ba Mon Sep 17 00:00:00 2001 From: Ly Tuan Kiet Date: Mon, 16 Dec 2024 17:53:39 +0700 Subject: [PATCH] chore: fix notification on service creation --- src/Service/service.schema.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Service/service.schema.ts b/src/Service/service.schema.ts index 6aebb55..d91242b 100644 --- a/src/Service/service.schema.ts +++ b/src/Service/service.schema.ts @@ -388,10 +388,13 @@ export class ServiceSchema extends PothosSchema { commission: commission ?? 0, }, }) - // mail to all mentor or center owner for the center + // mail to all mentor and center owner for the center const center = await prisma.center.findUnique({ where: { id: service.centerId }, }) + if (!center) { + throw new Error('Center not found') + } if (!center?.centerOwnerId) { throw new Error('Center owner not found') } @@ -415,8 +418,8 @@ export class ServiceSchema extends PothosSchema { SERVICE_NAME: service.name, CENTER_NAME: center.name, }) - // get user ids from mentorIds - const userIds = mentorIds.map((id) => id) + // get user ids from centerMentorIds + const userIds = [center.centerOwnerId, ...mentorIds] // send notification to user using context userIds.forEach(async (id) => { // add message to database @@ -443,7 +446,7 @@ export class ServiceSchema extends PothosSchema { }) // send notification to user using context // get user ids from mentorIds - const userIds = mentorIds.map((id) => id) + const userIds = [center.centerOwnerId, ...mentorIds] userIds.forEach(async (id) => { // add message to database const message = await this.prisma.message.create({