diff --git a/src/certificates/certificate_template.pdf b/src/templates/certificateTemplate.pdf similarity index 100% rename from src/certificates/certificate_template.pdf rename to src/templates/certificateTemplate.pdf diff --git a/src/utils.ts b/src/utils.ts index b86c7b7e..28423407 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -3,11 +3,13 @@ import jwt from 'jsonwebtoken' import type { Response } from 'express' import type Mentor from './entities/mentor.entity' import path from 'path' +import fs from 'fs' import multer from 'multer' import ejs from 'ejs' import { ApplicationStatus } from './enums' import { generateCertificate } from './services/admin/generateCertificate' import { randomUUID } from 'crypto' + export const signAndSetCookie = (res: Response, uuid: string): void => { const token = jwt.sign({ userId: uuid }, JWT_SECRET ?? '') @@ -176,11 +178,23 @@ export const getEmailContent = async ( Thank you again for considering our program and for the time you invested in your application. We wish you all the best in your future endeavours.` } case ApplicationStatus.COMPLETED: { + const certificatesDir = path.join(__dirname, 'certificates') + + if (!fs.existsSync(certificatesDir)) { + fs.mkdirSync(certificatesDir) + } + + const templatePath = path.join( + __dirname, + 'templates', + 'certificateTemplate.pdf' + ) + const uniqueId = randomUUID() const pdfFileName = await generateCertificate( name, - './src/certificates/certificate_template.pdf', - `./src/certificates/mentee/${uniqueId}_certificate.pdf` + templatePath, + path.join(certificatesDir, `${uniqueId}_certificate.pdf`) ) return { subject: 'Congratulations! You have completed ScholarX',