jp-shared 1.0.21 → 1.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -37,7 +37,7 @@ const educationSchema = new mongoose.Schema({
|
|
|
37
37
|
default: null,
|
|
38
38
|
},
|
|
39
39
|
// course: { type: String, required: true },
|
|
40
|
-
institute: { type:
|
|
40
|
+
institute: { type: ObjectId, required: true },
|
|
41
41
|
courseType: { type: String, required: true },
|
|
42
42
|
courseStartYear: {
|
|
43
43
|
type: Number,
|
package/package.json
CHANGED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
const nodemailer = require("nodemailer");
|
|
2
|
-
const puppeteer = require("puppeteer-core");
|
|
3
|
-
const chromium = require("chrome-aws-lambda");
|
|
4
|
-
// const localPuppeteer = require("puppeteer");
|
|
5
|
-
|
|
6
|
-
const { invoiceEmailTemplate } = require("./invoiceTemplate");
|
|
7
|
-
|
|
8
|
-
const { ToWords } = require("to-words");
|
|
9
|
-
const { OUR_ORG_INFO } = require("../constants");
|
|
10
|
-
const toWords = new ToWords();
|
|
11
|
-
|
|
12
|
-
// const generatePDF = async (htmlContent) => {
|
|
13
|
-
// // const browser = await puppeteer.launch();
|
|
14
|
-
// // const browser = await puppeteer.launch({
|
|
15
|
-
// // // executablePath: puppeteer.executablePath(),
|
|
16
|
-
// // headless: true, // Ensure the browser runs headlessly in the cloud
|
|
17
|
-
// // // args: ["--no-sandbox", "--disable-setuid-sandbox"], // Required in some environments like Firebase
|
|
18
|
-
// // });
|
|
19
|
-
// const browser = await puppeteer.launch({
|
|
20
|
-
// executablePath: await chromium.executablePath, // Use the correct Chromium executable for Firebase
|
|
21
|
-
// args: chromium.args, // Set required arguments for headless Chrome
|
|
22
|
-
// headless: chromium.headless, // Ensure Chrome runs in headless mode
|
|
23
|
-
// });
|
|
24
|
-
// const page = await browser.newPage();
|
|
25
|
-
// await page.setContent(htmlContent);
|
|
26
|
-
// const pdfBuffer = await page.pdf({ format: "A4" });
|
|
27
|
-
// await browser.close();
|
|
28
|
-
// return pdfBuffer;
|
|
29
|
-
// };
|
|
30
|
-
const generatePDF = async (htmlContent) => {
|
|
31
|
-
try {
|
|
32
|
-
// from below is for local development
|
|
33
|
-
// const browser = await localPuppeteer.launch();
|
|
34
|
-
|
|
35
|
-
// Launch browser with necessary configuration for Firebase or serverless environments
|
|
36
|
-
const browser = await puppeteer.launch({
|
|
37
|
-
executablePath: await chromium.executablePath, // Path to Chromium for Firebase/Serverless
|
|
38
|
-
args: chromium.args, // Required arguments for running headless
|
|
39
|
-
headless: chromium.headless, // Ensure headless mode is enabled
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
// Create a new page in the browser
|
|
43
|
-
const page = await browser.newPage();
|
|
44
|
-
|
|
45
|
-
// Set the HTML content dynamically passed to this function
|
|
46
|
-
await page.setContent(htmlContent);
|
|
47
|
-
|
|
48
|
-
// Generate the PDF from the page's content
|
|
49
|
-
const pdfBuffer = await page.pdf({
|
|
50
|
-
format: "A4", // Set paper format to A4 (you can customize this if needed)
|
|
51
|
-
printBackground: true, // Include background images or colors in the PDF
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
// Close the browser once done
|
|
55
|
-
await browser.close();
|
|
56
|
-
|
|
57
|
-
// Return the PDF as a buffer
|
|
58
|
-
return pdfBuffer;
|
|
59
|
-
} catch (error) {
|
|
60
|
-
console.error("Error generating PDF:", error);
|
|
61
|
-
throw error; // Re-throw the error for further handling
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
const sendInvoice = async (recruiterWithPlan, paymentHistory) => {
|
|
65
|
-
if (!recruiterWithPlan || !paymentHistory) {
|
|
66
|
-
throw new Error("No data provided to send the invoice.");
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const { recruiterEmail, gstAmount, totalAmount, amount, gstPercentage } =
|
|
70
|
-
recruiterWithPlan;
|
|
71
|
-
|
|
72
|
-
const { billNumber, jobId, planName } = paymentHistory;
|
|
73
|
-
|
|
74
|
-
// Check if the required environment variables are set
|
|
75
|
-
if (!process.env.EMAIL || !process.env.EMAIL_PASSWORD) {
|
|
76
|
-
const errorMsg = "Email credentials are not set in environment variables.";
|
|
77
|
-
console.error(errorMsg);
|
|
78
|
-
throw new Error(errorMsg); // Throw error to propagate it back to the caller
|
|
79
|
-
}
|
|
80
|
-
// console.log(totalAmount);
|
|
81
|
-
// Email content
|
|
82
|
-
const htmlBody = `
|
|
83
|
-
<p>Dear Customer,</p>
|
|
84
|
-
<p>Please find attached your invoice. If you have any questions, feel free to reach out to us.</p>
|
|
85
|
-
<p>Best regards,<br>Ocean academy</p>
|
|
86
|
-
`;
|
|
87
|
-
const invoiceData = {
|
|
88
|
-
date: new Date().toLocaleDateString(),
|
|
89
|
-
billNo: billNumber,
|
|
90
|
-
jobId,
|
|
91
|
-
items: [{ description: `${planName}`, amount: `${amount}` }],
|
|
92
|
-
totalAmount,
|
|
93
|
-
totalAmountWords: toWords.convert(totalAmount, { currency: true }),
|
|
94
|
-
gstPercentage,
|
|
95
|
-
gstAmount,
|
|
96
|
-
...OUR_ORG_INFO,
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
// Generate the invoice HTML content
|
|
100
|
-
const invoiceHTML = invoiceEmailTemplate(invoiceData);
|
|
101
|
-
const pdfBuffer = await generatePDF(invoiceHTML);
|
|
102
|
-
|
|
103
|
-
// Create a transporter using your email credentials
|
|
104
|
-
const transporter = nodemailer.createTransport({
|
|
105
|
-
service: "gmail",
|
|
106
|
-
auth: {
|
|
107
|
-
user: process.env.EMAIL,
|
|
108
|
-
pass: process.env.EMAIL_PASSWORD, // SMTP Password
|
|
109
|
-
},
|
|
110
|
-
// === add this === //
|
|
111
|
-
tls: { rejectUnauthorized: false },
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
// Email options
|
|
115
|
-
const mailOptions = {
|
|
116
|
-
from: process.env.EMAIL,
|
|
117
|
-
to: recruiterEmail,
|
|
118
|
-
subject: "Welcome to our OA Job Portal!",
|
|
119
|
-
html: htmlBody, // HTML content from the template
|
|
120
|
-
attachments: [
|
|
121
|
-
{
|
|
122
|
-
filename: "invoice.pdf",
|
|
123
|
-
content: pdfBuffer,
|
|
124
|
-
encoding: "base64",
|
|
125
|
-
},
|
|
126
|
-
],
|
|
127
|
-
};
|
|
128
|
-
// Send the email with the PDF attachment
|
|
129
|
-
try {
|
|
130
|
-
const info = await transporter.sendMail(mailOptions);
|
|
131
|
-
// console.log("Email sent successfully!", info);
|
|
132
|
-
return { status: 200, message: "Email sent successfully!", info };
|
|
133
|
-
} catch (error) {
|
|
134
|
-
console.error("Error sending email:", error);
|
|
135
|
-
throw new Error("Error sending email", error);
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
module.exports = { sendInvoice, generatePDF };
|