update invite center staff

This commit is contained in:
2024-10-27 19:47:50 +07:00
parent a5e9ad5ac1
commit ef89372e8c
10 changed files with 52 additions and 24 deletions

View File

@@ -11,6 +11,7 @@ services:
- ./src:/app/src
environment:
- NODE_ENV=development
- DISABLE_AUTH=true
- DATABASE_URL=postgresql://your_username:your_password@10.0.27.1:5432/epess
- CLERK_PUBLISHABLE_KEY=pk_test_aW4tY2hpbXAtOTcuY2xlcmsuYWNjb3VudHMuZGV2JA
- CLERK_SECRET_KEY=sk_test_sA5lsb1GHwUNXWQCp5ev70QkaoF5EmdAHNWiCGwZF6

View File

@@ -4,6 +4,13 @@
"sourceRoot": "src",
"language": "ts",
"compilerOptions": {
"deleteOutDir": true
"watchAssets": true,
"deleteOutDir": true,
"assets": [
{
"include": "**/*.pug",
"outDir": "./dist/src/"
}
]
}
}

View File

@@ -152,12 +152,14 @@ export class CenterStaffSchema extends PothosSchema {
// build invite url
const inviteUrl = `${process.env.CENTER_BASE_URL}/invite?token=${token}`;
// mail to user with params centerId, email
await this.mailService.sendEmail(
await this.mailService.sendTemplateEmail(
args.email,
'Invite to center',
`You are invited to join the center ${center.name}.
Please click the link below to join the center:
${inviteUrl}`,
'StaffInvitation',
{
center_name: center.name,
invite_url: inviteUrl,
},
);
return null;
});

View File

@@ -79,7 +79,7 @@ import { initContextCache } from '@pothos/core';
subscriptions: {
'graphql-ws': true,
},
context: async (req: Request) => ({
context: async ({ req }: { req: Request }) => ({
...initContextCache(),
me: await new GraphqlService(new PrismaService()).acquireContext(req),
}),

View File

@@ -10,12 +10,15 @@ export class GraphqlService {
async acquireContext(req: Request) {
// get x-session-id from headers
let sessionId;
let sessionId: string;
try {
sessionId = req.headers['x-session-id'];
sessionId = req.headers['x-session-id'] as string;
//eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (error) {
if (process.env.NODE_ENV === 'development') {
if (
process.env.NODE_ENV === 'development' &&
process.env.DISABLE_AUTH === 'true'
) {
return null;
}
throw new UnauthorizedException('Must provide a session ID');

View File

@@ -28,13 +28,15 @@ import { PugAdapter } from '@nestjs-modules/mailer/dist/adapters/pug.adapter';
defaults: {
from: process.env.MAILU_FROM,
},
// template: {
// dir: path.join(__dirname, 'templates'),
// adapter: new PugAdapter(),
// options: {
// strict: true,
// },
// },
template: {
dir: path.join(__dirname, 'templates'),
adapter: new PugAdapter({
inlineCssEnabled: true,
}),
options: {
strict: true,
},
},
}),
}),
OpenaiModule,

View File

@@ -21,7 +21,7 @@ export class MailService {
const result = await this.mailerService.sendMail({
to,
subject,
text: mailContent ?? text,
text: mailContent ?? text,
});
Logger.log(result, 'MailService');
} catch (error) {
@@ -33,7 +33,7 @@ export class MailService {
to: string,
subject: string,
template: string,
context: User,
context: any,
) {
try {
const result = await this.mailerService.sendMail({

View File

@@ -2,7 +2,7 @@ doctype html
html
head
meta(charset="UTF-8")
title Thư mời làm việc từ Trung tâm [center_name]
title Thư mời làm việc từ Trung tâm #{center_name}
style.
body {
font-family: Arial, sans-serif;
@@ -59,12 +59,12 @@ html
body
.container
.header
h1 Thư mời làm việc từ Trung tâm [center_name]
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 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
a.button(href=invite_url) 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,

View File

@@ -239,7 +239,15 @@ export class UserSchema extends PothosSchema {
to: t.arg({ type: 'String', required: true }),
},
resolve: async (_parent, args, _context, _info) => {
await this.mailService.sendEmail(args.to, 'Test', 'Test');
await this.mailService.sendTemplateEmail(
args.to,
'Bạn đã được mời làm việc tại Trung tâm băng đĩa lậu hải ngoại',
'StaffInvitation',
{
center_name: 'băng đĩa lậu hải ngoại',
invite_url: 'https://epess.org',
},
);
return 'Email sent';
},
}),

View File

@@ -13,7 +13,12 @@ async function bootstrap() {
app.enableCors({
origin: corsOrigin,
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
allowedHeaders: ['Content-Type', '*', 'x-apollo-operation-name'],
allowedHeaders: [
'Content-Type',
'*',
'x-apollo-operation-name',
'x-session-id',
],
credentials: true,
});