feat(ocp): added labeling logs in
This commit is contained in:
32
server/services/ocp/controller/labeling/getLabels.ts
Normal file
32
server/services/ocp/controller/labeling/getLabels.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { desc, lte, sql } from "drizzle-orm";
|
||||
import { db } from "../../../../../database/dbclient.js";
|
||||
import { prodlabels } from "../../../../../database/schema/prodLabels.js";
|
||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||
export const getLabels = async (hours: string) => {
|
||||
const { data: labelInfo, error: labelError } = await tryCatch(
|
||||
db
|
||||
.select()
|
||||
.from(prodlabels)
|
||||
.where(
|
||||
lte(
|
||||
prodlabels.upd_date,
|
||||
sql.raw(`NOW() - INTERVAL '${hours} hours'`)
|
||||
)
|
||||
)
|
||||
.orderBy(desc(prodlabels.upd_date))
|
||||
);
|
||||
|
||||
if (labelError) {
|
||||
return {
|
||||
success: false,
|
||||
message: "There was an error getting the labels",
|
||||
data: labelError,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Current labels order by upd_Date.",
|
||||
data: labelInfo,
|
||||
};
|
||||
};
|
||||
37
server/services/ocp/routes/labeling/getLabels.ts
Normal file
37
server/services/ocp/routes/labeling/getLabels.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
// an external way to creating logs
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||
import { getLabels } from "../../controller/labeling/getLabels.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["ocp"],
|
||||
summary: "Returns current active lots that are tech released",
|
||||
method: "get",
|
||||
path: "/getlabels",
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
const hours = c.req.query("hours");
|
||||
const { data: labelData, error: labelError } = await tryCatch(
|
||||
getLabels(hours ?? "2")
|
||||
);
|
||||
|
||||
if (labelError) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "There was an error getting the printers",
|
||||
});
|
||||
}
|
||||
|
||||
return c.json({
|
||||
success: labelData.success,
|
||||
message: labelData.message,
|
||||
data: labelData.data,
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
Reference in New Issue
Block a user