feat(apihits): so i can see if what end points are being used and when and how often

This commit is contained in:
2025-05-15 20:55:17 -05:00
parent 12ea23c9fb
commit 9d9a2683fa
86 changed files with 15710 additions and 496 deletions

View File

@@ -1,12 +1,17 @@
import type {Context} from "hono";
import {z, ZodError} from "zod";
import type { Context } from "hono";
import { z, ZodError } from "zod";
import { getConnInfo } from "@hono/node-server/conninfo";
import { tryCatch } from "./tryCatch.js";
import { db } from "../../database/dbclient.js";
import { apiHits } from "../../database/schema/apiHits.js";
import { sql } from "drizzle-orm";
// Define the request body schema
const requestSchema = z.object({
ip: z.string().optional(),
endpoint: z.string(),
action: z.string().optional(),
lastBody: z.string().optional(),
lastBody: z.array(z.object({})).or(z.object({})).optional(),
stats: z.string().optional(),
});
@@ -15,8 +20,9 @@ type ApiHitData = z.infer<typeof requestSchema>;
export const apiHit = async (
c: Context,
data: ApiHitData
): Promise<{success: boolean; data?: ApiHitData; errors?: any[]}> => {
// console.log(data);
): Promise<{ success: boolean; data?: ApiHitData; errors?: any[] }> => {
const info = getConnInfo(c);
// console.log(`Your remote address is ${info.remote.address}`);
try {
// Extract IP from request headers or connection info
const forwarded = c.req.header("host");
@@ -24,24 +30,45 @@ export const apiHit = async (
//console.log(forwarded);
// Validate the data
const checkData = {
ip: forwarded!,
ip: info.remote.address!,
endpoint: data?.endpoint,
lastBody: data?.lastBody,
action: data?.action,
stats: data?.stats,
//stats: data?.stats,
};
const validatedData = requestSchema.parse(checkData);
const { data: apitHitData, error } = await tryCatch(
db
.insert(apiHits)
.values(checkData)
.onConflictDoUpdate({
target: [apiHits.endpoint, apiHits.ip],
set: {
stats: sql`${apiHits.stats} + 1`,
lastBody: data?.lastBody,
action: data?.action,
upd_date: sql`NOW()`,
},
})
);
if (error) {
console.log(error);
}
// Proceed with the validated data
return {success: true, data: validatedData};
return { success: true, data: validatedData };
} catch (error) {
// Explicitly check if the error is an instance of ZodError
if (error instanceof ZodError) {
// console.log({success: false, errors: error.errors});
return {success: false, errors: error.errors};
console.log({ success: false, errors: error.errors });
return { success: false, errors: error.errors };
}
// Catch other unexpected errors
return {success: false, errors: [{message: "An unknown error occurred"}]};
return {
success: false,
errors: [{ message: "An unknown error occurred" }],
};
}
};

View File

@@ -3,6 +3,7 @@ import { responses } from "../../../globalUtils/routeDefs/responses.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { getINV } from "../controller/getinventory.js";
import { getFakeEDI } from "../controller/fakeEDIUpdate.js";
import { apiHit } from "../../../globalUtils/apiHits.js";
const app = new OpenAPIHono({ strict: false });
const Body = z.object({
@@ -27,7 +28,7 @@ app.openapi(
const address: string = c.req.query("address") ?? "";
// make sure we have a vaid user being accessed thats really logged in
//apiHit(c, { endpoint: `api/logger/logs/id` });
apiHit(c, { endpoint: "/fakeediupdate" });
const { data, error } = await tryCatch(
getFakeEDI(address.toString() ?? "")
);

View File

@@ -22,7 +22,7 @@ app.openapi(
async (c) => {
//const body = await c.req.json();
// make sure we have a vaid user being accessed thats really logged in
//apiHit(c, { endpoint: `api/logger/logs/id` });
apiHit(c, { endpoint: "/getarticles" });
try {
return c.json(
{

View File

@@ -1,5 +1,6 @@
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { responses } from "../../../globalUtils/routeDefs/responses.js";
import { apiHit } from "../../../globalUtils/apiHits.js";
const app = new OpenAPIHono({ strict: false });
const current: any = [
@@ -108,7 +109,7 @@ app.openapi(
async (c) => {
//const body = await c.req.json();
// make sure we have a vaid user being accessed thats really logged in
//apiHit(c, { endpoint: `api/logger/logs/id` });
apiHit(c, { endpoint: "/getavalibleaquerys" });
return c.json({
success: true,

View File

@@ -3,6 +3,7 @@ import { responses } from "../../../globalUtils/routeDefs/responses.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { getINV } from "../controller/getinventory.js";
import { getCurrentCustomerInv } from "../controller/getCustomerInventory.js";
import { apiHit } from "../../../globalUtils/apiHits.js";
const app = new OpenAPIHono({ strict: false });
const Body = z.object({
@@ -27,7 +28,7 @@ app.openapi(
const customer: string = c.req.query("customer") ?? "";
// make sure we have a vaid user being accessed thats really logged in
//apiHit(c, { endpoint: `api/logger/logs/id` });
apiHit(c, { endpoint: "/getcustomerinventory" });
const { data, error } = await tryCatch(
getCurrentCustomerInv(customer ? customer : null)
);

View File

@@ -2,6 +2,7 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { responses } from "../../../globalUtils/routeDefs/responses.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { getDeliveryByDateRange } from "../controller/getDeliveryByDateRange.js";
import { apiHit } from "../../../globalUtils/apiHits.js";
const app = new OpenAPIHono({ strict: false });
const Body = z.object({
@@ -26,7 +27,7 @@ app.openapi(
const delivery: any = c.req.queries();
// make sure we have a vaid user being accessed thats really logged in
//apiHit(c, { endpoint: `api/logger/logs/id` });
apiHit(c, { endpoint: "/deliverybydaterange" });
const { data, error } = await tryCatch(
getDeliveryByDateRange(delivery ? delivery : null)
);

View File

@@ -2,6 +2,7 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { responses } from "../../../globalUtils/routeDefs/responses.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { getINV } from "../controller/getinventory.js";
import { apiHit } from "../../../globalUtils/apiHits.js";
const app = new OpenAPIHono({ strict: false });
const Body = z.object({
@@ -27,7 +28,7 @@ app.openapi(
c.req.query("includeRunnningNumbers") ?? "";
// make sure we have a vaid user being accessed thats really logged in
//apiHit(c, { endpoint: `api/logger/logs/id` });
apiHit(c, { endpoint: "/getinventory" });
const { data, error } = await tryCatch(
getINV(includeRunnningNumbers?.length > 0 ? true : false)
);

View File

@@ -2,6 +2,7 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { responses } from "../../../globalUtils/routeDefs/responses.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { getOpenOrders } from "../controller/getOpenOrders.js";
import { apiHit } from "../../../globalUtils/apiHits.js";
const app = new OpenAPIHono({ strict: false });
// const Body = z.object({
@@ -26,7 +27,7 @@ app.openapi(
const customer: any = c.req.queries();
// make sure we have a vaid user being accessed thats really logged in
//apiHit(c, { endpoint: `api/logger/logs/id` });
apiHit(c, { endpoint: "/getopenorders" });
const { data, error } = await tryCatch(
getOpenOrders(customer ? customer : null)
);

View File

@@ -23,7 +23,7 @@ app.openapi(
async (c) => {
//const body = await c.req.json();
// make sure we have a vaid user being accessed thats really logged in
//apiHit(c, { endpoint: `api/logger/logs/id` });
apiHit(c, { endpoint: "/histinv" });
try {
return c.json({ success: true, message: "", data: [] }, 200);
} catch (error) {

View File

@@ -23,7 +23,7 @@ app.openapi(
async (c) => {
//const body = await c.req.json();
// make sure we have a vaid user being accessed thats really logged in
apiHit(c, { endpoint: `api/logger/logs/id` });
apiHit(c, { endpoint: "/stats" });
try {
return c.json({ success: true, message: "", data: [] }, 200);
} catch (error) {

View File

@@ -4,6 +4,7 @@ import { apiHit } from "../../../globalUtils/apiHits.js";
import { verify } from "hono/jwt";
import { consumeMaterial } from "../controller/materials/consumeMaterial.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
const app = new OpenAPIHono();
@@ -37,7 +38,19 @@ app.openapi(
},
}),
async (c) => {
apiHit(c, { endpoint: "api/sqlProd/close" });
const { data, error } = await tryCatch(c.req.json());
if (error) {
return c.json(
{
success: false,
message: "Missing data please try again",
error,
},
400
);
}
apiHit(c, { endpoint: "/consume", lastBody: data });
const authHeader = c.req.header("Authorization");
const token = authHeader?.split("Bearer ")[1] || "";
@@ -45,7 +58,7 @@ app.openapi(
const payload = await verify(token, process.env.JWT_SECRET!);
try {
//return apiReturn(c, true, access?.message, access?.data, 200);
const data = await c.req.json();
const consume = await consumeMaterial(data, payload);
return c.json(
{ success: consume?.success, message: consume?.message },

View File

@@ -3,6 +3,7 @@ import { responses } from "../../../../globalUtils/routeDefs/responses.js";
import { ordersIn } from "../../controller/dm/ordersIn/ordersIn.js";
import { verify } from "hono/jwt";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";
const app = new OpenAPIHono();
@@ -31,7 +32,7 @@ app.openapi(
responses: responses(),
}),
async (c) => {
//apiHit(c, { endpoint: "api/sqlProd/close" });
apiHit(c, { endpoint: "/postbulkorders" });
const body = await c.req.parseBody();
const authHeader = c.req.header("Authorization");
const token = authHeader?.split("Bearer ")[1] || "";

View File

@@ -4,6 +4,7 @@ import { ordersIn } from "../../controller/dm/ordersIn/ordersIn.js";
import { verify } from "hono/jwt";
import { forecastIn } from "../../controller/dm/forecast/forecastIn.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";
const app = new OpenAPIHono();
@@ -32,7 +33,7 @@ app.openapi(
responses: responses(),
}),
async (c) => {
//apiHit(c, { endpoint: "api/sqlProd/close" });
apiHit(c, { endpoint: "/postforecastin" });
const body = await c.req.parseBody();
const authHeader = c.req.header("Authorization");
const token = authHeader?.split("Bearer ")[1] || "";

View File

@@ -4,6 +4,7 @@ import { responses } from "../../../../globalUtils/routeDefs/responses.js";
import { standardTemplate } from "../../controller/dm/ordersIn/createTemplate.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { standardForCastTemplate } from "../../controller/dm/forecast/createTemplate.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";
const app = new OpenAPIHono();
@@ -32,7 +33,7 @@ app.openapi(
responses: responses(),
}),
async (c: any) => {
//apiHit(c, { endpoint: "api/sqlProd/close" });
apiHit(c, { endpoint: "/bulkforcasttemplate" });
const defaultFilename = `bulkForcastTemplate-${format(
new Date(Date.now()),
"M-d-yyyy"

View File

@@ -3,6 +3,7 @@ import { format } from "date-fns";
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
import { standardTemplate } from "../../controller/dm/ordersIn/createTemplate.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";
const app = new OpenAPIHono();
@@ -31,7 +32,7 @@ app.openapi(
responses: responses(),
}),
async (c: any) => {
//apiHit(c, { endpoint: "api/sqlProd/close" });
apiHit(c, { endpoint: "/bulkorderstemplate" });
const defaultFilename = `bulkOrdersInTemplate-${format(
new Date(Date.now()),
"M-d-yyyy"

View File

@@ -2,6 +2,7 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { responses } from "../../../globalUtils/routeDefs/responses.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { getCycleCountCheck } from "../controller/warehouse/cycleCountChecks/getCycleCountCheck.js";
import { apiHit } from "../../../globalUtils/apiHits.js";
const app = new OpenAPIHono();
@@ -30,7 +31,7 @@ app.openapi(
responses: responses(),
}),
async (c: any) => {
//apiHit(c, { endpoint: "api/sqlProd/close" });
apiHit(c, { endpoint: "/cyclecountcheck" });
const { data: body, error: be } = await tryCatch(c.req.json());
if (be) {

View File

@@ -3,6 +3,7 @@ import { responses } from "../../../globalUtils/routeDefs/responses.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { lanesToExcel } from "../controller/warehouse/cycleCountChecks/exportCycleCountData.js";
import { format } from "date-fns";
import { apiHit } from "../../../globalUtils/apiHits.js";
const app = new OpenAPIHono();
@@ -31,7 +32,7 @@ app.openapi(
responses: responses(),
}),
async (c: any) => {
//apiHit(c, { endpoint: "api/sqlProd/close" });
apiHit(c, { endpoint: "/getcyclecount" });
const defaultFilename = `cycleCount-${format(
new Date(Date.now()),
"M-d-yyyy"

View File

@@ -3,6 +3,7 @@ import { responses } from "../../../globalUtils/routeDefs/responses.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { getCycleCountCheck } from "../controller/warehouse/cycleCountChecks/getCycleCountCheck.js";
import { getPPOO } from "../controller/warehouse/ppoo/getPPOO.js";
import { apiHit } from "../../../globalUtils/apiHits.js";
const app = new OpenAPIHono();
@@ -31,7 +32,7 @@ app.openapi(
responses: responses(),
}),
async (c: any) => {
//apiHit(c, { endpoint: "api/sqlProd/close" });
apiHit(c, { endpoint: "/outbound" });
const body = await c.req.json();

View File

@@ -3,6 +3,7 @@ import { responses } from "../../../globalUtils/routeDefs/responses.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { getCycleCountCheck } from "../controller/warehouse/cycleCountChecks/getCycleCountCheck.js";
import { getPPOO } from "../controller/warehouse/ppoo/getPPOO.js";
import { apiHit } from "../../../globalUtils/apiHits.js";
const app = new OpenAPIHono();
@@ -31,7 +32,7 @@ app.openapi(
responses: responses(),
}),
async (c: any) => {
//apiHit(c, { endpoint: "api/sqlProd/close" });
apiHit(c, { endpoint: "/getppoo" });
const { data: ppoo, error } = await tryCatch(getPPOO());

View File

@@ -3,6 +3,7 @@ import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
import { apiHit } from "../../../globalUtils/apiHits.js";
import { verify } from "hono/jwt";
import { returnMaterial } from "../controller/materials/returnMaterial.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
const app = new OpenAPIHono();
@@ -36,7 +37,19 @@ app.openapi(
},
}),
async (c) => {
apiHit(c, { endpoint: "api/sqlProd/close" });
const { data, error } = await tryCatch(c.req.json());
if (error) {
return c.json(
{
success: false,
message: "Missing data please try again",
error,
},
400
);
}
apiHit(c, { endpoint: "/return", lastBody: data });
const authHeader = c.req.header("Authorization");
const token = authHeader?.split("Bearer ")[1] || "";
@@ -44,7 +57,7 @@ app.openapi(
const payload = await verify(token, process.env.JWT_SECRET!);
try {
//return apiReturn(c, true, access?.message, access?.data, 200);
const data = await c.req.json();
const consume = await returnMaterial(data, payload);
return c.json(
{ success: consume?.success, message: consume?.message },

View File

@@ -3,6 +3,8 @@ import { verify } from "hono/jwt";
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
import { createSiloAdjustment } from "../../controller/siloAdjustments/createSiloAdjustment.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
const app = new OpenAPIHono();
@@ -23,7 +25,19 @@ app.openapi(
responses: responses(),
}),
async (c) => {
//apiHit(c, { endpoint: "api/sqlProd/close" });
const { data, error } = await tryCatch(c.req.json());
if (error) {
return c.json(
{
success: false,
message: "Missing data please try again",
error,
},
400
);
}
apiHit(c, { endpoint: "/createsiloadjustment", lastBody: data });
const authHeader = c.req.header("Authorization");
const token = authHeader?.split("Bearer ")[1] || "";
@@ -31,7 +45,6 @@ app.openapi(
const payload = await verify(token, process.env.JWT_SECRET!);
try {
//return apiReturn(c, true, access?.message, access?.data, 200);
const data = await c.req.json();
const createSiloAdj = await createSiloAdjustment(
data,
payload.user

View File

@@ -4,6 +4,7 @@ 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({
@@ -26,6 +27,7 @@ app.openapi(
}),
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` });

View File

@@ -2,6 +2,7 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
import { getStockSiloData } from "../../controller/siloAdjustments/getCurrentStockSiloData.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";
const app = new OpenAPIHono();
@@ -21,7 +22,7 @@ app.openapi(
responses: responses(),
}),
async (c: any) => {
//apiHit(c, { endpoint: "api/sqlProd/close" });
apiHit(c, { endpoint: "/getstocksilo" });
try {
//return apiReturn(c, true, access?.message, access?.data, 200);

View File

@@ -4,6 +4,7 @@ import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
import { createSiloAdjustment } from "../../controller/siloAdjustments/createSiloAdjustment.js";
import { postSiloComment } from "../../controller/siloAdjustments/postComment.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";
const app = new OpenAPIHono();
@@ -42,7 +43,7 @@ app.openapi(
responses: responses(),
}),
async (c: any) => {
//apiHit(c, { endpoint: "api/sqlProd/close" });
apiHit(c, { endpoint: "/postcomment" });
const authHeader = c.req.header("Authorization");
const token = authHeader?.split("Bearer ")[1] || "";
const { adjId } = c.req.valid("param");

View File

@@ -2,6 +2,7 @@
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { responses } from "../../../globalUtils/routeDefs/responses.js";
import { getAllJobs } from "../utils/processNotifications.js";
import { apiHit } from "../../../globalUtils/apiHits.js";
const app = new OpenAPIHono({ strict: false });
@@ -15,6 +16,7 @@ app.openapi(
responses: responses(),
}),
async (c) => {
apiHit(c, { endpoint: "/activenotifications" });
const jobs = getAllJobs();
return c.json({
success: true,

View File

@@ -4,6 +4,7 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { responses } from "../../../globalUtils/routeDefs/responses.js";
import { getNotifications } from "../controller/getNotifications.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { apiHit } from "../../../globalUtils/apiHits.js";
const app = new OpenAPIHono({ strict: false });
@@ -18,7 +19,7 @@ app.openapi(
responses: responses(),
}),
async (c: any) => {
//apiHit(c, { endpoint: `api/logger/logs` });
apiHit(c, { endpoint: "/notifications" });
const { data, error } = await tryCatch(getNotifications());
if (error) {

View File

@@ -3,6 +3,7 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { responses } from "../../../globalUtils/routeDefs/responses.js";
import runTiImport from "../controller/notifications/tiIntergration.js";
import { apiHit } from "../../../globalUtils/apiHits.js";
const app = new OpenAPIHono({ strict: false });
@@ -16,6 +17,7 @@ app.openapi(
responses: responses(),
}),
async (c) => {
apiHit(c, { endpoint: "/tiTrigger" });
const tiImport = await runTiImport();
return c.json({
success: tiImport?.success,

View File

@@ -8,6 +8,7 @@ import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { notifications } from "../../../../database/schema/notifications.js";
import { db } from "../../../../database/dbclient.js";
import { eq } from "drizzle-orm";
import { apiHit } from "../../../globalUtils/apiHits.js";
const app = new OpenAPIHono({ strict: false });
@@ -24,7 +25,7 @@ app.openapi(
/**
* get the blocking notification stuff
*/
apiHit(c, { endpoint: "/blockingTrigger" });
const { data, error } = await tryCatch(
db
.select()

View File

@@ -4,6 +4,7 @@ import { responses } from "../../../globalUtils/routeDefs/responses.js";
import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
import { sendEmail } from "../controller/sendMail.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { apiHit } from "../../../globalUtils/apiHits.js";
const app = new OpenAPIHono({ strict: false });
@@ -41,6 +42,7 @@ app.openapi(
const { data: bodyData, error: bodyError } = await tryCatch(
c.req.json()
);
apiHit(c, { endpoint: "/sendmail", lastBody: bodyData });
if (bodyError) {
return c.json(
{

View File

@@ -30,10 +30,9 @@ app.openapi(
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();
apiHit(c, { endpoint: "/cycleCount", lastBody: body });
const authHeader = c.req.header("Authorization");
const token = authHeader?.split("Bearer ")[1] || "";

View File

@@ -16,7 +16,7 @@ app.openapi(
}),
async (c) => {
// make sure we have a vaid user being accessed thats really logged in
apiHit(c, { endpoint: "api/auth/register" });
apiHit(c, { endpoint: "/getInfo" });
try {
return c.json(
{ success: true, message: "Ocme Info", data: await getInfo() },

View File

@@ -5,110 +5,114 @@ 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: []}),
}),
},
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",
// },
},
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 });
}),
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: "/getshipmentpallets", lastBody: data });
console.log;
console.log;
if (!data.shipmentID) {
return c.json(
{
success: false,
message: "You are missing the shipment id please try again.",
data: [],
},
400
);
}
if (!data.shipmentID) {
return c.json(
{
success: false,
message:
"You are missing the shipment id please try again.",
data: [],
},
400
);
}
const shiptmentData = await getShipmentPallets(data.shipmentID);
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
);
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;

View File

@@ -6,109 +6,112 @@ 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: []}),
}),
},
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",
},
},
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
);
}),
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: "/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;

View File

@@ -85,7 +85,7 @@ app.openapi(
try {
const data = await c.req.json();
apiHit(c, {
endpoint: "api/ocme/postRunningNumber",
endpoint: "/postRunningNumber",
lastBody: data,
});
const postPallet: any = await postLabelData(data);

View File

@@ -6,101 +6,104 @@ 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: "/postSSCC",
request: {
body: {
content: {
"application/json": { schema: PostRunningNr },
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: []}),
}),
},
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",
// },
},
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
);
}),
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: "/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;

View File

@@ -16,7 +16,7 @@ app.openapi(
}),
async (c) => {
// make sure we have a vaid user being accessed thats really logged in
apiHit(c, { endpoint: "api/auth/register" });
apiHit(c, { endpoint: "/manualCameraTrigger" });
const manualTrigger: any = await triggerScanner();
console.log(manualTrigger);
return c.json({

View File

@@ -5,6 +5,7 @@ import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { labelingProcess } from "../../controller/labeling/labelProcess.js";
import { bookInLabel } from "../../controller/labeling/bookIn.js";
import { createSSCC } from "../../../../globalUtils/createSSCC.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";
const app = new OpenAPIHono({ strict: false });
@@ -21,6 +22,7 @@ app.openapi(
const { data: bodyData, error: bodyError } = await tryCatch(
c.req.json()
);
apiHit(c, { endpoint: "/bookin", lastBody: bodyData });
if (bodyError) {
return c.json({

View File

@@ -3,6 +3,7 @@ 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";
import { apiHit } from "../../../../globalUtils/apiHits.js";
const app = new OpenAPIHono({ strict: false });
@@ -19,6 +20,7 @@ app.openapi(
const { data: labelData, error: labelError } = await tryCatch(
getLabels(hours ?? "2")
);
apiHit(c, { endpoint: "/getLabels" });
if (labelError) {
return c.json({

View File

@@ -3,6 +3,7 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { labelingProcess } from "../../controller/labeling/labelProcess.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";
const app = new OpenAPIHono({ strict: false });
@@ -19,6 +20,7 @@ app.openapi(
const { data: bodyData, error: bodyError } = await tryCatch(
c.req.json()
);
apiHit(c, { endpoint: "/manualprintandfollow", lastBody: bodyData });
if (bodyError) {
return c.json({

View File

@@ -34,7 +34,7 @@ app.openapi(
}),
async (c) => {
const { data: body, error } = await tryCatch(c.req.json());
apiHit(c, { endpoint: "/manuallabellog", lastBody: body });
if (error) {
return c.json(
{

View File

@@ -3,6 +3,7 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { getLots } from "../../controller/lots/lots.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";
const app = new OpenAPIHono({ strict: false });
@@ -16,7 +17,7 @@ app.openapi(
}),
async (c: any) => {
const { data: lotData, error: lotError } = await tryCatch(getLots());
apiHit(c, { endpoint: "/getlots" });
if (lotError) {
return c.json({
success: false,

View File

@@ -4,6 +4,7 @@ import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { printerCycle } from "../../controller/printers/printerCycle.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";
const app = new OpenAPIHono({ strict: false });
@@ -22,6 +23,7 @@ app.openapi(
}),
async (c) => {
const { data, error } = await tryCatch(printerCycle());
apiHit(c, { endpoint: "/startsprintercycle" });
const dataError: any = error;
if (error) {
return c.json({

View File

@@ -4,6 +4,7 @@ import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { stopPrinterCycle } from "../../controller/printers/printerCycle.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";
const app = new OpenAPIHono({ strict: false });
@@ -22,6 +23,7 @@ app.openapi(
}),
async (c) => {
const { data, error } = await tryCatch(stopPrinterCycle());
apiHit(c, { endpoint: "/stopprintercycle" });
const dataError: any = error;
if (error) {
return c.json({

View File

@@ -3,6 +3,7 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { getPrinters } from "../../controller/printers/getPrinters.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";
const app = new OpenAPIHono({ strict: false });
const CreateLog = z.object({
@@ -32,6 +33,7 @@ app.openapi(
const { data: printData, error: printError } = await tryCatch(
getPrinters()
);
apiHit(c, { endpoint: "/getprinters" });
if (printError) {
return c.json({

View File

@@ -4,6 +4,7 @@ import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { printerCycle } from "../../controller/printers/printerCycle.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";
const app = new OpenAPIHono({ strict: false });
@@ -22,6 +23,7 @@ app.openapi(
}),
async (c) => {
const { data, error } = await tryCatch(printerCycle());
apiHit(c, { endpoint: "/startsprintercycle" });
const dataError: any = error;
if (error) {
return c.json({

View File

@@ -4,6 +4,7 @@ import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { stopPrinterCycle } from "../../controller/printers/printerCycle.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";
const app = new OpenAPIHono({ strict: false });
@@ -22,6 +23,7 @@ app.openapi(
}),
async (c) => {
const { data, error } = await tryCatch(stopPrinterCycle());
apiHit(c, { endpoint: "/stopprintercycle" });
const dataError: any = error;
if (error) {
return c.json({

View File

@@ -3,6 +3,7 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import { updatePrinters } from "../../controller/printers/updatePrinters.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";
const app = new OpenAPIHono({ strict: false });
const CreateLog = z.object({
@@ -32,6 +33,7 @@ app.openapi(
const { data: printData, error: printError } = await tryCatch(
updatePrinters()
);
apiHit(c, { endpoint: "/updateprinters" });
if (printError) {
return c.json({

View File

@@ -4,6 +4,7 @@ import { responses } from "../../../../../globalUtils/routeDefs/responses.js";
import { authMiddleware } from "../../../../auth/middleware/authMiddleware.js";
import { tryCatch } from "../../../../../globalUtils/tryCatch.js";
import { closeDyco } from "../../../controller/specialProcesses/dyco/plcConnection.js";
import { apiHit } from "../../../../../globalUtils/apiHits.js";
const app = new OpenAPIHono({ strict: false });
@@ -23,7 +24,7 @@ app.openapi(
}),
async (c) => {
//const body = await c.req.json();
//apiHit(c, {endpoint: `api/logger/logs/id`});
apiHit(c, { endpoint: `dycodisconnect` });
// const authHeader = c.req.header("Authorization");
// const token = authHeader?.split("Bearer ")[1] || "";

View File

@@ -4,6 +4,7 @@ import { responses } from "../../../../../globalUtils/routeDefs/responses.js";
import { authMiddleware } from "../../../../auth/middleware/authMiddleware.js";
import { tryCatch } from "../../../../../globalUtils/tryCatch.js";
import { dycoConnect } from "../../../controller/specialProcesses/dyco/plcConnection.js";
import { apiHit } from "../../../../../globalUtils/apiHits.js";
const app = new OpenAPIHono({ strict: false });
@@ -22,7 +23,7 @@ app.openapi(
}),
async (c) => {
//const body = await c.req.json();
//apiHit(c, {endpoint: `api/logger/logs/id`});
apiHit(c, { endpoint: `dycoconnect` });
// const authHeader = c.req.header("Authorization");
// const token = authHeader?.split("Bearer ")[1] || "";
@@ -37,6 +38,7 @@ app.openapi(
// }
const { data, error } = await tryCatch(dycoConnect());
const dataError: any = error;
if (error) {
return c.json({

View File

@@ -3,6 +3,7 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { responses } from "../../../globalUtils/routeDefs/responses.js";
import { getRequest } from "../controller/getRequests.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { apiHit } from "../../../globalUtils/apiHits.js";
const app = new OpenAPIHono({ strict: false });
@@ -16,7 +17,7 @@ app.openapi(
}),
async (c) => {
const { data, error } = await tryCatch(getRequest());
apiHit(c, { endpoint: "/getrequest" });
if (error) {
return c.json({
success: false,

View File

@@ -6,6 +6,7 @@ import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
import { addNewPallet } from "../controller/addNewPallet.js";
import { verify } from "hono/jwt";
import { apiHit } from "../../../globalUtils/apiHits.js";
const app = new OpenAPIHono({ strict: false });
const Body = z.object({
@@ -36,7 +37,7 @@ app.openapi(
const user: any = payload.user;
const { data: b, error: e } = await tryCatch(c.req.json());
apiHit(c, { endpoint: "/newrequest", lastBody: b });
if (e) {
return c.json({
success: false,

View File

@@ -1,15 +1,16 @@
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
import {addReader} from "../controller/addReader.js";
import {authMiddleware} from "../../auth/middleware/authMiddleware.js";
import {responses} from "../../../globalUtils/routeDefs/responses.js";
import type {User} from "../../../types/users.js";
import {verify} from "hono/jwt";
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
import { addReader } from "../controller/addReader.js";
import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
import { responses } from "../../../globalUtils/routeDefs/responses.js";
import type { User } from "../../../types/users.js";
import { verify } from "hono/jwt";
import { apiHit } from "../../../globalUtils/apiHits.js";
const app = new OpenAPIHono();
export const ReaderBody = z.object({
reader: z.string().openapi({example: "wrapper1"}),
readerIP: z.string().openapi({example: "192.168.1.52"}),
reader: z.string().openapi({ example: "wrapper1" }),
readerIP: z.string().openapi({ example: "192.168.1.52" }),
});
app.openapi(
@@ -21,14 +22,14 @@ app.openapi(
middleware: authMiddleware,
description: "Adding in a new reader to add to the network.",
request: {
body: {content: {"application/json": {schema: ReaderBody}}},
body: { content: { "application/json": { schema: ReaderBody } } },
},
responses: responses(),
}),
async (c) => {
const body = await c.req.json();
const authHeader = c.req.header("Authorization");
apiHit(c, { endpoint: "/addreader", lastBody: body });
const token = authHeader?.split("Bearer ")[1] || "";
let user: User;
@@ -36,14 +37,26 @@ app.openapi(
const payload = await verify(token, process.env.JWT_SECRET!);
user = payload.user as User;
} catch (error) {
return c.json({message: "Unauthorized"}, 401);
return c.json({ message: "Unauthorized" }, 401);
}
try {
const addingReader = await addReader(body, user);
return c.json({success: addingReader.success, message: addingReader.message}, 200);
return c.json(
{
success: addingReader.success,
message: addingReader.message,
},
200
);
} catch (error) {
return c.json({success: false, message: `${body.name} encountered an error while trying to be added`}, 400);
return c.json(
{
success: false,
message: `${body.name} encountered an error while trying to be added`,
},
400
);
}
}
);

View File

@@ -1,13 +1,14 @@
//http://usday1vms006:4000/api/v1/zebra/wrapper1
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
import {responses} from "../../../globalUtils/routeDefs/responses.js";
import {authMiddleware} from "../../auth/middleware/authMiddleware.js";
import {manualTag} from "../controller/tags/manualTag.js";
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
import { responses } from "../../../globalUtils/routeDefs/responses.js";
import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
import { manualTag } from "../controller/tags/manualTag.js";
import { apiHit } from "../../../globalUtils/apiHits.js";
const app = new OpenAPIHono();
const RequestBody = z.object({
tagNumber: z.string().openapi({example: "2541"}),
tagNumber: z.string().openapi({ example: "2541" }),
});
app.openapi(
@@ -18,20 +19,37 @@ app.openapi(
path: "/manualtag",
middleware: authMiddleware,
request: {
body: {content: {"application/json": {schema: RequestBody}}},
body: { content: { "application/json": { schema: RequestBody } } },
},
responses: responses(),
}),
async (c) => {
const body =
(await c.req.json()) ??
c.json({success: false, message: `Please check that you are sending over a json object`}, 400);
c.json(
{
success: false,
message: `Please check that you are sending over a json object`,
},
400
);
apiHit(c, { endpoint: "/manualtag" });
try {
const tag = await manualTag(body.tag, body.area);
return c.json({success: tag.success, message: tag.message, data: tag.data}, 200);
return c.json(
{ success: tag.success, message: tag.message, data: tag.data },
200
);
} catch (error) {
return c.json({success: true, message: `There was an error with entering a new tag`, error}, 400);
return c.json(
{
success: true,
message: `There was an error with entering a new tag`,
error,
},
400
);
}
}
);

View File

@@ -1,21 +1,22 @@
//http://usday1vms006:4000/api/v1/zebra/wrapper1
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
import {responses} from "../../../globalUtils/routeDefs/responses.js";
import {readTags} from "../controller/readTags.js";
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
import { responses } from "../../../globalUtils/routeDefs/responses.js";
import { readTags } from "../controller/readTags.js";
import { apiHit } from "../../../globalUtils/apiHits.js";
const app = new OpenAPIHono();
const ParamsSchema = z.object({
reader: z
.string()
.min(3)
.openapi({
param: {
name: "reader",
in: "path",
},
example: "1212121",
}),
.string()
.min(3)
.openapi({
param: {
name: "reader",
in: "path",
},
example: "1212121",
}),
});
app.openapi(
@@ -30,10 +31,16 @@ app.openapi(
responses: responses(),
}),
async (c) => {
const {reader} = c.req.valid("param");
const { reader } = c.req.valid("param");
const manualTrigger = await readTags(reader);
return c.json({success: true, message: `A Manaul trigger was done on ${reader}`}, 200);
apiHit(c, { endpoint: `/manualtrigger/${reader}` });
return c.json(
{
success: true,
message: `A Manaul trigger was done on ${reader}`,
},
200
);
}
);

View File

@@ -4,6 +4,7 @@ import { readTags } from "../controller/readTags.js";
import { createLog } from "../../logger/logger.js";
import { responses } from "../../../globalUtils/routeDefs/responses.js";
import { newHeartBeat } from "../controller/readerControl.js";
import { apiHit } from "../../../globalUtils/apiHits.js";
const app = new OpenAPIHono();
let lastGpiTimestamp = 0;
@@ -35,7 +36,7 @@ app.openapi(
async (c) => {
const { reader } = c.req.valid("param");
const body = await c.req.json();
apiHit(c, { endpoint: `/mgtevents/${reader}` });
if (body.type === "heartbeat") {
const heart = await newHeartBeat(reader);
return c.json(

View File

@@ -8,6 +8,7 @@ import { badRead, goodRead } from "../controller/readerControl.js";
import { createLog } from "../../logger/logger.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { stopRead } from "../controller/readTags.js";
import { apiHit } from "../../../globalUtils/apiHits.js";
const app = new OpenAPIHono();
@@ -40,7 +41,7 @@ app.openapi(
createLog("info", "rfid", "rfid", `${reader} is sending us data.`);
let tagdata: any = [];
const { data: body, error: bodyError } = await tryCatch(c.req.json());
apiHit(c, { endpoint: `/taginfo/${reader}`, lastBody: body });
if (bodyError) {
return c.json({ success: false, message: "missing data" }, 400);
}

View File

@@ -1,16 +1,17 @@
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
import {addReader} from "../controller/addReader.js";
import {authMiddleware} from "../../auth/middleware/authMiddleware.js";
import {responses} from "../../../globalUtils/routeDefs/responses.js";
import type {User} from "../../../types/users.js";
import {verify} from "hono/jwt";
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
import { addReader } from "../controller/addReader.js";
import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
import { responses } from "../../../globalUtils/routeDefs/responses.js";
import type { User } from "../../../types/users.js";
import { verify } from "hono/jwt";
import { apiHit } from "../../../globalUtils/apiHits.js";
const app = new OpenAPIHono();
export const ReaderBody = z.object({
reader: z.string().openapi({example: "wrapper1"}),
readerIP: z.string().openapi({example: "192.168.1.52"}),
active: z.boolean().optional().openapi({example: true}),
reader: z.string().openapi({ example: "wrapper1" }),
readerIP: z.string().openapi({ example: "192.168.1.52" }),
active: z.boolean().optional().openapi({ example: true }),
});
app.openapi(
@@ -22,14 +23,14 @@ app.openapi(
middleware: authMiddleware,
description: "Updates the reader data..",
request: {
body: {content: {"application/json": {schema: ReaderBody}}},
body: { content: { "application/json": { schema: ReaderBody } } },
},
responses: responses(),
}),
async (c) => {
const body = await c.req.json();
const authHeader = c.req.header("Authorization");
apiHit(c, { endpoint: `/updatereader`, lastBody: body });
const token = authHeader?.split("Bearer ")[1] || "";
let user: User;
@@ -37,14 +38,26 @@ app.openapi(
const payload = await verify(token, process.env.JWT_SECRET!);
user = payload.user as User;
} catch (error) {
return c.json({message: "Unauthorized"}, 401);
return c.json({ message: "Unauthorized" }, 401);
}
try {
const addingReader = await addReader(body, user);
return c.json({success: addingReader.success, message: addingReader.message}, 200);
return c.json(
{
success: addingReader.success,
message: addingReader.message,
},
200
);
} catch (error) {
return c.json({success: false, message: `${body.name} encountered an error while trying to be added`}, 400);
return c.json(
{
success: false,
message: `${body.name} encountered an error while trying to be added`,
},
400
);
}
}
);

View File

@@ -1,16 +1,23 @@
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
import type {User} from "../../../../types/users.js";
import {verify} from "hono/jwt";
import {authMiddleware} from "../../../auth/middleware/authMiddleware.js";
import {addModule} from "../../controller/module/addModule.js";
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
import type { User } from "../../../../types/users.js";
import { verify } from "hono/jwt";
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
import { addModule } from "../../controller/module/addModule.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";
// Define the response schema
const responseSchema = z.object({
message: z.string().optional(),
module_id: z.string().openapi({example: "6c922c6c-7de3-4ec4-acb0-f068abdc"}).optional(),
name: z.string().openapi({example: "Production"}).optional(),
active: z.boolean().openapi({example: true}).optional(),
roles: z.string().openapi({example: `["viewer","technician"]`}).optional(),
module_id: z
.string()
.openapi({ example: "6c922c6c-7de3-4ec4-acb0-f068abdc" })
.optional(),
name: z.string().openapi({ example: "Production" }).optional(),
active: z.boolean().openapi({ example: true }).optional(),
roles: z
.string()
.openapi({ example: `["viewer","technician"]` })
.optional(),
});
const app = new OpenAPIHono();
@@ -29,7 +36,7 @@ const app = new OpenAPIHono();
// });
const AddModule = z.object({
name: z.string().openapi({example: "production"}),
name: z.string().openapi({ example: "production" }),
});
app.openapi(
@@ -42,21 +49,26 @@ app.openapi(
request: {
body: {
content: {
"application/json": {schema: AddModule},
"application/json": { schema: AddModule },
},
},
},
responses: {
200: {
content: {
"application/json": {schema: responseSchema},
"application/json": { schema: responseSchema },
},
description: "Response message",
},
400: {
content: {
"application/json": {
schema: z.object({message: z.string().optional().openapi({example: "Internal Server error"})}),
schema: z.object({
message: z
.string()
.optional()
.openapi({ example: "Internal Server error" }),
}),
},
},
description: "Internal Server Error",
@@ -64,7 +76,12 @@ app.openapi(
401: {
content: {
"application/json": {
schema: z.object({message: z.string().optional().openapi({example: "Unauthenticated"})}),
schema: z.object({
message: z
.string()
.optional()
.openapi({ example: "Unauthenticated" }),
}),
},
},
description: "Unauthorized",
@@ -72,7 +89,12 @@ app.openapi(
500: {
content: {
"application/json": {
schema: z.object({message: z.string().optional().openapi({example: "Internal Server error"})}),
schema: z.object({
message: z
.string()
.optional()
.openapi({ example: "Internal Server error" }),
}),
},
},
description: "Internal Server Error",
@@ -92,16 +114,26 @@ app.openapi(
const payload = await verify(token, process.env.JWT_SECRET!);
user = payload.user as User;
} catch (error) {
return c.json({message: "Unauthorized"}, 401);
return c.json({ message: "Unauthorized" }, 401);
}
// now pass all the data over to update the user info
try {
const data = await c?.req.json();
apiHit(c, { endpoint: `/modules`, lastBody: data });
await addModule(data, user.user_id ?? "");
return c.json({success: true, message: "New setting was added"}, 200);
return c.json(
{ success: true, message: "New setting was added" },
200
);
} catch (error) {
return c.json({message: "Please make sure you are not missing your data.", error}, 400);
return c.json(
{
message: "Please make sure you are not missing your data.",
error,
},
400
);
}
}
);

View File

@@ -2,6 +2,7 @@ import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
import { modules } from "../../../../../database/schema/modules.js";
import { db } from "../../../../../database/dbclient.js";
import { desc } from "drizzle-orm";
import { apiHit } from "../../../../globalUtils/apiHits.js";
// Define the request body schema
const requestSchema = z.object({
@@ -45,6 +46,7 @@ app.openapi(
}),
async (c) => {
//console.log("system modules");
apiHit(c, { endpoint: `/getmodules`, action: "just modules" });
let module: any = [];
try {
module = await db.select().from(modules).orderBy(modules.name); // .where(eq(modules.active, true));

View File

@@ -2,6 +2,7 @@ import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
import { modules } from "../../../../../database/schema/modules.js";
import { db } from "../../../../../database/dbclient.js";
import { subModules } from "../../../../../database/schema/subModules.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";
// Define the request body schema
const requestSchema = z.object({
@@ -45,6 +46,7 @@ app.openapi(
}),
async (c) => {
//console.log("system modules");
apiHit(c, { endpoint: `/submodules` });
let module: any = [];
try {
module = await db

View File

@@ -1,31 +1,38 @@
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
import type {User} from "../../../../types/users.js";
import {verify} from "hono/jwt";
import {updateModule} from "../../controller/module/updateModule.js";
import {authMiddleware} from "../../../auth/middleware/authMiddleware.js";
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
import type { User } from "../../../../types/users.js";
import { verify } from "hono/jwt";
import { updateModule } from "../../controller/module/updateModule.js";
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";
// Define the response schema
const responseSchema = z.object({
message: z.string().optional(),
module_id: z.string().openapi({example: "6c922c6c-7de3-4ec4-acb0-f068abdc"}).optional(),
name: z.string().openapi({example: "Production"}).optional(),
active: z.boolean().openapi({example: true}).optional(),
roles: z.string().openapi({example: `["viewer","technician"]`}).optional(),
module_id: z
.string()
.openapi({ example: "6c922c6c-7de3-4ec4-acb0-f068abdc" })
.optional(),
name: z.string().openapi({ example: "Production" }).optional(),
active: z.boolean().openapi({ example: true }).optional(),
roles: z
.string()
.openapi({ example: `["viewer","technician"]` })
.optional(),
});
const app = new OpenAPIHono();
const ParamsSchema = z.object({
id: z
.string()
.min(3)
.openapi({
param: {
name: "id",
in: "path",
},
example: "1212121",
}),
.string()
.min(3)
.openapi({
param: {
name: "id",
in: "path",
},
example: "1212121",
}),
});
app.openapi(
@@ -41,14 +48,19 @@ app.openapi(
responses: {
200: {
content: {
"application/json": {schema: responseSchema},
"application/json": { schema: responseSchema },
},
description: "Response message",
},
400: {
content: {
"application/json": {
schema: z.object({message: z.string().optional().openapi({example: "Internal Server error"})}),
schema: z.object({
message: z
.string()
.optional()
.openapi({ example: "Internal Server error" }),
}),
},
},
description: "Internal Server Error",
@@ -56,7 +68,12 @@ app.openapi(
401: {
content: {
"application/json": {
schema: z.object({message: z.string().optional().openapi({example: "Unauthenticated"})}),
schema: z.object({
message: z
.string()
.optional()
.openapi({ example: "Unauthenticated" }),
}),
},
},
description: "Unauthorized",
@@ -64,7 +81,12 @@ app.openapi(
500: {
content: {
"application/json": {
schema: z.object({message: z.string().optional().openapi({example: "Internal Server error"})}),
schema: z.object({
message: z
.string()
.optional()
.openapi({ example: "Internal Server error" }),
}),
},
},
description: "Internal Server Error",
@@ -72,7 +94,7 @@ app.openapi(
},
}),
async (c) => {
const {id} = c.req.valid("param");
const { id } = c.req.valid("param");
// make sure we have a vaid user being accessed thats really logged in
const authHeader = c.req.header("Authorization");
@@ -84,16 +106,30 @@ app.openapi(
const payload = await verify(token, process.env.JWT_SECRET!);
user = payload.user as User;
} catch (error) {
return c.json({message: "Unauthorized"}, 401);
return c.json({ message: "Unauthorized" }, 401);
}
// now pass all the data over to update the user info
try {
const data = await c?.req.json();
apiHit(c, {
endpoint: `/modules/${id}`,
action: "just update modules",
lastBody: data,
});
await updateModule(data, id ?? "");
return c.json({success: true, message: "New setting was added"}, 200);
return c.json(
{ success: true, message: "New setting was added" },
200
);
} catch (error) {
return c.json({message: "Please make sure you are not missing your data.", error}, 400);
return c.json(
{
message: "Please make sure you are not missing your data.",
error,
},
400
);
}
return c.json({

View File

@@ -4,6 +4,7 @@ import { verify } from "hono/jwt";
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
import { updateSubModule } from "../../controller/module/updateSubModule.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";
// Define the response schema
const responseSchema = z.object({
@@ -112,6 +113,11 @@ app.openapi(
// now pass all the data over to update the user info
try {
const data = await c?.req.json();
apiHit(c, {
endpoint: `/submodules/${id}`,
action: "just updates submodules",
lastBody: data,
});
await updateSubModule(data, id ?? "");
return c.json({ success: true, message: "Module Updated" }, 200);
} catch (error) {

View File

@@ -1,8 +1,9 @@
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
import {db} from "../../../../../database/dbclient.js";
import {authMiddleware} from "../../../auth/middleware/authMiddleware.js";
import {serverData} from "../../../../../database/schema/serverData.js";
import {eq} from "drizzle-orm";
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
import { db } from "../../../../../database/dbclient.js";
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
import { serverData } from "../../../../../database/schema/serverData.js";
import { eq } from "drizzle-orm";
import { apiHit } from "../../../../globalUtils/apiHits.js";
// Define the request body schema
const requestSchema = z.object({
@@ -15,10 +16,16 @@ const requestSchema = z.object({
// Define the response schema
const responseSchema = z.object({
message: z.string().optional(),
module_id: z.string().openapi({example: "6c922c6c-7de3-4ec4-acb0-f068abdc"}).optional(),
name: z.string().openapi({example: "Production"}).optional(),
active: z.boolean().openapi({example: true}).optional(),
roles: z.string().openapi({example: `["viewer","technician"]`}).optional(),
module_id: z
.string()
.openapi({ example: "6c922c6c-7de3-4ec4-acb0-f068abdc" })
.optional(),
name: z.string().openapi({ example: "Production" }).optional(),
active: z.boolean().openapi({ example: true }).optional(),
roles: z
.string()
.openapi({ example: `["viewer","technician"]` })
.optional(),
});
const app = new OpenAPIHono();
@@ -33,7 +40,7 @@ app.openapi(
responses: {
200: {
content: {
"application/json": {schema: responseSchema},
"application/json": { schema: responseSchema },
},
description: "Response message",
},
@@ -41,16 +48,22 @@ app.openapi(
}),
async (c) => {
//console.log("system modules");
apiHit(c, { endpoint: `/servers` });
let servers: any = [];
try {
servers = await db.select().from(serverData).where(eq(serverData.active, true));
servers = await db
.select()
.from(serverData)
.where(eq(serverData.active, true));
} catch (error) {
console.log(error);
servers = [];
}
// sort the servers by there name
servers = servers.sort((a: any, b: any) => a.sName.localeCompare(b.sName));
servers = servers.sort((a: any, b: any) =>
a.sName.localeCompare(b.sName)
);
// Return response with the received data

View File

@@ -4,6 +4,7 @@ import { responses } from "../../../../globalUtils/routeDefs/responses.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
import hasCorrectRole from "../../../auth/middleware/roleCheck.js";
import { serviceControl } from "../../controller/server/serviceControl.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";
// Define the request body schema
const requestSchema = z.object({
@@ -33,7 +34,7 @@ app.openapi(
}),
async (c) => {
const { data, error } = await tryCatch(c.req.json());
//apiHit(c, { endpoint: `/serviceprocess`, lastBody: data });
if (error) {
return c.json({
success: false,

View File

@@ -1,19 +1,22 @@
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
import {addSetting} from "../../controller/settings/addSetting.js";
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { addSetting } from "../../controller/settings/addSetting.js";
import {verify} from "hono/jwt";
import type {User} from "../../../../types/users.js";
import {authMiddleware} from "../../../auth/middleware/authMiddleware.js";
import {responses} from "../../../../globalUtils/routeDefs/responses.js";
import { verify } from "hono/jwt";
import type { User } from "../../../../types/users.js";
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";
const app = new OpenAPIHono();
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(
@@ -26,7 +29,7 @@ app.openapi(
request: {
body: {
content: {
"application/json": {schema: AddSetting},
"application/json": { schema: AddSetting },
},
},
},
@@ -43,16 +46,26 @@ app.openapi(
const payload = await verify(token, process.env.JWT_SECRET!);
user = payload.user as User;
} catch (error) {
return c.json({message: "Unauthorized"}, 401);
return c.json({ message: "Unauthorized" }, 401);
}
// now pass all the data over to update the user info
try {
const data = await c?.req.json();
apiHit(c, { endpoint: `/addsettings`, lastBody: data });
await addSetting(data, user.user_id ?? "");
return c.json({success: true, message: "New setting was added"}, 200);
return c.json(
{ success: true, message: "New setting was added" },
200
);
} catch (error) {
return c.json({message: "Please make sure you are not missing your data.", error}, 400);
return c.json(
{
message: "Please make sure you are not missing your data.",
error,
},
400
);
}
}
);

View File

@@ -1,8 +1,9 @@
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import type {User} from "../../../../types/users.js";
import {verify} from "hono/jwt";
import {getSettings} from "../../controller/settings/getSettings.js";
import type { User } from "../../../../types/users.js";
import { verify } from "hono/jwt";
import { getSettings } from "../../controller/settings/getSettings.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";
const app = new OpenAPIHono();
@@ -17,8 +18,8 @@ app.openapi(
content: {
"application/json": {
schema: z.object({
success: z.boolean().openapi({example: true}),
message: z.string().openapi({example: "Starter"}),
success: z.boolean().openapi({ example: true }),
message: z.string().openapi({ example: "Starter" }),
}),
},
},
@@ -27,7 +28,12 @@ app.openapi(
400: {
content: {
"application/json": {
schema: z.object({message: z.string().optional().openapi({example: "Internal Server error"})}),
schema: z.object({
message: z
.string()
.optional()
.openapi({ example: "Internal Server error" }),
}),
},
},
description: "Internal Server Error",
@@ -35,7 +41,12 @@ app.openapi(
401: {
content: {
"application/json": {
schema: z.object({message: z.string().optional().openapi({example: "Unauthenticated"})}),
schema: z.object({
message: z
.string()
.optional()
.openapi({ example: "Unauthenticated" }),
}),
},
},
description: "Unauthorized",
@@ -43,7 +54,12 @@ app.openapi(
500: {
content: {
"application/json": {
schema: z.object({message: z.string().optional().openapi({example: "Internal Server error"})}),
schema: z.object({
message: z
.string()
.optional()
.openapi({ example: "Internal Server error" }),
}),
},
},
description: "Internal Server Error",
@@ -52,13 +68,19 @@ app.openapi(
}),
async (c) => {
// make sure we have a vaid user being accessed thats really logged in
apiHit(c, { endpoint: `/settings` });
// now pass all the data over to update the user info
try {
const data = await getSettings();
return c.json({success: true, message: "All Current Settings", data}, 200);
return c.json(
{ success: true, message: "All Current Settings", data },
200
);
} catch (error) {
return c.json({message: "There was an error getting the settings.", error}, 400);
return c.json(
{ message: "There was an error getting the settings.", error },
400
);
}
}
);

View File

@@ -1,13 +1,14 @@
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
import type {User} from "../../../../types/users.js";
import {verify} from "hono/jwt";
import {updateSetting} from "../../controller/settings/updateSetting.js";
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import type { User } from "../../../../types/users.js";
import { verify } from "hono/jwt";
import { updateSetting } from "../../controller/settings/updateSetting.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";
const app = new OpenAPIHono();
const UpdateSetting = z.object({
name: z.string().openapi({example: "server"}),
value: z.string().openapi({example: "localhost"}),
name: z.string().openapi({ example: "server" }),
value: z.string().openapi({ example: "localhost" }),
});
app.openapi(
@@ -19,7 +20,7 @@ app.openapi(
request: {
body: {
content: {
"application/json": {schema: UpdateSetting},
"application/json": { schema: UpdateSetting },
},
},
},
@@ -28,8 +29,8 @@ app.openapi(
content: {
"application/json": {
schema: z.object({
success: z.boolean().openapi({example: true}),
message: z.string().openapi({example: "Starter"}),
success: z.boolean().openapi({ example: true }),
message: z.string().openapi({ example: "Starter" }),
}),
},
},
@@ -38,7 +39,12 @@ app.openapi(
400: {
content: {
"application/json": {
schema: z.object({message: z.string().optional().openapi({example: "Internal Server error"})}),
schema: z.object({
message: z
.string()
.optional()
.openapi({ example: "Internal Server error" }),
}),
},
},
description: "Internal Server Error",
@@ -46,7 +52,12 @@ app.openapi(
401: {
content: {
"application/json": {
schema: z.object({message: z.string().optional().openapi({example: "Unauthenticated"})}),
schema: z.object({
message: z
.string()
.optional()
.openapi({ example: "Unauthenticated" }),
}),
},
},
description: "Unauthorized",
@@ -54,7 +65,12 @@ app.openapi(
500: {
content: {
"application/json": {
schema: z.object({message: z.string().optional().openapi({example: "Internal Server error"})}),
schema: z.object({
message: z
.string()
.optional()
.openapi({ example: "Internal Server error" }),
}),
},
},
description: "Internal Server Error",
@@ -66,11 +82,17 @@ app.openapi(
const authHeader = c.req.header("Authorization");
if (authHeader?.includes("Basic")) {
return c.json({message: "You are a Basic user! Please login to get a token"}, 401);
return c.json(
{
message:
"You are a Basic user! Please login to get a token",
},
401
);
}
if (!authHeader) {
return c.json({message: "Unauthorized"}, 401);
return c.json({ message: "Unauthorized" }, 401);
}
const token = authHeader?.split("Bearer ")[1] || "";
@@ -80,16 +102,27 @@ app.openapi(
const payload = await verify(token, process.env.JWT_SECRET!);
user = payload.user as User;
} catch (error) {
return c.json({message: "Unauthorized"}, 401);
return c.json({ message: "Unauthorized" }, 401);
}
// now pass all the data over to update the user info
try {
const data = await c?.req.json();
apiHit(c, { endpoint: `/updatesettings`, lastBody: data });
await updateSetting(data, user.user_id ?? "");
return c.json({success: true, message: "The Setting was just updated", data}, 200);
return c.json(
{
success: true,
message: "The Setting was just updated",
data,
},
200
);
} catch (error) {
return c.json({message: "There was an error updating the settings.", error}, 400);
return c.json(
{ message: "There was an error updating the settings.", error },
400
);
}
}
);

View File

@@ -4,6 +4,7 @@ import {
processAllServers,
updateServer,
} from "../../../../scripts/updateServers.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";
// Define the request body schema
const requestSchema = z.object({
@@ -80,7 +81,7 @@ app.openapi(
async (c) => {
const { server } = c.req.valid("param");
const body = await c.req.json();
apiHit(c, { endpoint: `/update/${server}`, lastBody: body });
// fire off the update we wont make this way
if (body.all) {
const update = await processAllServers(body.devDir);