feat: enhance resume submission notifications for moderators
- Updated ResumeSchema to notify moderators when a new resume is submitted, improving communication and response times. - Refactored notification logic to streamline the process of sending messages to all relevant moderators, ensuring timely updates. - Removed redundant checks for center owner notifications, simplifying the code while maintaining functionality.
This commit is contained in:
@@ -227,7 +227,7 @@ export class ResumeSchema extends PothosSchema {
|
|||||||
})
|
})
|
||||||
// if resume exists, append resumeFile
|
// if resume exists, append resumeFile
|
||||||
if (existingResume) {
|
if (existingResume) {
|
||||||
return await this.prisma.resume.update({
|
const resume = await this.prisma.resume.update({
|
||||||
where: { id: existingResume.id },
|
where: { id: existingResume.id },
|
||||||
data: {
|
data: {
|
||||||
resumeFile: {
|
resumeFile: {
|
||||||
@@ -239,29 +239,39 @@ export class ResumeSchema extends PothosSchema {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// notify Moderator
|
||||||
|
const centerMentor = await this.prisma.centerMentor.findMany({
|
||||||
|
where: { centerId },
|
||||||
|
})
|
||||||
|
const mentorIds = centerMentor.map((mentor) => mentor.mentorId)
|
||||||
|
const moderators = await this.prisma.user.findMany({
|
||||||
|
where: { id: { in: mentorIds } },
|
||||||
|
})
|
||||||
|
for (const moderator of moderators) {
|
||||||
|
const message = await this.prisma.message.create({
|
||||||
|
data: {
|
||||||
|
senderId: ctx.http.me?.id ?? '',
|
||||||
|
recipientId: moderator.id,
|
||||||
|
type: MessageType.TEXT,
|
||||||
|
content: `Có yêu cầu hồ sơ mới từ ${ctx.http.me?.name}`,
|
||||||
|
sentAt: DateTimeUtils.nowAsJSDate(),
|
||||||
|
context: MessageContextType.NOTIFICATION,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
ctx.http.pubSub.publish(`${PubSubEvent.NOTIFICATION}.${moderator.id}`, message)
|
||||||
|
}
|
||||||
|
return resume
|
||||||
}
|
}
|
||||||
// if resume does not exist, create new resume
|
// if resume does not exist, create new resume
|
||||||
const resume = await this.prisma.resume.create({
|
const resume = await this.prisma.resume.create({
|
||||||
data: { userId, centerId, resumeFile: { create: { fileUrl, type: mimetype, actualFileName } } },
|
data: { userId, centerId, resumeFile: { create: { fileUrl, type: mimetype, actualFileName } } },
|
||||||
})
|
})
|
||||||
// notify all mentor or center owner for the center
|
// send notification to all Moderator
|
||||||
const center = await this.prisma.center.findUnique({
|
|
||||||
where: { id: 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({
|
const centerMentor = await this.prisma.centerMentor.findMany({
|
||||||
where: { centerId: center.id },
|
where: { centerId },
|
||||||
})
|
})
|
||||||
const mentorIds = centerMentor.map((mentor) => mentor.mentorId)
|
const mentorIds = centerMentor.map((mentor) => mentor.mentorId)
|
||||||
// send notification to all Moderator
|
|
||||||
const moderators = await this.prisma.user.findMany({
|
const moderators = await this.prisma.user.findMany({
|
||||||
where: { id: { in: mentorIds } },
|
where: { id: { in: mentorIds } },
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user