diff --git a/compose.yaml b/compose.yaml index 1b9d995..470457f 100644 --- a/compose.yaml +++ b/compose.yaml @@ -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 diff --git a/nest-cli.json b/nest-cli.json index 15f0747..d7497e5 100644 --- a/nest-cli.json +++ b/nest-cli.json @@ -4,6 +4,13 @@ "sourceRoot": "src", "language": "ts", "compilerOptions": { - "deleteOutDir": true + "watchAssets": true, + "deleteOutDir": true, + "assets": [ + { + "include": "**/*.pug", + "outDir": "./dist/src/" + } + ] } } diff --git a/src/CenterStaff/centerstaff.schema.ts b/src/CenterStaff/centerstaff.schema.ts index 8e7dd73..7033f14 100644 --- a/src/CenterStaff/centerstaff.schema.ts +++ b/src/CenterStaff/centerstaff.schema.ts @@ -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; }); diff --git a/src/Graphql/graphql.module.ts b/src/Graphql/graphql.module.ts index fe968ca..513116c 100644 --- a/src/Graphql/graphql.module.ts +++ b/src/Graphql/graphql.module.ts @@ -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), }), diff --git a/src/Graphql/graphql.service.ts b/src/Graphql/graphql.service.ts index 8b678f1..635fc1d 100644 --- a/src/Graphql/graphql.service.ts +++ b/src/Graphql/graphql.service.ts @@ -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'); diff --git a/src/Mail/mail.module.ts b/src/Mail/mail.module.ts index cd22a38..848cc3d 100644 --- a/src/Mail/mail.module.ts +++ b/src/Mail/mail.module.ts @@ -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, diff --git a/src/Mail/mail.service.ts b/src/Mail/mail.service.ts index df530a8..da39ca2 100644 --- a/src/Mail/mail.service.ts +++ b/src/Mail/mail.service.ts @@ -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({ diff --git a/src/Mail/templates/StaffInvitation.pug b/src/Mail/templates/StaffInvitation.pug index 9bc101f..dd1dab9 100644 --- a/src/Mail/templates/StaffInvitation.pug +++ b/src/Mail/templates/StaffInvitation.pug @@ -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, diff --git a/src/User/user.schema.ts b/src/User/user.schema.ts index ebe4ac6..b7ac3f8 100644 --- a/src/User/user.schema.ts +++ b/src/User/user.schema.ts @@ -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'; }, }), diff --git a/src/main.ts b/src/main.ts index 35d2aba..eb5ac00 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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, });