feat(ocme): finalized posting RN and sscc just to keep it the same as ocme
This commit is contained in:
@@ -1,13 +1,43 @@
|
|||||||
|
import {db} from "../../../../database/dbclient.js";
|
||||||
|
import {ocmeData} from "../../../../database/schema/ocme.js";
|
||||||
|
import {createSSCC} from "../../../globalUtils/createSSCC.js";
|
||||||
|
import {createLog} from "../../logger/logger.js";
|
||||||
|
import {query} from "../../sqlServer/prodSqlServer.js";
|
||||||
|
import {labelData} from "../../sqlServer/querys/materialHelpers/labelInfo.js";
|
||||||
|
|
||||||
export const postLabelData = async (data: any) => {
|
export const postLabelData = async (data: any) => {
|
||||||
// if we have sscc we will do everything here and ignore the rn even it its sent over
|
// if we have sscc we will do everything here and ignore the rn even it its sent over
|
||||||
|
if (data.sscc && !data.runningNr) {
|
||||||
if (data.sscc) {
|
data.runningNr = data.sscc.slice(10, -1);
|
||||||
return {success: true, message: "sscc sent over", data: data};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.runningNr) {
|
if (!data.sscc && !data.runningNr) {
|
||||||
return {success: true, message: "runningNr sent over", data: data};
|
// data.runningNr = data.sscc.slice(10, -1);
|
||||||
} else {
|
return {success: false, message: "Missing data please try again", data: []};
|
||||||
throw Error("Improper data was sent over");
|
}
|
||||||
|
|
||||||
|
let label;
|
||||||
|
const filterQuery = labelData.replaceAll("[rn]", data.runningNr);
|
||||||
|
|
||||||
|
try {
|
||||||
|
label = await query(filterQuery, "Label data");
|
||||||
|
} catch (error) {
|
||||||
|
createLog("error", "ocme", "ocme", "There was an error getting the labelData");
|
||||||
|
}
|
||||||
|
const newPost = {
|
||||||
|
sscc: data.sscc ? data.sscc : await createSSCC(data.runningNr),
|
||||||
|
runningNr: data.runningNr,
|
||||||
|
completed: data.completed,
|
||||||
|
lineNum: label[0].machineLocation,
|
||||||
|
areaFrom: data.areaFrom,
|
||||||
|
pickedUp: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const enterNewData = await db.insert(ocmeData).values(newPost).returning({sscc: ocmeData.sscc});
|
||||||
|
return {success: true, message: "Data was posted to ocme info", data: enterNewData};
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
return {success: false, message: "Data was posted to ocme info", data: newPost};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
86
server/services/ocme/route/postSSCC.ts
Normal file
86
server/services/ocme/route/postSSCC.ts
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
|
||||||
|
import {getInfo} from "../controller/getInfo.js";
|
||||||
|
import {postLabelData} from "../controller/postRunningNr.js";
|
||||||
|
import {apiHit} from "../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
|
const PostRunningNr = z.object({
|
||||||
|
sscc: z.string().optional().openapi({example: "00090103830005710997"}),
|
||||||
|
runningNr: z.string().optional().openapi({example: "localhost"}),
|
||||||
|
areaFrom: z.string().optional().openapi({example: "The server we are going to connect to"}),
|
||||||
|
completed: z.boolean().optional().openapi({example: true}),
|
||||||
|
});
|
||||||
|
|
||||||
|
app.openapi(
|
||||||
|
createRoute({
|
||||||
|
tags: ["ocme"],
|
||||||
|
summary: "Post New running number to be picked up.",
|
||||||
|
method: "post",
|
||||||
|
path: "/postsscc",
|
||||||
|
request: {
|
||||||
|
body: {
|
||||||
|
content: {
|
||||||
|
"application/json": {schema: PostRunningNr},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
responses: {
|
||||||
|
200: {
|
||||||
|
content: {
|
||||||
|
"application/json": {
|
||||||
|
schema: z.object({
|
||||||
|
success: z.boolean().openapi({example: true}),
|
||||||
|
message: z.string().openapi({example: "Starter"}),
|
||||||
|
// data: z
|
||||||
|
// .array(z.object({sscc: z.string().optional()}))
|
||||||
|
// .optional()
|
||||||
|
// .openapi({example: []}),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
description: "Response message",
|
||||||
|
},
|
||||||
|
400: {
|
||||||
|
content: {
|
||||||
|
"application/json": {
|
||||||
|
schema: z.object({
|
||||||
|
success: z.boolean().openapi({example: false}),
|
||||||
|
message: z.string().optional().openapi({example: "Internal Server error"}),
|
||||||
|
data: z.array(z.object({})).optional().openapi({example: []}),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
description: "Internal Server Error",
|
||||||
|
},
|
||||||
|
// 401: {
|
||||||
|
// content: {
|
||||||
|
// "application/json": {
|
||||||
|
// schema: z.object({message: z.string().optional().openapi({example: "Unauthenticated"})}),
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// description: "Unauthorized",
|
||||||
|
// },
|
||||||
|
// 500: {
|
||||||
|
// content: {
|
||||||
|
// "application/json": {
|
||||||
|
// schema: z.object({message: z.string().optional().openapi({example: "Internal Server error"})}),
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// description: "Internal Server Error",
|
||||||
|
// },
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
async (c) => {
|
||||||
|
// make sure we have a vaid user being accessed thats really logged in
|
||||||
|
try {
|
||||||
|
const data = await c.req.json();
|
||||||
|
apiHit(c, {endpoint: "api/ocme/postRunningNumber", lastBody: data});
|
||||||
|
const postPallet = await postLabelData(data);
|
||||||
|
return c.json({success: postPallet.success, message: postPallet.message, data: postPallet.data ?? []}, 200);
|
||||||
|
} catch (error) {
|
||||||
|
return c.json({success: false, message: "There was an error getting ocmeInfo data", data: error}, 400);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
export default app;
|
||||||
Reference in New Issue
Block a user