test(ocme): lots of changes to get it working in production
This commit is contained in:
@@ -1,16 +1,21 @@
|
||||
import axios from "axios";
|
||||
|
||||
export const ocmeInv = async (data: any) => {
|
||||
try {
|
||||
const res = await axios.post(
|
||||
"http://usday1vms010:3250/api/v1/getLaneData",
|
||||
{lane: data.lane, laneType: data.laneType},
|
||||
{headers: {"Content-Type": "application/json", Connection: "keep-alive"}}
|
||||
);
|
||||
// console.log(res.data.data);
|
||||
try {
|
||||
const res = await axios.post(
|
||||
"http://usday1vms010:3250/api/v1/getlanedata",
|
||||
{ lane: data.lane, laneType: data.laneType },
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Connection: "keep-alive",
|
||||
},
|
||||
}
|
||||
);
|
||||
// console.log(res.data.data);
|
||||
|
||||
return res.data.data;
|
||||
} catch (error: any) {
|
||||
console.log(error.code);
|
||||
}
|
||||
return res.data.data;
|
||||
} catch (error: any) {
|
||||
console.log(error.code);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,43 +1,67 @@
|
||||
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";
|
||||
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) => {
|
||||
// if we have sscc we will do everything here and ignore the rn even it its sent over
|
||||
if (data.sscc && !data.runningNr) {
|
||||
data.runningNr = data.sscc.slice(10, -1);
|
||||
}
|
||||
|
||||
if (!data.sscc && !data.runningNr) {
|
||||
// data.runningNr = data.sscc.slice(10, -1);
|
||||
return {success: false, message: "Missing data please try again", data: []};
|
||||
}
|
||||
|
||||
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,
|
||||
console.log(data);
|
||||
let newData = data;
|
||||
if (Array.isArray(data)) {
|
||||
newData = {
|
||||
sscc: data[1],
|
||||
areaFrom: data[0],
|
||||
completed: true,
|
||||
};
|
||||
}
|
||||
|
||||
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};
|
||||
}
|
||||
if (newData.sscc && !newData.runningNr) {
|
||||
newData.runningNr = newData.sscc.slice(10, -1);
|
||||
}
|
||||
if (!newData.sscc && !newData.runningNr) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Missing data please try again",
|
||||
data: [],
|
||||
};
|
||||
}
|
||||
let label;
|
||||
const filterQuery = labelData.replaceAll("[rn]", newData.runningNr);
|
||||
try {
|
||||
label = await query(filterQuery, "Label data");
|
||||
} catch (error) {
|
||||
createLog(
|
||||
"error",
|
||||
"ocme",
|
||||
"ocme",
|
||||
"There was an error getting the labelData"
|
||||
);
|
||||
}
|
||||
const newPost = {
|
||||
sscc: newData.sscc ? newData.sscc : await createSSCC(newData.runningNr),
|
||||
runningNr: newData.runningNr,
|
||||
completed: newData.completed,
|
||||
lineNum: label[0].machineLocation,
|
||||
areaFrom: newData.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,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,60 +1,71 @@
|
||||
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
|
||||
import {apiHit} from "../../../globalUtils/apiHits.js";
|
||||
import {responses} from "../../../globalUtils/routeDefs/responses.js";
|
||||
import {authMiddleware} from "../../auth/middleware/authMiddleware.js";
|
||||
import {cycleCount} from "../controller/cycleCount.js";
|
||||
import type {User} from "../../../types/users.js";
|
||||
import {verify} from "hono/jwt";
|
||||
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||
import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
|
||||
import { cycleCount } from "../controller/cycleCount.js";
|
||||
import type { User } from "../../../types/users.js";
|
||||
import { verify } from "hono/jwt";
|
||||
|
||||
const app = new OpenAPIHono({strict: false});
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
|
||||
const AddSetting = z.object({
|
||||
lane: z.string().openapi({example: "L064"}),
|
||||
lane: z.string().openapi({ example: "L064" }),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["ocme"],
|
||||
summary: "Cycle counts a lane based on the lane Alias",
|
||||
method: "post",
|
||||
path: "/cyclecount",
|
||||
middleware: authMiddleware,
|
||||
request: {
|
||||
body: {
|
||||
content: {
|
||||
"application/json": {schema: AddSetting},
|
||||
},
|
||||
},
|
||||
createRoute({
|
||||
tags: ["ocme"],
|
||||
summary: "Cycle counts a lane based on the lane Alias",
|
||||
method: "post",
|
||||
path: "/cycleCount",
|
||||
middleware: authMiddleware,
|
||||
request: {
|
||||
body: {
|
||||
content: {
|
||||
"application/json": { schema: AddSetting },
|
||||
},
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
apiHit(c, {endpoint: "api/auth/register"});
|
||||
// make sure we have a vaid user being accessed thats really logged in
|
||||
const body = await c.req.json();
|
||||
},
|
||||
},
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
apiHit(c, { endpoint: "api/auth/register" });
|
||||
// make sure we have a vaid user being accessed thats really logged in
|
||||
const body = await c.req.json();
|
||||
|
||||
const authHeader = c.req.header("Authorization");
|
||||
const authHeader = c.req.header("Authorization");
|
||||
|
||||
const token = authHeader?.split("Bearer ")[1] || "";
|
||||
let user: User;
|
||||
const token = authHeader?.split("Bearer ")[1] || "";
|
||||
let user: User;
|
||||
|
||||
try {
|
||||
const payload = await verify(token, process.env.JWT_SECRET!);
|
||||
user = payload.user as User;
|
||||
} catch (error) {
|
||||
return c.json({message: "Unauthorized"}, 401);
|
||||
}
|
||||
|
||||
try {
|
||||
const cycleData = await cycleCount(body, user);
|
||||
return c.json({success: true, message: `${body.lane} was just cycle counted.`, data: cycleData}, 200);
|
||||
} catch (error) {
|
||||
return c.json(
|
||||
{success: false, message: `There was an error cycle counting ${body.lane}`, data: error},
|
||||
400
|
||||
);
|
||||
}
|
||||
try {
|
||||
const payload = await verify(token, process.env.JWT_SECRET!);
|
||||
user = payload.user as User;
|
||||
} catch (error) {
|
||||
return c.json({ message: "Unauthorized" }, 401);
|
||||
}
|
||||
|
||||
try {
|
||||
const cycleData = await cycleCount(body, user);
|
||||
return c.json(
|
||||
{
|
||||
success: true,
|
||||
message: `${body.lane} was just cycle counted.`,
|
||||
data: cycleData,
|
||||
},
|
||||
200
|
||||
);
|
||||
} catch (error) {
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
message: `There was an error cycle counting ${body.lane}`,
|
||||
data: error,
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
|
||||
@@ -1,81 +1,96 @@
|
||||
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
|
||||
import {getInfo} from "../controller/getInfo.js";
|
||||
import {apiHit} from "../../../globalUtils/apiHits.js";
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { getInfo } from "../controller/getInfo.js";
|
||||
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||
|
||||
const app = new OpenAPIHono({strict: false});
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
|
||||
const AddSetting = z.object({
|
||||
name: z.string().openapi({example: "server"}),
|
||||
value: z.string().openapi({example: "localhost"}),
|
||||
description: z.string().openapi({example: "The server we are going to connect to"}),
|
||||
roles: z.string().openapi({example: "admin"}),
|
||||
module: z.string().openapi({example: "production"}),
|
||||
name: z.string().openapi({ example: "server" }),
|
||||
value: z.string().openapi({ example: "localhost" }),
|
||||
description: z
|
||||
.string()
|
||||
.openapi({ example: "The server we are going to connect to" }),
|
||||
roles: z.string().openapi({ example: "admin" }),
|
||||
module: z.string().openapi({ example: "production" }),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["ocme"],
|
||||
summary: "Get all current info",
|
||||
method: "get",
|
||||
path: "/getinfo",
|
||||
request: {
|
||||
body: {
|
||||
content: {
|
||||
"application/json": {schema: AddSetting},
|
||||
},
|
||||
},
|
||||
createRoute({
|
||||
tags: ["ocme"],
|
||||
summary: "Get all current info",
|
||||
method: "get",
|
||||
path: "/getInfo",
|
||||
request: {
|
||||
body: {
|
||||
content: {
|
||||
"application/json": { schema: AddSetting },
|
||||
},
|
||||
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({})).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",
|
||||
// },
|
||||
},
|
||||
},
|
||||
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({})).optional().openapi({ example: [] }),
|
||||
}),
|
||||
},
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
// make sure we have a vaid user being accessed thats really logged in
|
||||
apiHit(c, {endpoint: "api/auth/register"});
|
||||
try {
|
||||
return c.json({success: true, message: "Ocme Info", data: await getInfo()}, 200);
|
||||
} catch (error) {
|
||||
return c.json({success: false, message: "There was an error getting ocmeInfo data", data: error}, 400);
|
||||
}
|
||||
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
|
||||
apiHit(c, { endpoint: "api/auth/register" });
|
||||
try {
|
||||
return c.json(
|
||||
{ success: true, message: "Ocme Info", data: await getInfo() },
|
||||
200
|
||||
);
|
||||
} catch (error) {
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
message: "There was an error getting ocmeInfo data",
|
||||
data: error,
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
|
||||
@@ -1,94 +1,114 @@
|
||||
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
|
||||
import {apiHit} from "../../../globalUtils/apiHits.js";
|
||||
import {getShipmentPallets} from "../controller/getShipmentPallets.js";
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||
import { getShipmentPallets } from "../controller/getShipmentPallets.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
const ShipmentID = z.object({
|
||||
shipmentID: z.string().optional().openapi({example: "14558"}),
|
||||
shipmentID: z.string().optional().openapi({ example: "14558" }),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["ocme"],
|
||||
summary: "Post New running number to be picked up.",
|
||||
method: "post",
|
||||
path: "/getshipmentpallets",
|
||||
request: {
|
||||
body: {
|
||||
content: {
|
||||
"application/json": {schema: ShipmentID},
|
||||
},
|
||||
},
|
||||
createRoute({
|
||||
tags: ["ocme"],
|
||||
summary: "Post New running number to be picked up.",
|
||||
method: "post",
|
||||
path: "/GetShipmentPallets",
|
||||
request: {
|
||||
body: {
|
||||
content: {
|
||||
"application/json": { schema: ShipmentID },
|
||||
},
|
||||
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",
|
||||
// },
|
||||
},
|
||||
},
|
||||
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: []}),
|
||||
}),
|
||||
},
|
||||
},
|
||||
}),
|
||||
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/getshipmentpallets", lastBody: data});
|
||||
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/getshipmentpallets", lastBody: data });
|
||||
|
||||
if (!data.shipmentID) {
|
||||
return c.json(
|
||||
{success: false, message: "You are missing the shipment id please try again.", data: []},
|
||||
400
|
||||
);
|
||||
}
|
||||
console.log;
|
||||
|
||||
const shiptmentData = await getShipmentPallets(data.shipmentID);
|
||||
if (!data.shipmentID) {
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
message: "You are missing the shipment id please try again.",
|
||||
data: [],
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
return c.json(
|
||||
{success: shiptmentData.success, message: shiptmentData.message, data: shiptmentData.data ?? []},
|
||||
200
|
||||
);
|
||||
} catch (error) {
|
||||
return c.json({success: false, message: "There was an error getting the shipment data.", data: error}, 400);
|
||||
}
|
||||
const shiptmentData = await getShipmentPallets(data.shipmentID);
|
||||
|
||||
return c.json(
|
||||
{
|
||||
success: shiptmentData.success,
|
||||
message: shiptmentData.message,
|
||||
data: shiptmentData.data ?? [],
|
||||
},
|
||||
200
|
||||
);
|
||||
} catch (error) {
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
message: "There was an error getting the shipment data.",
|
||||
data: error,
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
|
||||
@@ -1,89 +1,114 @@
|
||||
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
|
||||
import {postLabelData} from "../controller/postRunningNr.js";
|
||||
import {apiHit} from "../../../globalUtils/apiHits.js";
|
||||
import {pickedup} from "../controller/pickedup.js";
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { postLabelData } from "../controller/postRunningNr.js";
|
||||
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||
import { pickedup } from "../controller/pickedup.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}),
|
||||
all: z.boolean().optional().openapi({example: false}),
|
||||
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 }),
|
||||
all: z.boolean().optional().openapi({ example: false }),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["ocme"],
|
||||
summary: "Picks up a pallet in the system.",
|
||||
method: "patch",
|
||||
description:
|
||||
"removes the pallet(s) from showing as needed to be picked up, we clear everything related to the pallet number to reduce the risk of a mix, passing `all` will just clear everything that is pending.",
|
||||
path: "/pickedup",
|
||||
request: {
|
||||
body: {
|
||||
content: {
|
||||
"application/json": {schema: PostRunningNr},
|
||||
},
|
||||
},
|
||||
createRoute({
|
||||
tags: ["ocme"],
|
||||
summary: "Picks up a pallet in the system.",
|
||||
method: "patch",
|
||||
description:
|
||||
"removes the pallet(s) from showing as needed to be picked up, we clear everything related to the pallet number to reduce the risk of a mix, passing `all` will just clear everything that is pending.",
|
||||
path: "/pickedUp",
|
||||
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",
|
||||
},
|
||||
},
|
||||
},
|
||||
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: []}),
|
||||
}),
|
||||
},
|
||||
},
|
||||
}),
|
||||
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/pickedup", lastBody: data});
|
||||
const postPallet = await pickedup(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);
|
||||
}
|
||||
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/pickedup", lastBody: data });
|
||||
const postPallet = await pickedup(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;
|
||||
|
||||
@@ -1,86 +1,106 @@
|
||||
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";
|
||||
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}),
|
||||
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: "/postrunningnumber",
|
||||
request: {
|
||||
body: {
|
||||
content: {
|
||||
"application/json": {schema: PostRunningNr},
|
||||
},
|
||||
},
|
||||
createRoute({
|
||||
tags: ["ocme"],
|
||||
summary: "Post New running number to be picked up.",
|
||||
method: "post",
|
||||
path: "/postRunningNumber",
|
||||
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",
|
||||
// },
|
||||
},
|
||||
},
|
||||
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: []}),
|
||||
}),
|
||||
},
|
||||
},
|
||||
}),
|
||||
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);
|
||||
}
|
||||
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;
|
||||
|
||||
@@ -1,64 +1,79 @@
|
||||
import net from "net";
|
||||
import {OpenAPIHono} from "@hono/zod-openapi";
|
||||
import {createLog} from "../logger/logger.js";
|
||||
import { OpenAPIHono } from "@hono/zod-openapi";
|
||||
import { createLog } from "../logger/logger.js";
|
||||
|
||||
import startTCP from "./route/startServer.js";
|
||||
import stopTCP from "./route/stopServer.js";
|
||||
import restartTCP from "./route/restartServer.js";
|
||||
import {db} from "../../../database/dbclient.js";
|
||||
import {settings} from "../../../database/schema/settings.js";
|
||||
import {eq} from "drizzle-orm";
|
||||
import { db } from "../../../database/dbclient.js";
|
||||
import { settings } from "../../../database/schema/settings.js";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { postLabelData } from "../ocme/controller/postRunningNr.js";
|
||||
|
||||
let tcpServer: net.Server;
|
||||
let tcpSockets: Set<net.Socket> = new Set();
|
||||
let isServerRunning = false;
|
||||
|
||||
const tcpPort = await db.select().from(settings).where(eq(settings.name, "tcpPort"));
|
||||
const tcpPort = await db
|
||||
.select()
|
||||
.from(settings)
|
||||
.where(eq(settings.name, "tcpPort"));
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
export const startTCPServer = () => {
|
||||
if (isServerRunning) return {success: false, message: "Server is already running"};
|
||||
if (isServerRunning)
|
||||
return { success: false, message: "Server is already running" };
|
||||
|
||||
tcpServer = net.createServer((socket) => {
|
||||
console.log("Client connected");
|
||||
tcpServer = net.createServer((socket) => {
|
||||
console.log("Client connected");
|
||||
|
||||
tcpSockets.add(socket);
|
||||
socket.on("data", (data: Buffer) => {
|
||||
console.log("Received:", data.toString());
|
||||
socket.write("Message received");
|
||||
});
|
||||
|
||||
socket.on("end", () => {
|
||||
console.log("Client disconnected");
|
||||
tcpSockets.delete(socket);
|
||||
});
|
||||
|
||||
socket.on("error", (err: Error) => {
|
||||
console.error("Socket error:", err);
|
||||
tcpSockets.delete(socket);
|
||||
});
|
||||
tcpSockets.add(socket);
|
||||
socket.on("data", (data: Buffer) => {
|
||||
console.log("Received:", data.toString());
|
||||
const parseData = data.toString("utf-8").trimEnd().split(" ");
|
||||
if (parseData[0] === "HB") {
|
||||
return;
|
||||
}
|
||||
postLabelData(parseData);
|
||||
});
|
||||
|
||||
tcpServer.listen(tcpPort[0]?.value ?? 2222, () => {
|
||||
createLog("info", "lst", "tcp", `TCP Server listening on port ${tcpPort[0]?.value ?? 2222}`);
|
||||
socket.on("end", () => {
|
||||
console.log("Client disconnected");
|
||||
tcpSockets.delete(socket);
|
||||
});
|
||||
|
||||
isServerRunning = true;
|
||||
return {success: true, message: "TCP Server started"};
|
||||
socket.on("error", (err: Error) => {
|
||||
console.error("Socket error:", err);
|
||||
tcpSockets.delete(socket);
|
||||
});
|
||||
});
|
||||
|
||||
tcpServer.listen(tcpPort[0]?.value ?? 2222, () => {
|
||||
createLog(
|
||||
"info",
|
||||
"lst",
|
||||
"tcp",
|
||||
`TCP Server listening on port ${tcpPort[0]?.value ?? 2222}`
|
||||
);
|
||||
});
|
||||
|
||||
isServerRunning = true;
|
||||
return { success: true, message: "TCP Server started" };
|
||||
};
|
||||
|
||||
// Function to stop the TCP server
|
||||
export const stopTCPServer = () => {
|
||||
if (!isServerRunning) return {success: false, message: "Server is not running"};
|
||||
for (const socket of tcpSockets) {
|
||||
socket.destroy();
|
||||
}
|
||||
tcpSockets.clear();
|
||||
tcpServer.close(() => {
|
||||
console.log("TCP Server stopped");
|
||||
});
|
||||
isServerRunning = false;
|
||||
return {success: true, message: "TCP Server stopped"};
|
||||
if (!isServerRunning)
|
||||
return { success: false, message: "Server is not running" };
|
||||
for (const socket of tcpSockets) {
|
||||
socket.destroy();
|
||||
}
|
||||
tcpSockets.clear();
|
||||
tcpServer.close(() => {
|
||||
console.log("TCP Server stopped");
|
||||
});
|
||||
isServerRunning = false;
|
||||
return { success: true, message: "TCP Server stopped" };
|
||||
};
|
||||
|
||||
app.route("/tcpserver/start", startTCP);
|
||||
@@ -67,7 +82,7 @@ app.route("/tcpserver/restart", restartTCP);
|
||||
|
||||
// start the server after on system start up
|
||||
setTimeout(() => {
|
||||
startTCPServer();
|
||||
startTCPServer();
|
||||
}, 5000);
|
||||
|
||||
export default app;
|
||||
|
||||
Reference in New Issue
Block a user