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 - ./src:/app/src
environment: environment:
- NODE_ENV=development - NODE_ENV=development
- DISABLE_AUTH=true
- DATABASE_URL=postgresql://your_username:your_password@10.0.27.1:5432/epess - DATABASE_URL=postgresql://your_username:your_password@10.0.27.1:5432/epess
- CLERK_PUBLISHABLE_KEY=pk_test_aW4tY2hpbXAtOTcuY2xlcmsuYWNjb3VudHMuZGV2JA - CLERK_PUBLISHABLE_KEY=pk_test_aW4tY2hpbXAtOTcuY2xlcmsuYWNjb3VudHMuZGV2JA
- CLERK_SECRET_KEY=sk_test_sA5lsb1GHwUNXWQCp5ev70QkaoF5EmdAHNWiCGwZF6 - CLERK_SECRET_KEY=sk_test_sA5lsb1GHwUNXWQCp5ev70QkaoF5EmdAHNWiCGwZF6

View File

@@ -4,6 +4,13 @@
"sourceRoot": "src", "sourceRoot": "src",
"language": "ts", "language": "ts",
"compilerOptions": { "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 // build invite url
const inviteUrl = `${process.env.CENTER_BASE_URL}/invite?token=${token}`; const inviteUrl = `${process.env.CENTER_BASE_URL}/invite?token=${token}`;
// mail to user with params centerId, email // mail to user with params centerId, email
await this.mailService.sendEmail( await this.mailService.sendTemplateEmail(
args.email, args.email,
'Invite to center', 'Invite to center',
`You are invited to join the center ${center.name}. 'StaffInvitation',
Please click the link below to join the center: {
${inviteUrl}`, center_name: center.name,
invite_url: inviteUrl,
},
); );
return null; return null;
}); });

View File

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

View File

@@ -10,12 +10,15 @@ export class GraphqlService {
async acquireContext(req: Request) { async acquireContext(req: Request) {
// get x-session-id from headers // get x-session-id from headers
let sessionId; let sessionId: string;
try { try {
sessionId = req.headers['x-session-id']; sessionId = req.headers['x-session-id'] as string;
//eslint-disable-next-line @typescript-eslint/no-unused-vars //eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (error) { } catch (error) {
if (process.env.NODE_ENV === 'development') { if (
process.env.NODE_ENV === 'development' &&
process.env.DISABLE_AUTH === 'true'
) {
return null; return null;
} }
throw new UnauthorizedException('Must provide a session ID'); 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: { defaults: {
from: process.env.MAILU_FROM, from: process.env.MAILU_FROM,
}, },
// template: { template: {
// dir: path.join(__dirname, 'templates'), dir: path.join(__dirname, 'templates'),
// adapter: new PugAdapter(), adapter: new PugAdapter({
// options: { inlineCssEnabled: true,
// strict: true, }),
// }, options: {
// }, strict: true,
},
},
}), }),
}), }),
OpenaiModule, OpenaiModule,

View File

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

View File

@@ -2,7 +2,7 @@ doctype html
html html
head head
meta(charset="UTF-8") 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. style.
body { body {
font-family: Arial, sans-serif; font-family: Arial, sans-serif;
@@ -59,12 +59,12 @@ html
body body
.container .container
.header .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 .content
p Chào bạn, 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. 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. 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 .footer
p Trân trọng, p Trân trọng,

View File

@@ -239,7 +239,15 @@ export class UserSchema extends PothosSchema {
to: t.arg({ type: 'String', required: true }), to: t.arg({ type: 'String', required: true }),
}, },
resolve: async (_parent, args, _context, _info) => { 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'; return 'Email sent';
}, },
}), }),

View File

@@ -13,7 +13,12 @@ async function bootstrap() {
app.enableCors({ app.enableCors({
origin: corsOrigin, origin: corsOrigin,
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'], 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, credentials: true,
}); });