feat: enhance PersonalMilestone and Service schemas with new functionalities
- Added a new mutation to update personal milestones and change schedule status to IN_PROGRESS in PersonalMilestoneSchema. - Refactored service notification logic to send messages to moderators upon service approval in ServiceSchema, improving communication flow. - Cleaned up commented-out code for better readability and maintainability. These changes enhance the GraphQL API by improving milestone management and service notification processes, ensuring better user experience and state management.
This commit is contained in:
@@ -261,30 +261,35 @@ export class ServiceSchema extends PothosSchema {
|
||||
if (!centerOwner) {
|
||||
throw new Error('Center owner not found')
|
||||
}
|
||||
const centerMentor = await this.prisma.centerMentor.findMany({
|
||||
where: { centerId: service.centerId },
|
||||
// const centerMentor = await this.prisma.centerMentor.findMany({
|
||||
// where: { centerId: service.centerId },
|
||||
// })
|
||||
// const mentorIds = centerMentor.map((mentor) => mentor.mentorId)
|
||||
// const mentorEmails = await this.prisma.user.findMany({
|
||||
// where: { id: { in: mentorIds } },
|
||||
// })
|
||||
// const emails = [centerOwner.email, ...mentorEmails.map((mentor) => mentor.email)]
|
||||
// await this.mailService.sendTemplateEmail(emails, 'Thông báo về trạng thái dịch vụ', 'ServiceApproved', {
|
||||
// SERVICE_NAME: service.name,
|
||||
// CENTER_NAME: center.name,
|
||||
// })
|
||||
// send notification to all moderator using context
|
||||
const moderatorIds = await this.prisma.user.findMany({
|
||||
where: { role: Role.MODERATOR },
|
||||
})
|
||||
const mentorIds = centerMentor.map((mentor) => mentor.mentorId)
|
||||
const mentorEmails = await this.prisma.user.findMany({
|
||||
where: { id: { in: mentorIds } },
|
||||
})
|
||||
const emails = [centerOwner.email, ...mentorEmails.map((mentor) => mentor.email)]
|
||||
await this.mailService.sendTemplateEmail(emails, 'Thông báo về trạng thái dịch vụ', 'ServiceApproved', {
|
||||
SERVICE_NAME: service.name,
|
||||
CENTER_NAME: center.name,
|
||||
})
|
||||
// send notification to all mentor or center owner for the center using context
|
||||
const message = await this.prisma.message.create({
|
||||
data: {
|
||||
const messages = await this.prisma.message.createMany({
|
||||
data: moderatorIds.map((moderator) => ({
|
||||
senderId: ctx.http.me?.id ?? '',
|
||||
recipientId: centerOwner.id,
|
||||
recipientId: moderator.id,
|
||||
type: MessageType.TEXT,
|
||||
content: `Dịch vụ ${service.name} của bạn đã được chấp thuận`,
|
||||
content: `Có một dịch vụ mới với tên ${service.name} được đăng tải bởi ${center.name}`,
|
||||
sentAt: DateTimeUtils.nowAsJSDate(),
|
||||
context: MessageContextType.NOTIFICATION,
|
||||
},
|
||||
})),
|
||||
})
|
||||
moderatorIds.forEach((moderator) => {
|
||||
ctx.http.pubSub.publish(`${PubSubEvent.NOTIFICATION}.${moderator.id}`, messages)
|
||||
})
|
||||
ctx.http.pubSub.publish(`${PubSubEvent.NOTIFICATION}.${centerOwner.id}`, message)
|
||||
return service
|
||||
},
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user