feat(eom): lastSales, lastPurch added to be pulled with new template
This commit is contained in:
32
server/services/eom/controller/getHistoricalInvByDate.ts
Normal file
32
server/services/eom/controller/getHistoricalInvByDate.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "../../../../database/dbclient.js";
|
||||
import { invHistoricalData } from "../../../../database/schema/historicalINV.js";
|
||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||
import { format } from "date-fns";
|
||||
|
||||
export const historicalInvByDate = async (date: string) => {
|
||||
const histDate = new Date(date);
|
||||
|
||||
const { data, error } = (await tryCatch(
|
||||
db
|
||||
.select()
|
||||
.from(invHistoricalData)
|
||||
.where(
|
||||
eq(invHistoricalData.histDate, format(histDate, "yyyy-MM-dd"))
|
||||
)
|
||||
)) as any;
|
||||
|
||||
if (error) {
|
||||
return {
|
||||
success: false,
|
||||
message: "There was an error with getting the inventory",
|
||||
data: error,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `Historical inventory for ${date}`,
|
||||
data: data,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user