update approve center
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,
|
||||
@@ -9,13 +9,14 @@ import { Builder } from '../Graphql/graphql.builder';
|
||||
import { PrismaService } from '../Prisma/prisma.service';
|
||||
import { MinioService } from '../Minio/minio.service';
|
||||
import { CenterStatus } from '@prisma/client';
|
||||
|
||||
import { MailService } from '../Mail/mail.service';
|
||||
@Injectable()
|
||||
export class CenterSchema extends PothosSchema {
|
||||
constructor(
|
||||
@Inject(SchemaBuilderToken) private readonly builder: Builder,
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly minioService: MinioService,
|
||||
private readonly mailService: MailService,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
@@ -189,6 +190,77 @@ export class CenterSchema extends PothosSchema {
|
||||
});
|
||||
},
|
||||
}),
|
||||
approveOrRejectCenter: t.prismaField({
|
||||
type: this.center(),
|
||||
description: 'Approve a center and promote centerstaff to staff',
|
||||
args: {
|
||||
centerId: t.arg({
|
||||
type: 'String',
|
||||
required: true,
|
||||
}),
|
||||
approve: t.arg({
|
||||
type: 'Boolean',
|
||||
required: true,
|
||||
}),
|
||||
},
|
||||
resolve: async (query, root, args, ctx, info) => {
|
||||
return await this.prisma.$transaction(async (prisma) => {
|
||||
const center = await prisma.center.findUnique({
|
||||
...query,
|
||||
where: {
|
||||
id: args.centerId,
|
||||
},
|
||||
});
|
||||
if (!center) {
|
||||
throw new Error('Center not found');
|
||||
}
|
||||
// check if center is already approved or rejected
|
||||
if (
|
||||
center.centerStatus === CenterStatus.APPROVED ||
|
||||
center.centerStatus === CenterStatus.REJECTED
|
||||
) {
|
||||
throw new Error('Center is already approved or rejected');
|
||||
}
|
||||
// find center owner and promote to staff
|
||||
const centerOwnerId = center.centerOwnerId;
|
||||
if (!centerOwnerId) {
|
||||
throw new Error('Center owner not found');
|
||||
}
|
||||
const centerOwner = await prisma.user.findUnique({
|
||||
where: {
|
||||
id: centerOwnerId,
|
||||
},
|
||||
});
|
||||
if (!centerOwner) {
|
||||
throw new Error('Center owner not found');
|
||||
}
|
||||
const updatedCenter = await prisma.center.update({
|
||||
...query,
|
||||
where: {
|
||||
id: args.centerId,
|
||||
},
|
||||
data: {
|
||||
centerStatus: args.approve
|
||||
? CenterStatus.APPROVED
|
||||
: CenterStatus.REJECTED,
|
||||
},
|
||||
});
|
||||
// mail to center owner
|
||||
try {
|
||||
await this.mailService.sendEmail(
|
||||
centerOwner.email,
|
||||
args.approve
|
||||
? 'Your center has been approved'
|
||||
: 'Your center has been rejected',
|
||||
args.approve ? 'center-approved' : 'center-rejected',
|
||||
);
|
||||
} catch (error) {
|
||||
Logger.error(error, 'CenterSchema');
|
||||
}
|
||||
return updatedCenter;
|
||||
});
|
||||
},
|
||||
}),
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,17 +13,15 @@ export class MailService {
|
||||
|
||||
async sendEmail(to: string, subject: string, text: string) {
|
||||
try {
|
||||
const mailContent =
|
||||
await this.openaiService.generateInvitationMailContent(
|
||||
to,
|
||||
'John Doe',
|
||||
'https://epess.org',
|
||||
);
|
||||
const mailContent = `
|
||||
<h1>${subject}</h1>
|
||||
<p>${text}</p>
|
||||
`;
|
||||
|
||||
const result = await this.mailerService.sendMail({
|
||||
to,
|
||||
subject,
|
||||
text: mailContent ?? text,
|
||||
text: mailContent ?? text,
|
||||
});
|
||||
Logger.log(result, 'MailService');
|
||||
} catch (error) {
|
||||
|
||||
71
src/Mail/templates/StaffInvitation.pug
Normal file
71
src/Mail/templates/StaffInvitation.pug
Normal file
@@ -0,0 +1,71 @@
|
||||
doctype html
|
||||
html
|
||||
head
|
||||
meta(charset="UTF-8")
|
||||
title Thư mời làm việc từ Trung tâm [center_name]
|
||||
style.
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #f0f8ff;
|
||||
color: #333;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
.container {
|
||||
max-width: 600px;
|
||||
margin: 20px auto;
|
||||
padding: 20px;
|
||||
background-color: #ffffff;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.header {
|
||||
text-align: center;
|
||||
background-color: #457D84; /* Medium teal */
|
||||
color: #ffffff;
|
||||
padding: 15px;
|
||||
border-radius: 8px 8px 0 0;
|
||||
}
|
||||
.header h1 {
|
||||
margin: 0;
|
||||
font-size: 24px;
|
||||
}
|
||||
.content {
|
||||
padding: 20px;
|
||||
color: #333;
|
||||
}
|
||||
.content p {
|
||||
font-size: 16px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.button {
|
||||
display: inline-block;
|
||||
padding: 12px 20px;
|
||||
background-color: #2BD4E2; /* Bright aqua */
|
||||
color: #ffffff;
|
||||
text-decoration: none;
|
||||
font-size: 16px;
|
||||
border-radius: 5px;
|
||||
text-align: center;
|
||||
margin: 20px 0;
|
||||
}
|
||||
.footer {
|
||||
text-align: center;
|
||||
font-size: 14px;
|
||||
color: #555;
|
||||
padding: 10px;
|
||||
border-top: 1px solid #e0e0e0;
|
||||
}
|
||||
body
|
||||
.container
|
||||
.header
|
||||
h1 Thư mời làm việc từ Trung tâm [center_name]
|
||||
.content
|
||||
p Chào bạn,
|
||||
p Chúng tôi rất vui mừng thông báo rằng bạn đã được mời làm nhân viên tại trung tâm [center_name].
|
||||
p Để tiếp tục quá trình ứng tuyển, vui lòng nhấn vào nút dưới đây để truy cập vào trang nộp resume của bạn.
|
||||
a.button(href="http://localhost:3000/upload-cv?centerId=[center_id]") Nộp Resume
|
||||
p Nếu bạn có bất kỳ thắc mắc nào, đừng ngần ngại liên hệ với chúng tôi.
|
||||
.footer
|
||||
p Trân trọng,
|
||||
p EPESS
|
||||
Reference in New Issue
Block a user