Skip to content

Commit a0231e5

Browse files
committed
create waiver pdf registration email
1 parent 93fbdfa commit a0231e5

File tree

10 files changed

+6371
-6144
lines changed

10 files changed

+6371
-6144
lines changed

backend/typescript/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"graphql-middleware": "^6.0.6",
3333
"graphql-upload": "^12.0.0",
3434
"json2csv": "^5.0.6",
35+
"jspdf": "^2.5.1",
3536
"lodash": "^4.17.21",
3637
"mongoose": "^6.2.3",
3738
"multer": "^1.4.2",

backend/typescript/rest/camperRoutes.ts

+15
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@ import { getErrorMessage } from "../utilities/errorUtils";
1414
import { sendResponseByMimeType } from "../utilities/responseUtil";
1515
import { CamperDTO, CreateCampersDTO, WaitlistedCamperDTO } from "../types";
1616
import { createWaitlistedCamperDtoValidator } from "../middlewares/validators/waitlistedCamperValidators";
17+
import IEmailService from "../services/interfaces/emailService";
18+
import EmailService from "../services/implementations/emailService";
19+
import nodemailerConfig from "../nodemailer.config";
1720

1821
const camperRouter: Router = Router();
1922

2023
const camperService: ICamperService = new CamperService();
2124

25+
const emailService: IEmailService = new EmailService(nodemailerConfig);
26+
2227
// ROLES: Leaving unprotected as the registration flow probs needs this endpoint to register @dhruv
2328
/* Create a camper */
2429
camperRouter.post("/register", createCampersDtoValidator, async (req, res) => {
@@ -34,6 +39,16 @@ camperRouter.post("/register", createCampersDtoValidator, async (req, res) => {
3439
}
3540
});
3641

42+
camperRouter.post("/email", async (req, res) => {
43+
try {
44+
const waiverContent = req.body;
45+
emailService.sendWaiverEmail(waiverContent);
46+
res.status(201);
47+
} catch (error: unknown) {
48+
res.status(500).json({ error: getErrorMessage(error) });
49+
}
50+
});
51+
3752
// ROLES: Admin + CC
3853
/* Get all campers, optionally filter by camp ID */
3954
camperRouter.get(

backend/typescript/server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const swaggerDocument = YAML.load("swagger.yml");
3232
const app = express();
3333
app.use(cookieParser());
3434
app.use(cors(CORS_OPTIONS));
35-
app.use(express.json());
35+
app.use(express.json({ limit: "50mb" }));
3636
app.use(express.urlencoded({ extended: true }));
3737

3838
app.use("/auth", authRouter);

backend/typescript/services/implementations/emailService.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import nodemailer, { Transporter } from "nodemailer";
2+
import { Attachment } from "nodemailer/lib/mailer";
23
import IEmailService from "../interfaces/emailService";
3-
import { NodemailerConfig } from "../../types";
4+
import { EmailDTO, NodemailerConfig } from "../../types";
45
import { getErrorMessage } from "../../utilities/errorUtils";
56
import logger from "../../utilities/logger";
67
import { Camper } from "../../models/camper.model";
@@ -34,6 +35,22 @@ class EmailService implements IEmailService {
3435
}
3536
}
3637

38+
async sendWaiverEmail(waiverContent: EmailDTO): Promise<void> {
39+
const pdfAttachment: Attachment = {
40+
filename: "waiver.pdf",
41+
content: Buffer.from(waiverContent.pdf),
42+
contentType: "application/pdf",
43+
encoding: "base64",
44+
};
45+
46+
await this.sendEmail(
47+
48+
"Focus on Nature Camp Registration - Waiver",
49+
"A copy of your Focus on Nature Camp Registration is attached.",
50+
[pdfAttachment],
51+
);
52+
}
53+
3754
async sendParentConfirmationEmail(
3855
camp: Camp,
3956
campers: Camper[],
@@ -267,12 +284,14 @@ class EmailService implements IEmailService {
267284
to: string,
268285
subject: string,
269286
htmlBody: string,
287+
attachments?: Attachment[],
270288
): Promise<void> {
271289
const mailOptions = {
272290
from: this.sender,
273291
to,
274292
subject,
275293
html: htmlBody,
294+
attachments,
276295
};
277296

278297
try {

backend/typescript/services/interfaces/emailService.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { Camp } from "../../models/camp.model";
22
import { Camper } from "../../models/camper.model";
33
import { CampSession } from "../../models/campSession.model";
44
import { WaitlistedCamper } from "../../models/waitlistedCamper.model";
5+
import { EmailDTO } from "../../types";
56

67
interface IEmailService {
8+
sendWaiverEmail(waiverContent: EmailDTO): Promise<void>;
79
/**
810
* Send camp registration confirmation email.
911
* @throws Error if email was not sent successfully

backend/typescript/types.ts

+4
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ export type NodemailerConfig = {
239239
};
240240
};
241241

242+
export type EmailDTO = {
243+
pdf: string;
244+
};
245+
242246
export type WaiverDTO = {
243247
clauses: {
244248
text: string;

0 commit comments

Comments
 (0)