jp-shared 1.0.21 → 1.0.22
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,43 +1,31 @@
|
|
|
1
1
|
const nodemailer = require("nodemailer");
|
|
2
2
|
const puppeteer = require("puppeteer-core");
|
|
3
3
|
const chromium = require("chrome-aws-lambda");
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const localPuppeteer = require("puppeteer");
|
|
6
5
|
const { invoiceEmailTemplate } = require("./invoiceTemplate");
|
|
7
|
-
|
|
8
6
|
const { ToWords } = require("to-words");
|
|
9
7
|
const { OUR_ORG_INFO } = require("../constants");
|
|
8
|
+
const { invoiceSchema } = require("../../../src/validators");
|
|
9
|
+
const { isProduction, isTest } = require("jp-shared/utils/env-utils");
|
|
10
10
|
const toWords = new ToWords();
|
|
11
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
12
|
const generatePDF = async (htmlContent) => {
|
|
31
13
|
try {
|
|
32
14
|
// from below is for local development
|
|
33
15
|
// const browser = await localPuppeteer.launch();
|
|
34
16
|
|
|
35
17
|
// Launch browser with necessary configuration for Firebase or serverless environments
|
|
36
|
-
const browser = await puppeteer.launch({
|
|
18
|
+
// const browser = await puppeteer.launch({
|
|
19
|
+
// executablePath: await chromium.executablePath, // Path to Chromium for Firebase/Serverless
|
|
20
|
+
// args: chromium.args, // Required arguments for running headless
|
|
21
|
+
// headless: chromium.headless, // Ensure headless mode is enabled
|
|
22
|
+
// });
|
|
23
|
+
|
|
24
|
+
const browser = isProduction() || isTest() ? await puppeteer.launch({
|
|
37
25
|
executablePath: await chromium.executablePath, // Path to Chromium for Firebase/Serverless
|
|
38
26
|
args: chromium.args, // Required arguments for running headless
|
|
39
27
|
headless: chromium.headless, // Ensure headless mode is enabled
|
|
40
|
-
});
|
|
28
|
+
}) : await localPuppeteer.launch();
|
|
41
29
|
|
|
42
30
|
// Create a new page in the browser
|
|
43
31
|
const page = await browser.newPage();
|
|
@@ -61,15 +49,23 @@ const generatePDF = async (htmlContent) => {
|
|
|
61
49
|
throw error; // Re-throw the error for further handling
|
|
62
50
|
}
|
|
63
51
|
};
|
|
64
|
-
const sendInvoice = async (
|
|
65
|
-
if (!recruiterWithPlan || !paymentHistory) {
|
|
66
|
-
throw new Error("No data provided to send the invoice.");
|
|
67
|
-
}
|
|
52
|
+
const sendInvoice = async (invoiceInput) => {
|
|
68
53
|
|
|
69
|
-
|
|
70
|
-
|
|
54
|
+
// Validate input
|
|
55
|
+
const { error, value } = invoiceSchema.validate(invoiceInput);
|
|
56
|
+
if (error) throw new Error(`Invalid invoice input: ${error.message}`);
|
|
71
57
|
|
|
72
|
-
|
|
58
|
+
// Destructure the validated value
|
|
59
|
+
const {
|
|
60
|
+
recruiterEmail,
|
|
61
|
+
gstAmount,
|
|
62
|
+
totalAmount,
|
|
63
|
+
amount,
|
|
64
|
+
gstPercentage,
|
|
65
|
+
billNumber,
|
|
66
|
+
jobId,
|
|
67
|
+
planName,
|
|
68
|
+
} = value;
|
|
73
69
|
|
|
74
70
|
// Check if the required environment variables are set
|
|
75
71
|
if (!process.env.EMAIL || !process.env.EMAIL_PASSWORD) {
|