import { tryCatch } from "../../../globalUtils/tryCatch.js"; import { createLog } from "../../logger/logger.js"; import { query } from "../../sqlServer/prodSqlServer.js"; import { planningNumbersByAVDate } from "../../sqlServer/querys/psiReport/planningNumbersByAv.js"; import { improvedPsiPlanningInfo } from "./psiPlanningDataImproved.js"; // type ArticleData = { // id: string // } export const psiGetPlanningData = async ( avs: string, startDate: string, endDate: string, ) => { let articles: any = []; if (!avs) { return { success: false, message: `Missing av's please send at least one over`, data: [], }; } const { data, error } = (await tryCatch( query( planningNumbersByAVDate .replace("[articles]", avs) .replace("[startDate]", startDate) .replace("[endDate]", endDate), "PSI planning info", ), )) as any; // improvedPsiPlanningInfo({ // avs, // startDate, // endDate, // }); if (error) { createLog( "error", "datamart", "datamart", `There was an error getting the planning info: ${JSON.stringify(error)}`, ); return { success: false, messsage: `There was an error getting the planning info`, data: error, }; } // TODO: if we are not running planning we no pass the old structure if we are running new planning use the below improved version that makes sure we dont have negative numebrs. articles = data.data; return { success: true, message: "PSI planning Data", data: await improvedPsiPlanningInfo({ avs, startDate, endDate, }), // data: articles.map((n: any) => { // if (n.PalDay) { // return { ...n, PalDay: n.PalDay.toFixed(2) }; // } // return n; // }), }; };