feat(dm): standard forecast added in rest of migration to come
This commit is contained in:
49
backend/utils/excelTemplates.utils.ts
Normal file
49
backend/utils/excelTemplates.utils.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import * as XLSX from "xlsx";
|
||||
|
||||
export type Template = {
|
||||
name: string;
|
||||
headers: string[];
|
||||
};
|
||||
|
||||
export const excelTemplate = async (data: Template) => {
|
||||
/**
|
||||
* Creates the standard Template for bulk orders in
|
||||
*/
|
||||
|
||||
// const headers = [
|
||||
// [
|
||||
// "CustomerArticleNumber",
|
||||
// "CustomerOrderNumber",
|
||||
// "CustomerLineNumber",
|
||||
// "CustomerRealeaseNumber",
|
||||
// "Quantity",
|
||||
// "DeliveryDate",
|
||||
// "CustomerID",
|
||||
// "Remark",
|
||||
// // "InvoiceID",
|
||||
// ],
|
||||
// ];
|
||||
|
||||
// create a new workbook
|
||||
const wb = XLSX.utils.book_new();
|
||||
const ws = XLSX.utils.aoa_to_sheet([data.headers]);
|
||||
//const ws2 = XLSX.utils.aoa_to_sheet(headers2);
|
||||
|
||||
const columnWidths = data.headers.map((header) => ({
|
||||
width: header.length + 2,
|
||||
}));
|
||||
|
||||
ws["!cols"] = columnWidths;
|
||||
|
||||
// append the worksheet to the workbook
|
||||
XLSX.utils.book_append_sheet(wb, ws, `Sheet1`);
|
||||
//XLSX.utils.book_append_sheet(wb, ws2, `Sheet2`);
|
||||
|
||||
// Creates the file to disk'
|
||||
// XLSX.writeFile(wb, data.name);
|
||||
|
||||
// Write the workbook to a buffer and return it
|
||||
const excelBuffer = XLSX.write(wb, { bookType: "xlsx", type: "buffer" });
|
||||
|
||||
return excelBuffer;
|
||||
};
|
||||
28
backend/utils/excelToDate.utils.ts
Normal file
28
backend/utils/excelToDate.utils.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { getJsDateFromExcel } from "excel-date-to-js";
|
||||
|
||||
export const excelDateStuff = (serial: number, time?: any) => {
|
||||
if (typeof serial !== "number" || serial <= 0) {
|
||||
return "invalid Date";
|
||||
}
|
||||
|
||||
// Default time to 8:00 AM if not provided
|
||||
if (!time) {
|
||||
time = 800;
|
||||
}
|
||||
|
||||
// Get base date from Excel serial (this gives you UTC midnight)
|
||||
const date = getJsDateFromExcel(serial);
|
||||
|
||||
const localOffset = new Date().getTimezoneOffset() / 60;
|
||||
const hours = Math.floor(time / 100);
|
||||
const minutes = time % 100;
|
||||
|
||||
// Set the time in UTC
|
||||
date.setUTCHours(hours + localOffset);
|
||||
date.setUTCMinutes(minutes);
|
||||
date.setUTCSeconds(0);
|
||||
date.setUTCMilliseconds(0);
|
||||
|
||||
//console.log(date.toISOString(), serial, time);
|
||||
return date.toISOString();
|
||||
};
|
||||
@@ -1,5 +1,6 @@
|
||||
import https from "node:https";
|
||||
import axios from "axios";
|
||||
import { createLogger } from "../logger/logger.controller.js";
|
||||
import { returnFunc } from "./returnHelper.utils.js";
|
||||
import { tryCatch } from "./trycatch.utils.js";
|
||||
|
||||
@@ -59,9 +60,14 @@ export const prodEndpointCreation = async (endpoint: string) => {
|
||||
* @param timeoutDelay
|
||||
* @returns
|
||||
*/
|
||||
export const runProdApi = async (data: Data) => {
|
||||
export const runProdApi = async (data: Data, name?: string) => {
|
||||
const log = createLogger({ module: "utils", subModule: "prodEndpoints" });
|
||||
const url = await prodEndpointCreation(data.endpoint);
|
||||
|
||||
log.debug(
|
||||
{ stack: data },
|
||||
`Info passed over for ${name ? name : "Missing name"}`,
|
||||
);
|
||||
const { data: d, error } = await tryCatch(
|
||||
axios({
|
||||
method: data.method as string,
|
||||
@@ -94,7 +100,7 @@ export const runProdApi = async (data: Data) => {
|
||||
level: "error",
|
||||
module: "utils",
|
||||
subModule: "prodEndpoint",
|
||||
message: "Data from prod endpoint",
|
||||
message: "Error data from prod endpoint",
|
||||
data: d.data,
|
||||
notify: false,
|
||||
});
|
||||
@@ -104,10 +110,30 @@ export const runProdApi = async (data: Data) => {
|
||||
level: "error",
|
||||
module: "utils",
|
||||
subModule: "prodEndpoint",
|
||||
message: "Data from prod endpoint",
|
||||
message: "Error data from prod endpoint",
|
||||
data: d.data,
|
||||
notify: false,
|
||||
});
|
||||
case 500:
|
||||
return returnFunc({
|
||||
success: false,
|
||||
level: "error",
|
||||
module: "utils",
|
||||
subModule: "prodEndpoint",
|
||||
message: "Error data from prod endpoint",
|
||||
data: d.data,
|
||||
notify: false,
|
||||
});
|
||||
default:
|
||||
returnFunc({
|
||||
success: false,
|
||||
level: "error",
|
||||
module: "utils",
|
||||
subModule: "prodEndpoint",
|
||||
message: "Unknown error encountered",
|
||||
data: d?.data as any,
|
||||
notify: false,
|
||||
});
|
||||
}
|
||||
|
||||
if (error) {
|
||||
|
||||
@@ -18,7 +18,8 @@ export interface ReturnHelper<T = unknown[]> {
|
||||
| "admin"
|
||||
| "mobile"
|
||||
| "dockdoor"
|
||||
| "eom";
|
||||
| "eom"
|
||||
| "dm";
|
||||
subModule: string;
|
||||
|
||||
level: "info" | "error" | "debug" | "fatal" | "warn";
|
||||
|
||||
Reference in New Issue
Block a user