implement redis cache for context
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { Inject, Injectable, Logger } from '@nestjs/common';
|
||||
import {
|
||||
Pothos,
|
||||
PothosRef,
|
||||
@@ -237,6 +237,10 @@ export class ServiceSchema extends PothosSchema {
|
||||
type: 'Boolean',
|
||||
required: true,
|
||||
}),
|
||||
adminNote: t.arg({
|
||||
type: 'String',
|
||||
required: false,
|
||||
}),
|
||||
},
|
||||
resolve: async (query, root, args, ctx, info) => {
|
||||
return await this.prisma.$transaction(async (prisma) => {
|
||||
@@ -258,9 +262,15 @@ export class ServiceSchema extends PothosSchema {
|
||||
status: args.approve
|
||||
? ServiceStatus.APPROVED
|
||||
: ServiceStatus.REJECTED,
|
||||
adminNote: {
|
||||
create: {
|
||||
content: args.adminNote ?? '',
|
||||
notedByUserId: ctx.me.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
// mail to center owner and mentor who requested the service
|
||||
// mail to all mentor or center owner for the center
|
||||
const center = await prisma.center.findUnique({
|
||||
where: { id: service.centerId },
|
||||
});
|
||||
@@ -276,15 +286,36 @@ export class ServiceSchema extends PothosSchema {
|
||||
const centerMentor = await prisma.centerMentor.findMany({
|
||||
where: { centerId: service.centerId },
|
||||
});
|
||||
const mentorEmails = centerMentor.map((mentor) => mentor.mentorId);
|
||||
const emails = [centerOwner.email, ...mentorEmails];
|
||||
for (const email of emails) {
|
||||
await this.mailService.sendEmail(
|
||||
email,
|
||||
args.approve
|
||||
? 'Your service has been approved'
|
||||
: 'Your service has been rejected',
|
||||
args.approve ? 'service-approved' : 'service-rejected',
|
||||
const mentorIds = centerMentor.map((mentor) => mentor.mentorId);
|
||||
// get mentor emails
|
||||
const mentorEmails = await prisma.user.findMany({
|
||||
where: { id: { in: mentorIds } },
|
||||
});
|
||||
Logger.log(mentorEmails, 'ServiceSchema');
|
||||
const emails = [
|
||||
centerOwner.email,
|
||||
...mentorEmails.map((mentor) => mentor.email),
|
||||
];
|
||||
if (args.approve) {
|
||||
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,
|
||||
},
|
||||
);
|
||||
} else {
|
||||
await this.mailService.sendTemplateEmail(
|
||||
emails,
|
||||
'Thông báo về trạng thái dịch vụ',
|
||||
'ServiceRejected',
|
||||
{
|
||||
SERVICE_NAME: service.name,
|
||||
CENTER_NAME: center.name,
|
||||
ADMIN_NOTE: args.adminNote ?? 'Không có lý do',
|
||||
},
|
||||
);
|
||||
}
|
||||
return updatedService;
|
||||
|
||||
Reference in New Issue
Block a user