Skip to content

Commit

Permalink
feat: Update certificate generation path
Browse files Browse the repository at this point in the history
The code changes update the path for generating certificates in `utils.ts`. The previous path `./src/certificates/mentee/${uniqueId}_certificate.pdf` has been changed to `./certificates/${uniqueId}_certificate.pdf`. This change ensures that the certificates are generated in the correct directory.
  • Loading branch information
mayura-andrew committed Aug 1, 2024
1 parent ec04026 commit 3f5e282
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Binary file removed src/certificates/certificate_template.pdf
Binary file not shown.
File renamed without changes.
18 changes: 16 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? '')

Expand Down Expand Up @@ -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,
'./certificates/certificate_template.pdf',
`./certificates/${uniqueId}_certificate.pdf`
templatePath,
path.join(certificatesDir, `${uniqueId}_certificate.pdf`)
)
return {
subject: 'Congratulations! You have completed ScholarX',
Expand Down

0 comments on commit 3f5e282

Please sign in to comment.