feat(lstv2 move): moved lstv2 into this app to keep them combined and easier to maintain
This commit is contained in:
69
lstV2/server/services/dataMart/route/getFinanceAudit.ts
Normal file
69
lstV2/server/services/dataMart/route/getFinanceAudit.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||
import { getfinanceAudit } from "../controller/getFinanceAudit.js";
|
||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
const EomStat = z.object({
|
||||
plant: z.string().openapi({ example: "Salt Lake City" }),
|
||||
userRan: z.string().openapi({ example: "smith034" }),
|
||||
eomSheetVersion: z.string().openapi({ example: "0.0.223" }),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["dataMart"],
|
||||
summary:
|
||||
"Returns inventory to date and current sales prices and booking date of the inventory.",
|
||||
method: "get",
|
||||
path: "/getfinanceaudit",
|
||||
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c: any) => {
|
||||
//const body = await c.req.json();
|
||||
// make sure we have a vaid user being accessed thats really logged in
|
||||
const { data, error } = (await tryCatch(c.req.query())) as any;
|
||||
|
||||
//console.log(data.date);
|
||||
|
||||
if (error) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Missing Mandatory Data",
|
||||
data: error,
|
||||
};
|
||||
}
|
||||
|
||||
if (!data.date) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Missing Date",
|
||||
data: [],
|
||||
};
|
||||
}
|
||||
apiHit(c, { endpoint: "/getfinanceaudit", lastBody: data });
|
||||
|
||||
try {
|
||||
return c.json(
|
||||
{
|
||||
success: true,
|
||||
message: `Inventory older than ${data.date}`,
|
||||
data: await getfinanceAudit(data.date),
|
||||
},
|
||||
200
|
||||
);
|
||||
} catch (error) {
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
message: "There was an error getting inventory data",
|
||||
data: error,
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
Reference in New Issue
Block a user