52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
// import {prisma} from "database";
|
|
// import {createLog} from "logging";
|
|
|
|
import { lte, sql } from "drizzle-orm";
|
|
import { db } from "../../../../database/dbclient.js";
|
|
import { invHistoricalData } from "../../../../database/schema/historicalINV.js";
|
|
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
|
import { createLog } from "../../logger/logger.js";
|
|
|
|
// export const deleteHistory = async (date: string) => {
|
|
// // delete the inventory if it equals this date
|
|
// try {
|
|
// const remove = await prisma.$executeRaw`
|
|
// DELETE FROM historyInventory
|
|
// WHERE histDate < ${date}
|
|
// `;
|
|
// createLog("general/eom", "info", `${remove} were just remove from the historical inventory for date: ${date}`);
|
|
// } catch (error) {
|
|
// createLog("general/eom", "error", `Removing historical inventory error: ${error}`);
|
|
// }
|
|
// };
|
|
|
|
export const deleteHistory = async () => {
|
|
const { data, error } = await tryCatch(
|
|
db
|
|
.delete(invHistoricalData)
|
|
.where(
|
|
lte(
|
|
invHistoricalData.histDate,
|
|
sql`(NOW() - INTERVAL '45 day')::date`
|
|
)
|
|
)
|
|
);
|
|
|
|
if (error) {
|
|
createLog(
|
|
"error",
|
|
"eom",
|
|
"eom",
|
|
"There was an error deleting the historical data."
|
|
);
|
|
return;
|
|
}
|
|
|
|
createLog(
|
|
"info",
|
|
"eom",
|
|
"eom",
|
|
"Data older than 45 days has been deleted."
|
|
);
|
|
};
|