Skip to content

Commit

Permalink
Add complete status (#145)
Browse files Browse the repository at this point in the history
Co-authored-by: Dileepa Mabulage <[email protected]>
  • Loading branch information
mayura-andrew and dileepainivossl authored Aug 3, 2024
1 parent 21df4b8 commit dba439b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
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,
'./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',
Expand Down

0 comments on commit dba439b

Please sign in to comment.