Skip to content

Instantly share code, notes, and snippets.

@seanconnelly34
Created July 8, 2020 20:03
Show Gist options
  • Save seanconnelly34/3063e2486018ed0e6b119a2ed5db4ca5 to your computer and use it in GitHub Desktop.
Save seanconnelly34/3063e2486018ed0e6b119a2ed5db4ca5 to your computer and use it in GitHub Desktop.
const path = require("path");
const express = require("express");
const fs = require("fs");
const app = express();
const cors = require("cors");
const buildPath = path.join(__dirname, "..", "build");
app.use(express.json());
app.use(express.static(buildPath));
app.use(cors());
//pdf
const PDFDocument = require("pdfkit");
const doc = new PDFDocument({ margin: 20, compress: false });
const transporter = require("./config");
app.post("http://138.197.128.137:3030/registration", (req, res) => {
let fileName = req.body.name;
console.log("reqqqq", req.body);
doc.pipe(fs.createWriteStream(__dirname + `/${fileName}.pdf`));
// Set some meta data
doc.info["Title"] = "Landings Surgical Center Registration Form";
doc.info["Author"] = "Landings Surgical Center";
doc.fontSize(17);
doc.text("The Landings Surgical Center", {
underline: true,
align: "center",
});
doc.fontSize(12);
doc.moveDown();
doc.text("Pre-Screening Data", { align: "center" });
doc.fontSize(11);
//----------------------------------------- LEFT SIDE START
//DATE
doc.font("Times-Bold");
doc.text("Date:", 50, 90, {
underline: true,
});
doc.font("Times-Roman");
doc.text(req.body.workphone, 145, 210);
//END workphone
// work email
doc.font("Times-Bold");
doc.text("Family Physician:", 50, 230, {
underline: true,
});
// province
doc.font("Times-Bold");
doc.text("Province:", 300, 170, {
underline: true,
});
doc.font("Times-Roman");
doc.text(req.body.province, 390, 170);
//END
// homephone
doc.font("Times-Bold");
doc.text("Home Phone:", 300, 190, {
underline: true,
});
doc.font("Times-Roman");
doc.text(req.body.homephone, 390, 190);
//END
// cell
doc.font("Times-Bold");
doc.text("Cell Phone:", 300, 210, {
underline: true,
});
doc.font("Times-Roman");
doc.text(req.body.cellphone, 390, 210);
//END
// occupation
doc.font("Times-Bold");
doc.text("Occupation:", 300, 230, {
underline: true,
});
doc.font("Times-Roman");
doc.text(req.body.occupation, 390, 230);
//END
doc.font("Times-Bold");
doc.text("Comments", 50, 540, {
underline: true,
});
doc.font("Times-Roman");
doc.text(`${req.body.comments}`, 50, 570, { columns: 1, width: 510 });
{
}
doc.image(req.body.trimmedSignature, 50, 650, { width: 150 });
doc.end();
try {
const mailOptions = {
from: req.body.email,
to: "[email protected]",
subject: `Registration - ${req.body.name}`,
html: req.body.date,
html: req.body.name,
attachments: [
{
filename: `${req.body.name}-Registration.pdf`,
path: __dirname + `/${fileName}.pdf`,
contentType: "application/pdf",
},
],
};
transporter.sendMail(mailOptions, function (err, info) {
if (err) {
res.status(500).send({
success: false,
message: "somthing went wrong, try again",
});
}
// else {
// res.send({
// success: true,
// message: "thanks for contacting us.",
// });
// }
});
} catch (error) {
res.sendStatus(500).send({
success: false,
message: "Somting went wrong, try again later",
});
}
});
//------------------------------------------------------covid
app.post("http://138.197.128.137:3030/covid", (req, res) => {
let fileName = req.body.name;
console.log(req.body);
console.log(req.body.name);
doc.pipe(fs.createWriteStream(__dirname + `/Covid_${fileName}.pdf`));
// Set some meta data
doc.info["Title"] = "Covid Assessment Form";
doc.info["Author"] = "Landings Surgical Center";
doc.fontSize(17);
doc.text("Covid Assessment Form", {
underline: true,
align: "center",
});
doc.fontSize(11);
//----------------------------------------- LEFT SIDE START
doc.font("Times-Bold");
doc.text("Name:", 50, 130, {
underline: true,
});
doc.text("High Blood Pressure:", 50, 510);
doc.text(`${req.body.sneeze ? "Yes" : "No"}`, 175, 510);
doc.end();
try {
const mailOptions = {
from: req.body.email,
to: req.body.email,
subject: `Covid-19 Assessment - ${req.body.name}`,
html: req.body.date,
html: req.body.name,
attachments: [
{
filename: `Covid_${fileName}.pdf`,
path: __dirname + `/Covid_${fileName}.pdf`,
contentType: "application/pdf",
},
],
};
transporter.sendMail(mailOptions, function (err, info) {
if (err) {
res.status(500).send({
success: false,
message: "somthing went wrong, try again",
});
} else {
res.send({
success: true,
message: "thanks for contacting us.",
});
}
});
} catch (error) {
res.sendStatus(500).send({
success: false,
message: "Somting went wrong, try again later",
});
}
});
app.listen(3030, () => {
console.log("server on port 3030");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment