Reformat all project files to use the prettier config file.

This commit is contained in:
Patrick Fic
2024-03-27 15:35:07 -07:00
parent b161530381
commit e1df64d592
873 changed files with 111387 additions and 125473 deletions

View File

@@ -1,9 +1,6 @@
const path = require("path");
require("dotenv").config({
path: path.resolve(
process.cwd(),
`.env.${process.env.NODE_ENV || "development"}`
),
path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
});
const client = require("../graphql-client/graphql-client").client;
const emailer = require("../email/sendemail");
@@ -11,74 +8,76 @@ const moment = require("moment-timezone");
const converter = require("json-2-csv");
exports.taskHandler = async (req, res) => {
try {
const {bodyshopid, query, variables, text, to, subject, timezone} = req.body;
try {
const { bodyshopid, query, variables, text, to, subject, timezone } = req.body;
//Check the variables to see if they are an object.
Object.keys(variables).forEach((key) => {
if (typeof variables[key] === "object") {
if (variables[key].function) {
variables[key] = functionMapper(variables[key].function, timezone);
}
}
});
//Check the variables to see if they are an object.
Object.keys(variables).forEach((key) => {
if (typeof variables[key] === "object") {
if (variables[key].function) {
variables[key] = functionMapper(variables[key].function, timezone);
}
}
});
const response = await client.request(query, variables);
const rootElement = response[Object.keys(response)[0]]; //This element should always be an array.
const response = await client.request(query, variables);
const rootElement = response[Object.keys(response)[0]]; //This element should always be an array.
const csv = converter.json2csv(rootElement, {emptyFieldValue: ""});
const csv = converter.json2csv(rootElement, { emptyFieldValue: "" });
emailer.sendTaskEmail({
to,
subject,
text,
attachments: [{filename: "query.csv", content: csv}],
}).catch(err => {
console.error('Errors sending CSV Email.')
});
emailer
.sendTaskEmail({
to,
subject,
text,
attachments: [{ filename: "query.csv", content: csv }]
})
.catch((err) => {
console.error("Errors sending CSV Email.");
});
return res.status(200).send(csv);
} catch (error) {
res.status(500).json({error: error.message, stack: error.stackTrace});
}
return res.status(200).send(csv);
} catch (error) {
res.status(500).json({ error: error.message, stack: error.stackTrace });
}
};
const isoFormat = "YYYY-MM-DD";
function functionMapper(f, timezone) {
switch (f) {
case "date.today":
return moment().tz(timezone).format(isoFormat);
case "date.now":
return moment().tz(timezone);
case "date.yesterday":
return moment().tz(timezone).subtract(1, "day").format(isoFormat);
case "date.3daysago":
return moment().tz(timezone).subtract(3, "day").format(isoFormat);
case "date.7daysago":
return moment().tz(timezone).subtract(7, "day").format(isoFormat);
case "date.tomorrow":
return moment().tz(timezone).add(1, "day").format(isoFormat);
case "date.3daysfromnow":
return moment().tz(timezone).add(3, "day").format(isoFormat);
case "date.7daysfromnow":
return moment().tz(timezone).add(7, "day").format(isoFormat);
case "date.yesterdaytz":
return moment().tz(timezone).subtract(1, "day");
case "date.3daysagotz":
return moment().tz(timezone).subtract(3, "day");
case "date.7daysagotz":
return moment().tz(timezone).subtract(7, "day");
case "date.tomorrowtz":
return moment().tz(timezone).add(1, "day");
case "date.3daysfromnowtz":
return moment().tz(timezone).add(3, "day");
case "date.7daysfromnowtz":
return moment().tz(timezone).add(7, "day");
switch (f) {
case "date.today":
return moment().tz(timezone).format(isoFormat);
case "date.now":
return moment().tz(timezone);
case "date.yesterday":
return moment().tz(timezone).subtract(1, "day").format(isoFormat);
case "date.3daysago":
return moment().tz(timezone).subtract(3, "day").format(isoFormat);
case "date.7daysago":
return moment().tz(timezone).subtract(7, "day").format(isoFormat);
case "date.tomorrow":
return moment().tz(timezone).add(1, "day").format(isoFormat);
case "date.3daysfromnow":
return moment().tz(timezone).add(3, "day").format(isoFormat);
case "date.7daysfromnow":
return moment().tz(timezone).add(7, "day").format(isoFormat);
case "date.yesterdaytz":
return moment().tz(timezone).subtract(1, "day");
case "date.3daysagotz":
return moment().tz(timezone).subtract(3, "day");
case "date.7daysagotz":
return moment().tz(timezone).subtract(7, "day");
case "date.tomorrowtz":
return moment().tz(timezone).add(1, "day");
case "date.3daysfromnowtz":
return moment().tz(timezone).add(3, "day");
case "date.7daysfromnowtz":
return moment().tz(timezone).add(7, "day");
case "date.now":
return moment().tz(timezone);
default:
return f;
}
case "date.now":
return moment().tz(timezone);
default:
return f;
}
}