feat: enhance notification system and role-based access across schemas
- Updated MessageSchema to include context-aware filtering for notifications, allowing retrieval based on recipientId for NOTIFICATION and SYSTEM contexts. - Enhanced RefundTicketSchema to notify moderators upon refund requests, improving communication and response times. - Modified ResumeSchema to send notifications to mentors and center owners when a new resume is submitted, ensuring timely updates. - Improved ServiceSchema to notify center owners and mentors about service approvals, enhancing user engagement and awareness. - Implemented role-based access control checks across schemas to ensure only authorized users can perform specific actions, enhancing security and user experience.
This commit is contained in:
@@ -263,10 +263,48 @@ export class ServiceSchema extends PothosSchema {
|
||||
}
|
||||
// replace userId with current user id
|
||||
args.input.user = { connect: { id: ctx.http.me?.id ?? '' } }
|
||||
return await this.prisma.service.create({
|
||||
const service = await this.prisma.service.create({
|
||||
...query,
|
||||
data: args.input,
|
||||
})
|
||||
// send notification to all mentor or center owner for the center
|
||||
const center = await this.prisma.center.findUnique({
|
||||
where: { id: service.centerId },
|
||||
})
|
||||
if (!center?.centerOwnerId) {
|
||||
throw new Error('Center owner not found')
|
||||
}
|
||||
const centerOwner = await this.prisma.user.findUnique({
|
||||
where: { id: center.centerOwnerId },
|
||||
})
|
||||
if (!centerOwner) {
|
||||
throw new Error('Center owner not found')
|
||||
}
|
||||
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 mentor or center owner for the center using context
|
||||
const message = await this.prisma.message.create({
|
||||
data: {
|
||||
senderId: ctx.http.me?.id ?? '',
|
||||
recipientId: centerOwner.id,
|
||||
type: MessageType.TEXT,
|
||||
content: `Dịch vụ ${service.name} của bạn đã được chấp thuận`,
|
||||
sentAt: DateTimeUtils.nowAsJSDate(),
|
||||
context: MessageContextType.NOTIFICATION,
|
||||
},
|
||||
})
|
||||
ctx.http.pubSub.publish(`${PubSubEvent.NOTIFICATION}.${centerOwner.id}`, message)
|
||||
return service
|
||||
},
|
||||
}),
|
||||
updateService: t.prismaField({
|
||||
|
||||
Reference in New Issue
Block a user