80 lines
2.5 KiB
TypeScript
80 lines
2.5 KiB
TypeScript
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
|
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
|
import { getOpenOrders } from "../../../dataMart/controller/getOpenOrders.js";
|
|
import axios from "axios";
|
|
import { getSiloAdjustments } from "../../controller/siloAdjustments/getSiloAdjustments.js";
|
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
|
|
|
const app = new OpenAPIHono({ strict: false });
|
|
// const Body = z.object({
|
|
// includeRunnningNumbers: z.string().openapi({ example: "x" }),
|
|
// });
|
|
app.openapi(
|
|
createRoute({
|
|
tags: ["dataMart"],
|
|
summary: "Returns All open orders.",
|
|
method: "get",
|
|
path: "/getsilosdjustment",
|
|
// request: {
|
|
// body: {
|
|
// content: {
|
|
// "application/json": { schema: Body },
|
|
// },
|
|
// },
|
|
// },
|
|
responses: responses(),
|
|
}),
|
|
async (c: any) => {
|
|
const customer: any = c.req.queries();
|
|
apiHit(c, { endpoint: "/getsilosdjustment" });
|
|
|
|
// make sure we have a vaid user being accessed thats really logged in
|
|
//apiHit(c, { endpoint: `api/logger/logs/id` });
|
|
// const { data, error } = await tryCatch(
|
|
// getOpenOrders(customer ? customer : null)
|
|
// );
|
|
|
|
// if (error) {
|
|
// return c.json(
|
|
// {
|
|
// success: false,
|
|
// message: "There was an error getting the inv.",
|
|
// data: error,
|
|
// },
|
|
// 400
|
|
// );
|
|
// }
|
|
|
|
const dates: any = c.req.queries();
|
|
|
|
// const { data, error } = await tryCatch(
|
|
// axios.get(
|
|
// `/api/v1/warehouse/getSilosAdjustment?startDate=${dates.startDate[0]}&endDate=${dates.endDate[0]}`
|
|
// )
|
|
// );
|
|
const startDate = dates.startDate ? dates.startDate[0] : null;
|
|
const endDate = dates.endDate ? dates.endDate[0] : null;
|
|
|
|
const { data, error } = await tryCatch(
|
|
getSiloAdjustments(startDate, endDate)
|
|
);
|
|
|
|
if (error) {
|
|
console.log(error);
|
|
return c.json({
|
|
success: false,
|
|
message: "Error running query",
|
|
data: error,
|
|
});
|
|
}
|
|
|
|
return c.json({
|
|
success: data?.success,
|
|
message: data?.message,
|
|
data: data?.data,
|
|
});
|
|
}
|
|
);
|
|
export default app;
|