feat(apihits): so i can see if what end points are being used and when and how often
This commit is contained in:
11
database/migrations/0053_short_colleen_wing.sql
Normal file
11
database/migrations/0053_short_colleen_wing.sql
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
CREATE TABLE "apiHits" (
|
||||||
|
"ip" text,
|
||||||
|
"endpoint" text,
|
||||||
|
"action" text,
|
||||||
|
"lastBody" text,
|
||||||
|
"stats" text,
|
||||||
|
"add_date" timestamp DEFAULT now(),
|
||||||
|
"upd_date" timestamp DEFAULT now()
|
||||||
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE UNIQUE INDEX "endpoint" ON "apiHits" USING btree ("endpoint","ip");
|
||||||
1
database/migrations/0054_careless_ultron.sql
Normal file
1
database/migrations/0054_careless_ultron.sql
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE "apiHits" ADD COLUMN "apiHit_id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL;
|
||||||
1
database/migrations/0055_sudden_frank_castle.sql
Normal file
1
database/migrations/0055_sudden_frank_castle.sql
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE "apiHits" ALTER COLUMN "stats" SET DATA TYPE integer;
|
||||||
1
database/migrations/0056_breezy_inertia.sql
Normal file
1
database/migrations/0056_breezy_inertia.sql
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE "apiHits" DROP COLUMN "stats";
|
||||||
1
database/migrations/0057_orange_lady_deathstrike.sql
Normal file
1
database/migrations/0057_orange_lady_deathstrike.sql
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE "apiHits" ADD COLUMN "stats" integer;
|
||||||
1
database/migrations/0058_cultured_argent.sql
Normal file
1
database/migrations/0058_cultured_argent.sql
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE "apiHits" ALTER COLUMN "stats" SET DEFAULT 1;
|
||||||
1
database/migrations/0059_calm_energizer.sql
Normal file
1
database/migrations/0059_calm_energizer.sql
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE "apiHits" DROP COLUMN "lastBody";
|
||||||
1
database/migrations/0060_daffy_overlord.sql
Normal file
1
database/migrations/0060_daffy_overlord.sql
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE "apiHits" ADD COLUMN "lastBody" jsonb;
|
||||||
1844
database/migrations/meta/0053_snapshot.json
Normal file
1844
database/migrations/meta/0053_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
1851
database/migrations/meta/0054_snapshot.json
Normal file
1851
database/migrations/meta/0054_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
1851
database/migrations/meta/0055_snapshot.json
Normal file
1851
database/migrations/meta/0055_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
1845
database/migrations/meta/0056_snapshot.json
Normal file
1845
database/migrations/meta/0056_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
1851
database/migrations/meta/0057_snapshot.json
Normal file
1851
database/migrations/meta/0057_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
1852
database/migrations/meta/0058_snapshot.json
Normal file
1852
database/migrations/meta/0058_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
1846
database/migrations/meta/0059_snapshot.json
Normal file
1846
database/migrations/meta/0059_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
1852
database/migrations/meta/0060_snapshot.json
Normal file
1852
database/migrations/meta/0060_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -372,6 +372,62 @@
|
|||||||
"when": 1744685129838,
|
"when": 1744685129838,
|
||||||
"tag": "0052_dark_human_torch",
|
"tag": "0052_dark_human_torch",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 53,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1747355241210,
|
||||||
|
"tag": "0053_short_colleen_wing",
|
||||||
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 54,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1747355689811,
|
||||||
|
"tag": "0054_careless_ultron",
|
||||||
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 55,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1747355837326,
|
||||||
|
"tag": "0055_sudden_frank_castle",
|
||||||
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 56,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1747355877490,
|
||||||
|
"tag": "0056_breezy_inertia",
|
||||||
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 57,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1747355892746,
|
||||||
|
"tag": "0057_orange_lady_deathstrike",
|
||||||
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 58,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1747356938396,
|
||||||
|
"tag": "0058_cultured_argent",
|
||||||
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 59,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1747357471279,
|
||||||
|
"tag": "0059_calm_energizer",
|
||||||
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 60,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1747357513268,
|
||||||
|
"tag": "0060_daffy_overlord",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -1,21 +1,30 @@
|
|||||||
import {pgTable, text, timestamp} from "drizzle-orm/pg-core";
|
import {
|
||||||
import {createSelectSchema} from "drizzle-zod";
|
integer,
|
||||||
|
jsonb,
|
||||||
|
pgTable,
|
||||||
|
text,
|
||||||
|
timestamp,
|
||||||
|
uniqueIndex,
|
||||||
|
uuid,
|
||||||
|
} from "drizzle-orm/pg-core";
|
||||||
|
import { createSelectSchema } from "drizzle-zod";
|
||||||
|
|
||||||
export const apiHits = pgTable(
|
export const apiHits = pgTable(
|
||||||
"apiHits",
|
"apiHits",
|
||||||
{
|
{
|
||||||
|
apiHit_id: uuid("apiHit_id").defaultRandom().primaryKey(),
|
||||||
ip: text("ip"),
|
ip: text("ip"),
|
||||||
endpoint: text("endpoint"),
|
endpoint: text("endpoint"),
|
||||||
action: text("action"),
|
action: text("action"),
|
||||||
lastBody: text("lastBody"),
|
lastBody: jsonb("lastBody"),
|
||||||
stats: text("stats"),
|
stats: integer("stats").default(1),
|
||||||
add_date: timestamp().defaultNow(),
|
add_date: timestamp().defaultNow(),
|
||||||
upd_date: timestamp().defaultNow(),
|
upd_date: timestamp().defaultNow(),
|
||||||
}
|
},
|
||||||
// (table) => [
|
(table) => [
|
||||||
// // uniqueIndex('emailUniqueIndex').on(sql`lower(${table.email})`),
|
// uniqueIndex('emailUniqueIndex').on(sql`lower(${table.email})`),
|
||||||
// uniqueIndex("role_name").on(table.name),
|
uniqueIndex("endpoint").on(table.endpoint, table.ip),
|
||||||
// ]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
// Schema for inserting a user - can be used to validate API requests
|
// Schema for inserting a user - can be used to validate API requests
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
import type {Context} from "hono";
|
import type { Context } from "hono";
|
||||||
import {z, ZodError} from "zod";
|
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
|
// Define the request body schema
|
||||||
const requestSchema = z.object({
|
const requestSchema = z.object({
|
||||||
ip: z.string().optional(),
|
ip: z.string().optional(),
|
||||||
endpoint: z.string(),
|
endpoint: z.string(),
|
||||||
action: z.string().optional(),
|
action: z.string().optional(),
|
||||||
lastBody: z.string().optional(),
|
lastBody: z.array(z.object({})).or(z.object({})).optional(),
|
||||||
stats: z.string().optional(),
|
stats: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -15,8 +20,9 @@ type ApiHitData = z.infer<typeof requestSchema>;
|
|||||||
export const apiHit = async (
|
export const apiHit = async (
|
||||||
c: Context,
|
c: Context,
|
||||||
data: ApiHitData
|
data: ApiHitData
|
||||||
): Promise<{success: boolean; data?: ApiHitData; errors?: any[]}> => {
|
): Promise<{ success: boolean; data?: ApiHitData; errors?: any[] }> => {
|
||||||
// console.log(data);
|
const info = getConnInfo(c);
|
||||||
|
// console.log(`Your remote address is ${info.remote.address}`);
|
||||||
try {
|
try {
|
||||||
// Extract IP from request headers or connection info
|
// Extract IP from request headers or connection info
|
||||||
const forwarded = c.req.header("host");
|
const forwarded = c.req.header("host");
|
||||||
@@ -24,24 +30,45 @@ export const apiHit = async (
|
|||||||
//console.log(forwarded);
|
//console.log(forwarded);
|
||||||
// Validate the data
|
// Validate the data
|
||||||
const checkData = {
|
const checkData = {
|
||||||
ip: forwarded!,
|
ip: info.remote.address!,
|
||||||
endpoint: data?.endpoint,
|
endpoint: data?.endpoint,
|
||||||
lastBody: data?.lastBody,
|
lastBody: data?.lastBody,
|
||||||
action: data?.action,
|
action: data?.action,
|
||||||
stats: data?.stats,
|
//stats: data?.stats,
|
||||||
};
|
};
|
||||||
const validatedData = requestSchema.parse(checkData);
|
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
|
// Proceed with the validated data
|
||||||
return {success: true, data: validatedData};
|
return { success: true, data: validatedData };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Explicitly check if the error is an instance of ZodError
|
// Explicitly check if the error is an instance of ZodError
|
||||||
if (error instanceof ZodError) {
|
if (error instanceof ZodError) {
|
||||||
// console.log({success: false, errors: error.errors});
|
console.log({ success: false, errors: error.errors });
|
||||||
return {success: false, errors: error.errors};
|
return { success: false, errors: error.errors };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Catch other unexpected errors
|
// Catch other unexpected errors
|
||||||
return {success: false, errors: [{message: "An unknown error occurred"}]};
|
return {
|
||||||
|
success: false,
|
||||||
|
errors: [{ message: "An unknown error occurred" }],
|
||||||
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
|||||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||||
import { getINV } from "../controller/getinventory.js";
|
import { getINV } from "../controller/getinventory.js";
|
||||||
import { getFakeEDI } from "../controller/fakeEDIUpdate.js";
|
import { getFakeEDI } from "../controller/fakeEDIUpdate.js";
|
||||||
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono({ strict: false });
|
const app = new OpenAPIHono({ strict: false });
|
||||||
const Body = z.object({
|
const Body = z.object({
|
||||||
@@ -27,7 +28,7 @@ app.openapi(
|
|||||||
const address: string = c.req.query("address") ?? "";
|
const address: string = c.req.query("address") ?? "";
|
||||||
|
|
||||||
// make sure we have a vaid user being accessed thats really logged in
|
// 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(
|
const { data, error } = await tryCatch(
|
||||||
getFakeEDI(address.toString() ?? "")
|
getFakeEDI(address.toString() ?? "")
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ app.openapi(
|
|||||||
async (c) => {
|
async (c) => {
|
||||||
//const body = await c.req.json();
|
//const body = await c.req.json();
|
||||||
// make sure we have a vaid user being accessed thats really logged in
|
// 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 {
|
try {
|
||||||
return c.json(
|
return c.json(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||||
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono({ strict: false });
|
const app = new OpenAPIHono({ strict: false });
|
||||||
const current: any = [
|
const current: any = [
|
||||||
@@ -108,7 +109,7 @@ app.openapi(
|
|||||||
async (c) => {
|
async (c) => {
|
||||||
//const body = await c.req.json();
|
//const body = await c.req.json();
|
||||||
// make sure we have a vaid user being accessed thats really logged in
|
// 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({
|
return c.json({
|
||||||
success: true,
|
success: true,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
|||||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||||
import { getINV } from "../controller/getinventory.js";
|
import { getINV } from "../controller/getinventory.js";
|
||||||
import { getCurrentCustomerInv } from "../controller/getCustomerInventory.js";
|
import { getCurrentCustomerInv } from "../controller/getCustomerInventory.js";
|
||||||
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono({ strict: false });
|
const app = new OpenAPIHono({ strict: false });
|
||||||
const Body = z.object({
|
const Body = z.object({
|
||||||
@@ -27,7 +28,7 @@ app.openapi(
|
|||||||
const customer: string = c.req.query("customer") ?? "";
|
const customer: string = c.req.query("customer") ?? "";
|
||||||
|
|
||||||
// make sure we have a vaid user being accessed thats really logged in
|
// 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(
|
const { data, error } = await tryCatch(
|
||||||
getCurrentCustomerInv(customer ? customer : null)
|
getCurrentCustomerInv(customer ? customer : null)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
|||||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||||
import { getDeliveryByDateRange } from "../controller/getDeliveryByDateRange.js";
|
import { getDeliveryByDateRange } from "../controller/getDeliveryByDateRange.js";
|
||||||
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono({ strict: false });
|
const app = new OpenAPIHono({ strict: false });
|
||||||
const Body = z.object({
|
const Body = z.object({
|
||||||
@@ -26,7 +27,7 @@ app.openapi(
|
|||||||
const delivery: any = c.req.queries();
|
const delivery: any = c.req.queries();
|
||||||
|
|
||||||
// make sure we have a vaid user being accessed thats really logged in
|
// 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(
|
const { data, error } = await tryCatch(
|
||||||
getDeliveryByDateRange(delivery ? delivery : null)
|
getDeliveryByDateRange(delivery ? delivery : null)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
|||||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||||
import { getINV } from "../controller/getinventory.js";
|
import { getINV } from "../controller/getinventory.js";
|
||||||
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono({ strict: false });
|
const app = new OpenAPIHono({ strict: false });
|
||||||
const Body = z.object({
|
const Body = z.object({
|
||||||
@@ -27,7 +28,7 @@ app.openapi(
|
|||||||
c.req.query("includeRunnningNumbers") ?? "";
|
c.req.query("includeRunnningNumbers") ?? "";
|
||||||
|
|
||||||
// make sure we have a vaid user being accessed thats really logged in
|
// 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(
|
const { data, error } = await tryCatch(
|
||||||
getINV(includeRunnningNumbers?.length > 0 ? true : false)
|
getINV(includeRunnningNumbers?.length > 0 ? true : false)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
|||||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||||
import { getOpenOrders } from "../controller/getOpenOrders.js";
|
import { getOpenOrders } from "../controller/getOpenOrders.js";
|
||||||
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono({ strict: false });
|
const app = new OpenAPIHono({ strict: false });
|
||||||
// const Body = z.object({
|
// const Body = z.object({
|
||||||
@@ -26,7 +27,7 @@ app.openapi(
|
|||||||
const customer: any = c.req.queries();
|
const customer: any = c.req.queries();
|
||||||
|
|
||||||
// make sure we have a vaid user being accessed thats really logged in
|
// 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(
|
const { data, error } = await tryCatch(
|
||||||
getOpenOrders(customer ? customer : null)
|
getOpenOrders(customer ? customer : null)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ app.openapi(
|
|||||||
async (c) => {
|
async (c) => {
|
||||||
//const body = await c.req.json();
|
//const body = await c.req.json();
|
||||||
// make sure we have a vaid user being accessed thats really logged in
|
// 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 {
|
try {
|
||||||
return c.json({ success: true, message: "", data: [] }, 200);
|
return c.json({ success: true, message: "", data: [] }, 200);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ app.openapi(
|
|||||||
async (c) => {
|
async (c) => {
|
||||||
//const body = await c.req.json();
|
//const body = await c.req.json();
|
||||||
// make sure we have a vaid user being accessed thats really logged in
|
// 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 {
|
try {
|
||||||
return c.json({ success: true, message: "", data: [] }, 200);
|
return c.json({ success: true, message: "", data: [] }, 200);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { apiHit } from "../../../globalUtils/apiHits.js";
|
|||||||
|
|
||||||
import { verify } from "hono/jwt";
|
import { verify } from "hono/jwt";
|
||||||
import { consumeMaterial } from "../controller/materials/consumeMaterial.js";
|
import { consumeMaterial } from "../controller/materials/consumeMaterial.js";
|
||||||
|
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
@@ -37,7 +38,19 @@ app.openapi(
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
async (c) => {
|
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 authHeader = c.req.header("Authorization");
|
||||||
const token = authHeader?.split("Bearer ")[1] || "";
|
const token = authHeader?.split("Bearer ")[1] || "";
|
||||||
|
|
||||||
@@ -45,7 +58,7 @@ app.openapi(
|
|||||||
const payload = await verify(token, process.env.JWT_SECRET!);
|
const payload = await verify(token, process.env.JWT_SECRET!);
|
||||||
try {
|
try {
|
||||||
//return apiReturn(c, true, access?.message, access?.data, 200);
|
//return apiReturn(c, true, access?.message, access?.data, 200);
|
||||||
const data = await c.req.json();
|
|
||||||
const consume = await consumeMaterial(data, payload);
|
const consume = await consumeMaterial(data, payload);
|
||||||
return c.json(
|
return c.json(
|
||||||
{ success: consume?.success, message: consume?.message },
|
{ success: consume?.success, message: consume?.message },
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
|||||||
import { ordersIn } from "../../controller/dm/ordersIn/ordersIn.js";
|
import { ordersIn } from "../../controller/dm/ordersIn/ordersIn.js";
|
||||||
import { verify } from "hono/jwt";
|
import { verify } from "hono/jwt";
|
||||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
@@ -31,7 +32,7 @@ app.openapi(
|
|||||||
responses: responses(),
|
responses: responses(),
|
||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
//apiHit(c, { endpoint: "api/sqlProd/close" });
|
apiHit(c, { endpoint: "/postbulkorders" });
|
||||||
const body = await c.req.parseBody();
|
const body = await c.req.parseBody();
|
||||||
const authHeader = c.req.header("Authorization");
|
const authHeader = c.req.header("Authorization");
|
||||||
const token = authHeader?.split("Bearer ")[1] || "";
|
const token = authHeader?.split("Bearer ")[1] || "";
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { ordersIn } from "../../controller/dm/ordersIn/ordersIn.js";
|
|||||||
import { verify } from "hono/jwt";
|
import { verify } from "hono/jwt";
|
||||||
import { forecastIn } from "../../controller/dm/forecast/forecastIn.js";
|
import { forecastIn } from "../../controller/dm/forecast/forecastIn.js";
|
||||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
@@ -32,7 +33,7 @@ app.openapi(
|
|||||||
responses: responses(),
|
responses: responses(),
|
||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
//apiHit(c, { endpoint: "api/sqlProd/close" });
|
apiHit(c, { endpoint: "/postforecastin" });
|
||||||
const body = await c.req.parseBody();
|
const body = await c.req.parseBody();
|
||||||
const authHeader = c.req.header("Authorization");
|
const authHeader = c.req.header("Authorization");
|
||||||
const token = authHeader?.split("Bearer ")[1] || "";
|
const token = authHeader?.split("Bearer ")[1] || "";
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
|||||||
import { standardTemplate } from "../../controller/dm/ordersIn/createTemplate.js";
|
import { standardTemplate } from "../../controller/dm/ordersIn/createTemplate.js";
|
||||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
import { standardForCastTemplate } from "../../controller/dm/forecast/createTemplate.js";
|
import { standardForCastTemplate } from "../../controller/dm/forecast/createTemplate.js";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
@@ -32,7 +33,7 @@ app.openapi(
|
|||||||
responses: responses(),
|
responses: responses(),
|
||||||
}),
|
}),
|
||||||
async (c: any) => {
|
async (c: any) => {
|
||||||
//apiHit(c, { endpoint: "api/sqlProd/close" });
|
apiHit(c, { endpoint: "/bulkforcasttemplate" });
|
||||||
const defaultFilename = `bulkForcastTemplate-${format(
|
const defaultFilename = `bulkForcastTemplate-${format(
|
||||||
new Date(Date.now()),
|
new Date(Date.now()),
|
||||||
"M-d-yyyy"
|
"M-d-yyyy"
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { format } from "date-fns";
|
|||||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||||
import { standardTemplate } from "../../controller/dm/ordersIn/createTemplate.js";
|
import { standardTemplate } from "../../controller/dm/ordersIn/createTemplate.js";
|
||||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
@@ -31,7 +32,7 @@ app.openapi(
|
|||||||
responses: responses(),
|
responses: responses(),
|
||||||
}),
|
}),
|
||||||
async (c: any) => {
|
async (c: any) => {
|
||||||
//apiHit(c, { endpoint: "api/sqlProd/close" });
|
apiHit(c, { endpoint: "/bulkorderstemplate" });
|
||||||
const defaultFilename = `bulkOrdersInTemplate-${format(
|
const defaultFilename = `bulkOrdersInTemplate-${format(
|
||||||
new Date(Date.now()),
|
new Date(Date.now()),
|
||||||
"M-d-yyyy"
|
"M-d-yyyy"
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
|||||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||||
import { getCycleCountCheck } from "../controller/warehouse/cycleCountChecks/getCycleCountCheck.js";
|
import { getCycleCountCheck } from "../controller/warehouse/cycleCountChecks/getCycleCountCheck.js";
|
||||||
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
@@ -30,7 +31,7 @@ app.openapi(
|
|||||||
responses: responses(),
|
responses: responses(),
|
||||||
}),
|
}),
|
||||||
async (c: any) => {
|
async (c: any) => {
|
||||||
//apiHit(c, { endpoint: "api/sqlProd/close" });
|
apiHit(c, { endpoint: "/cyclecountcheck" });
|
||||||
const { data: body, error: be } = await tryCatch(c.req.json());
|
const { data: body, error: be } = await tryCatch(c.req.json());
|
||||||
|
|
||||||
if (be) {
|
if (be) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
|||||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||||
import { lanesToExcel } from "../controller/warehouse/cycleCountChecks/exportCycleCountData.js";
|
import { lanesToExcel } from "../controller/warehouse/cycleCountChecks/exportCycleCountData.js";
|
||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
@@ -31,7 +32,7 @@ app.openapi(
|
|||||||
responses: responses(),
|
responses: responses(),
|
||||||
}),
|
}),
|
||||||
async (c: any) => {
|
async (c: any) => {
|
||||||
//apiHit(c, { endpoint: "api/sqlProd/close" });
|
apiHit(c, { endpoint: "/getcyclecount" });
|
||||||
const defaultFilename = `cycleCount-${format(
|
const defaultFilename = `cycleCount-${format(
|
||||||
new Date(Date.now()),
|
new Date(Date.now()),
|
||||||
"M-d-yyyy"
|
"M-d-yyyy"
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
|||||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||||
import { getCycleCountCheck } from "../controller/warehouse/cycleCountChecks/getCycleCountCheck.js";
|
import { getCycleCountCheck } from "../controller/warehouse/cycleCountChecks/getCycleCountCheck.js";
|
||||||
import { getPPOO } from "../controller/warehouse/ppoo/getPPOO.js";
|
import { getPPOO } from "../controller/warehouse/ppoo/getPPOO.js";
|
||||||
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
@@ -31,7 +32,7 @@ app.openapi(
|
|||||||
responses: responses(),
|
responses: responses(),
|
||||||
}),
|
}),
|
||||||
async (c: any) => {
|
async (c: any) => {
|
||||||
//apiHit(c, { endpoint: "api/sqlProd/close" });
|
apiHit(c, { endpoint: "/outbound" });
|
||||||
|
|
||||||
const body = await c.req.json();
|
const body = await c.req.json();
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
|||||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||||
import { getCycleCountCheck } from "../controller/warehouse/cycleCountChecks/getCycleCountCheck.js";
|
import { getCycleCountCheck } from "../controller/warehouse/cycleCountChecks/getCycleCountCheck.js";
|
||||||
import { getPPOO } from "../controller/warehouse/ppoo/getPPOO.js";
|
import { getPPOO } from "../controller/warehouse/ppoo/getPPOO.js";
|
||||||
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
@@ -31,7 +32,7 @@ app.openapi(
|
|||||||
responses: responses(),
|
responses: responses(),
|
||||||
}),
|
}),
|
||||||
async (c: any) => {
|
async (c: any) => {
|
||||||
//apiHit(c, { endpoint: "api/sqlProd/close" });
|
apiHit(c, { endpoint: "/getppoo" });
|
||||||
|
|
||||||
const { data: ppoo, error } = await tryCatch(getPPOO());
|
const { data: ppoo, error } = await tryCatch(getPPOO());
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
|
|||||||
import { apiHit } from "../../../globalUtils/apiHits.js";
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
import { verify } from "hono/jwt";
|
import { verify } from "hono/jwt";
|
||||||
import { returnMaterial } from "../controller/materials/returnMaterial.js";
|
import { returnMaterial } from "../controller/materials/returnMaterial.js";
|
||||||
|
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
@@ -36,7 +37,19 @@ app.openapi(
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
async (c) => {
|
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 authHeader = c.req.header("Authorization");
|
||||||
const token = authHeader?.split("Bearer ")[1] || "";
|
const token = authHeader?.split("Bearer ")[1] || "";
|
||||||
|
|
||||||
@@ -44,7 +57,7 @@ app.openapi(
|
|||||||
const payload = await verify(token, process.env.JWT_SECRET!);
|
const payload = await verify(token, process.env.JWT_SECRET!);
|
||||||
try {
|
try {
|
||||||
//return apiReturn(c, true, access?.message, access?.data, 200);
|
//return apiReturn(c, true, access?.message, access?.data, 200);
|
||||||
const data = await c.req.json();
|
|
||||||
const consume = await returnMaterial(data, payload);
|
const consume = await returnMaterial(data, payload);
|
||||||
return c.json(
|
return c.json(
|
||||||
{ success: consume?.success, message: consume?.message },
|
{ success: consume?.success, message: consume?.message },
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import { verify } from "hono/jwt";
|
|||||||
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
||||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||||
import { createSiloAdjustment } from "../../controller/siloAdjustments/createSiloAdjustment.js";
|
import { createSiloAdjustment } from "../../controller/siloAdjustments/createSiloAdjustment.js";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
@@ -23,7 +25,19 @@ app.openapi(
|
|||||||
responses: responses(),
|
responses: responses(),
|
||||||
}),
|
}),
|
||||||
async (c) => {
|
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 authHeader = c.req.header("Authorization");
|
||||||
const token = authHeader?.split("Bearer ")[1] || "";
|
const token = authHeader?.split("Bearer ")[1] || "";
|
||||||
|
|
||||||
@@ -31,7 +45,6 @@ app.openapi(
|
|||||||
const payload = await verify(token, process.env.JWT_SECRET!);
|
const payload = await verify(token, process.env.JWT_SECRET!);
|
||||||
try {
|
try {
|
||||||
//return apiReturn(c, true, access?.message, access?.data, 200);
|
//return apiReturn(c, true, access?.message, access?.data, 200);
|
||||||
const data = await c.req.json();
|
|
||||||
const createSiloAdj = await createSiloAdjustment(
|
const createSiloAdj = await createSiloAdjustment(
|
||||||
data,
|
data,
|
||||||
payload.user
|
payload.user
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
|||||||
import { getOpenOrders } from "../../../dataMart/controller/getOpenOrders.js";
|
import { getOpenOrders } from "../../../dataMart/controller/getOpenOrders.js";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { getSiloAdjustments } from "../../controller/siloAdjustments/getSiloAdjustments.js";
|
import { getSiloAdjustments } from "../../controller/siloAdjustments/getSiloAdjustments.js";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono({ strict: false });
|
const app = new OpenAPIHono({ strict: false });
|
||||||
// const Body = z.object({
|
// const Body = z.object({
|
||||||
@@ -26,6 +27,7 @@ app.openapi(
|
|||||||
}),
|
}),
|
||||||
async (c: any) => {
|
async (c: any) => {
|
||||||
const customer: any = c.req.queries();
|
const customer: any = c.req.queries();
|
||||||
|
apiHit(c, { endpoint: "/getsilosdjustment" });
|
||||||
|
|
||||||
// make sure we have a vaid user being accessed thats really logged in
|
// make sure we have a vaid user being accessed thats really logged in
|
||||||
//apiHit(c, { endpoint: `api/logger/logs/id` });
|
//apiHit(c, { endpoint: `api/logger/logs/id` });
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
|||||||
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
||||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||||
import { getStockSiloData } from "../../controller/siloAdjustments/getCurrentStockSiloData.js";
|
import { getStockSiloData } from "../../controller/siloAdjustments/getCurrentStockSiloData.js";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
@@ -21,7 +22,7 @@ app.openapi(
|
|||||||
responses: responses(),
|
responses: responses(),
|
||||||
}),
|
}),
|
||||||
async (c: any) => {
|
async (c: any) => {
|
||||||
//apiHit(c, { endpoint: "api/sqlProd/close" });
|
apiHit(c, { endpoint: "/getstocksilo" });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//return apiReturn(c, true, access?.message, access?.data, 200);
|
//return apiReturn(c, true, access?.message, access?.data, 200);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
|||||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||||
import { createSiloAdjustment } from "../../controller/siloAdjustments/createSiloAdjustment.js";
|
import { createSiloAdjustment } from "../../controller/siloAdjustments/createSiloAdjustment.js";
|
||||||
import { postSiloComment } from "../../controller/siloAdjustments/postComment.js";
|
import { postSiloComment } from "../../controller/siloAdjustments/postComment.js";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
@@ -42,7 +43,7 @@ app.openapi(
|
|||||||
responses: responses(),
|
responses: responses(),
|
||||||
}),
|
}),
|
||||||
async (c: any) => {
|
async (c: any) => {
|
||||||
//apiHit(c, { endpoint: "api/sqlProd/close" });
|
apiHit(c, { endpoint: "/postcomment" });
|
||||||
const authHeader = c.req.header("Authorization");
|
const authHeader = c.req.header("Authorization");
|
||||||
const token = authHeader?.split("Bearer ")[1] || "";
|
const token = authHeader?.split("Bearer ")[1] || "";
|
||||||
const { adjId } = c.req.valid("param");
|
const { adjId } = c.req.valid("param");
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||||
import { getAllJobs } from "../utils/processNotifications.js";
|
import { getAllJobs } from "../utils/processNotifications.js";
|
||||||
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono({ strict: false });
|
const app = new OpenAPIHono({ strict: false });
|
||||||
|
|
||||||
@@ -15,6 +16,7 @@ app.openapi(
|
|||||||
responses: responses(),
|
responses: responses(),
|
||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
|
apiHit(c, { endpoint: "/activenotifications" });
|
||||||
const jobs = getAllJobs();
|
const jobs = getAllJobs();
|
||||||
return c.json({
|
return c.json({
|
||||||
success: true,
|
success: true,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
|||||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||||
import { getNotifications } from "../controller/getNotifications.js";
|
import { getNotifications } from "../controller/getNotifications.js";
|
||||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||||
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono({ strict: false });
|
const app = new OpenAPIHono({ strict: false });
|
||||||
|
|
||||||
@@ -18,7 +19,7 @@ app.openapi(
|
|||||||
responses: responses(),
|
responses: responses(),
|
||||||
}),
|
}),
|
||||||
async (c: any) => {
|
async (c: any) => {
|
||||||
//apiHit(c, { endpoint: `api/logger/logs` });
|
apiHit(c, { endpoint: "/notifications" });
|
||||||
const { data, error } = await tryCatch(getNotifications());
|
const { data, error } = await tryCatch(getNotifications());
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
|||||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||||
|
|
||||||
import runTiImport from "../controller/notifications/tiIntergration.js";
|
import runTiImport from "../controller/notifications/tiIntergration.js";
|
||||||
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono({ strict: false });
|
const app = new OpenAPIHono({ strict: false });
|
||||||
|
|
||||||
@@ -16,6 +17,7 @@ app.openapi(
|
|||||||
responses: responses(),
|
responses: responses(),
|
||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
|
apiHit(c, { endpoint: "/tiTrigger" });
|
||||||
const tiImport = await runTiImport();
|
const tiImport = await runTiImport();
|
||||||
return c.json({
|
return c.json({
|
||||||
success: tiImport?.success,
|
success: tiImport?.success,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
|||||||
import { notifications } from "../../../../database/schema/notifications.js";
|
import { notifications } from "../../../../database/schema/notifications.js";
|
||||||
import { db } from "../../../../database/dbclient.js";
|
import { db } from "../../../../database/dbclient.js";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono({ strict: false });
|
const app = new OpenAPIHono({ strict: false });
|
||||||
|
|
||||||
@@ -24,7 +25,7 @@ app.openapi(
|
|||||||
/**
|
/**
|
||||||
* get the blocking notification stuff
|
* get the blocking notification stuff
|
||||||
*/
|
*/
|
||||||
|
apiHit(c, { endpoint: "/blockingTrigger" });
|
||||||
const { data, error } = await tryCatch(
|
const { data, error } = await tryCatch(
|
||||||
db
|
db
|
||||||
.select()
|
.select()
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
|||||||
import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
|
import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
|
||||||
import { sendEmail } from "../controller/sendMail.js";
|
import { sendEmail } from "../controller/sendMail.js";
|
||||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||||
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono({ strict: false });
|
const app = new OpenAPIHono({ strict: false });
|
||||||
|
|
||||||
@@ -41,6 +42,7 @@ app.openapi(
|
|||||||
const { data: bodyData, error: bodyError } = await tryCatch(
|
const { data: bodyData, error: bodyError } = await tryCatch(
|
||||||
c.req.json()
|
c.req.json()
|
||||||
);
|
);
|
||||||
|
apiHit(c, { endpoint: "/sendmail", lastBody: bodyData });
|
||||||
if (bodyError) {
|
if (bodyError) {
|
||||||
return c.json(
|
return c.json(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -30,10 +30,9 @@ app.openapi(
|
|||||||
responses: responses(),
|
responses: responses(),
|
||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
apiHit(c, { endpoint: "api/auth/register" });
|
|
||||||
// make sure we have a vaid user being accessed thats really logged in
|
// make sure we have a vaid user being accessed thats really logged in
|
||||||
const body = await c.req.json();
|
const body = await c.req.json();
|
||||||
|
apiHit(c, { endpoint: "/cycleCount", lastBody: body });
|
||||||
const authHeader = c.req.header("Authorization");
|
const authHeader = c.req.header("Authorization");
|
||||||
|
|
||||||
const token = authHeader?.split("Bearer ")[1] || "";
|
const token = authHeader?.split("Bearer ")[1] || "";
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ app.openapi(
|
|||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
// make sure we have a vaid user being accessed thats really logged in
|
// make sure we have a vaid user being accessed thats really logged in
|
||||||
apiHit(c, { endpoint: "api/auth/register" });
|
apiHit(c, { endpoint: "/getInfo" });
|
||||||
try {
|
try {
|
||||||
return c.json(
|
return c.json(
|
||||||
{ success: true, message: "Ocme Info", data: await getInfo() },
|
{ success: true, message: "Ocme Info", data: await getInfo() },
|
||||||
|
|||||||
@@ -46,7 +46,10 @@ app.openapi(
|
|||||||
.string()
|
.string()
|
||||||
.optional()
|
.optional()
|
||||||
.openapi({ example: "Internal Server error" }),
|
.openapi({ example: "Internal Server error" }),
|
||||||
data: z.array(z.object({})).optional().openapi({ example: [] }),
|
data: z
|
||||||
|
.array(z.object({}))
|
||||||
|
.optional()
|
||||||
|
.openapi({ example: [] }),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -74,7 +77,7 @@ app.openapi(
|
|||||||
// make sure we have a vaid user being accessed thats really logged in
|
// make sure we have a vaid user being accessed thats really logged in
|
||||||
try {
|
try {
|
||||||
const data = await c.req.json();
|
const data = await c.req.json();
|
||||||
apiHit(c, { endpoint: "api/ocme/getshipmentpallets", lastBody: data });
|
apiHit(c, { endpoint: "/getshipmentpallets", lastBody: data });
|
||||||
|
|
||||||
console.log;
|
console.log;
|
||||||
|
|
||||||
@@ -82,7 +85,8 @@ app.openapi(
|
|||||||
return c.json(
|
return c.json(
|
||||||
{
|
{
|
||||||
success: false,
|
success: false,
|
||||||
message: "You are missing the shipment id please try again.",
|
message:
|
||||||
|
"You are missing the shipment id please try again.",
|
||||||
data: [],
|
data: [],
|
||||||
},
|
},
|
||||||
400
|
400
|
||||||
|
|||||||
@@ -56,7 +56,10 @@ app.openapi(
|
|||||||
.string()
|
.string()
|
||||||
.optional()
|
.optional()
|
||||||
.openapi({ example: "Internal Server error" }),
|
.openapi({ example: "Internal Server error" }),
|
||||||
data: z.array(z.object({})).optional().openapi({ example: [] }),
|
data: z
|
||||||
|
.array(z.object({}))
|
||||||
|
.optional()
|
||||||
|
.openapi({ example: [] }),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -89,7 +92,7 @@ app.openapi(
|
|||||||
// make sure we have a vaid user being accessed thats really logged in
|
// make sure we have a vaid user being accessed thats really logged in
|
||||||
try {
|
try {
|
||||||
const data = await c.req.json();
|
const data = await c.req.json();
|
||||||
apiHit(c, { endpoint: "api/ocme/pickedup", lastBody: data });
|
apiHit(c, { endpoint: "/pickedup", lastBody: data });
|
||||||
const postPallet = await pickedup(data);
|
const postPallet = await pickedup(data);
|
||||||
return c.json(
|
return c.json(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ app.openapi(
|
|||||||
try {
|
try {
|
||||||
const data = await c.req.json();
|
const data = await c.req.json();
|
||||||
apiHit(c, {
|
apiHit(c, {
|
||||||
endpoint: "api/ocme/postRunningNumber",
|
endpoint: "/postRunningNumber",
|
||||||
lastBody: data,
|
lastBody: data,
|
||||||
});
|
});
|
||||||
const postPallet: any = await postLabelData(data);
|
const postPallet: any = await postLabelData(data);
|
||||||
|
|||||||
@@ -53,7 +53,10 @@ app.openapi(
|
|||||||
.string()
|
.string()
|
||||||
.optional()
|
.optional()
|
||||||
.openapi({ example: "Internal Server error" }),
|
.openapi({ example: "Internal Server error" }),
|
||||||
data: z.array(z.object({})).optional().openapi({ example: [] }),
|
data: z
|
||||||
|
.array(z.object({}))
|
||||||
|
.optional()
|
||||||
|
.openapi({ example: [] }),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -81,7 +84,7 @@ app.openapi(
|
|||||||
// make sure we have a vaid user being accessed thats really logged in
|
// make sure we have a vaid user being accessed thats really logged in
|
||||||
try {
|
try {
|
||||||
const data = await c.req.json();
|
const data = await c.req.json();
|
||||||
apiHit(c, { endpoint: "api/ocme/postRunningNumber", lastBody: data });
|
apiHit(c, { endpoint: "/postRunningNumber", lastBody: data });
|
||||||
const postPallet = await postLabelData(data);
|
const postPallet = await postLabelData(data);
|
||||||
return c.json(
|
return c.json(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ app.openapi(
|
|||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
// make sure we have a vaid user being accessed thats really logged in
|
// 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();
|
const manualTrigger: any = await triggerScanner();
|
||||||
console.log(manualTrigger);
|
console.log(manualTrigger);
|
||||||
return c.json({
|
return c.json({
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
|||||||
import { labelingProcess } from "../../controller/labeling/labelProcess.js";
|
import { labelingProcess } from "../../controller/labeling/labelProcess.js";
|
||||||
import { bookInLabel } from "../../controller/labeling/bookIn.js";
|
import { bookInLabel } from "../../controller/labeling/bookIn.js";
|
||||||
import { createSSCC } from "../../../../globalUtils/createSSCC.js";
|
import { createSSCC } from "../../../../globalUtils/createSSCC.js";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono({ strict: false });
|
const app = new OpenAPIHono({ strict: false });
|
||||||
|
|
||||||
@@ -21,6 +22,7 @@ app.openapi(
|
|||||||
const { data: bodyData, error: bodyError } = await tryCatch(
|
const { data: bodyData, error: bodyError } = await tryCatch(
|
||||||
c.req.json()
|
c.req.json()
|
||||||
);
|
);
|
||||||
|
apiHit(c, { endpoint: "/bookin", lastBody: bodyData });
|
||||||
|
|
||||||
if (bodyError) {
|
if (bodyError) {
|
||||||
return c.json({
|
return c.json({
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
|||||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
import { getLabels } from "../../controller/labeling/getLabels.js";
|
import { getLabels } from "../../controller/labeling/getLabels.js";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono({ strict: false });
|
const app = new OpenAPIHono({ strict: false });
|
||||||
|
|
||||||
@@ -19,6 +20,7 @@ app.openapi(
|
|||||||
const { data: labelData, error: labelError } = await tryCatch(
|
const { data: labelData, error: labelError } = await tryCatch(
|
||||||
getLabels(hours ?? "2")
|
getLabels(hours ?? "2")
|
||||||
);
|
);
|
||||||
|
apiHit(c, { endpoint: "/getLabels" });
|
||||||
|
|
||||||
if (labelError) {
|
if (labelError) {
|
||||||
return c.json({
|
return c.json({
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
|||||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
import { labelingProcess } from "../../controller/labeling/labelProcess.js";
|
import { labelingProcess } from "../../controller/labeling/labelProcess.js";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono({ strict: false });
|
const app = new OpenAPIHono({ strict: false });
|
||||||
|
|
||||||
@@ -19,6 +20,7 @@ app.openapi(
|
|||||||
const { data: bodyData, error: bodyError } = await tryCatch(
|
const { data: bodyData, error: bodyError } = await tryCatch(
|
||||||
c.req.json()
|
c.req.json()
|
||||||
);
|
);
|
||||||
|
apiHit(c, { endpoint: "/manualprintandfollow", lastBody: bodyData });
|
||||||
|
|
||||||
if (bodyError) {
|
if (bodyError) {
|
||||||
return c.json({
|
return c.json({
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ app.openapi(
|
|||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
const { data: body, error } = await tryCatch(c.req.json());
|
const { data: body, error } = await tryCatch(c.req.json());
|
||||||
|
apiHit(c, { endpoint: "/manuallabellog", lastBody: body });
|
||||||
if (error) {
|
if (error) {
|
||||||
return c.json(
|
return c.json(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
|||||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
import { getLots } from "../../controller/lots/lots.js";
|
import { getLots } from "../../controller/lots/lots.js";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono({ strict: false });
|
const app = new OpenAPIHono({ strict: false });
|
||||||
|
|
||||||
@@ -16,7 +17,7 @@ app.openapi(
|
|||||||
}),
|
}),
|
||||||
async (c: any) => {
|
async (c: any) => {
|
||||||
const { data: lotData, error: lotError } = await tryCatch(getLots());
|
const { data: lotData, error: lotError } = await tryCatch(getLots());
|
||||||
|
apiHit(c, { endpoint: "/getlots" });
|
||||||
if (lotError) {
|
if (lotError) {
|
||||||
return c.json({
|
return c.json({
|
||||||
success: false,
|
success: false,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
|||||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
import { printerCycle } from "../../controller/printers/printerCycle.js";
|
import { printerCycle } from "../../controller/printers/printerCycle.js";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono({ strict: false });
|
const app = new OpenAPIHono({ strict: false });
|
||||||
|
|
||||||
@@ -22,6 +23,7 @@ app.openapi(
|
|||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
const { data, error } = await tryCatch(printerCycle());
|
const { data, error } = await tryCatch(printerCycle());
|
||||||
|
apiHit(c, { endpoint: "/startsprintercycle" });
|
||||||
const dataError: any = error;
|
const dataError: any = error;
|
||||||
if (error) {
|
if (error) {
|
||||||
return c.json({
|
return c.json({
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
|||||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
import { stopPrinterCycle } from "../../controller/printers/printerCycle.js";
|
import { stopPrinterCycle } from "../../controller/printers/printerCycle.js";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono({ strict: false });
|
const app = new OpenAPIHono({ strict: false });
|
||||||
|
|
||||||
@@ -22,6 +23,7 @@ app.openapi(
|
|||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
const { data, error } = await tryCatch(stopPrinterCycle());
|
const { data, error } = await tryCatch(stopPrinterCycle());
|
||||||
|
apiHit(c, { endpoint: "/stopprintercycle" });
|
||||||
const dataError: any = error;
|
const dataError: any = error;
|
||||||
if (error) {
|
if (error) {
|
||||||
return c.json({
|
return c.json({
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
|||||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
import { getPrinters } from "../../controller/printers/getPrinters.js";
|
import { getPrinters } from "../../controller/printers/getPrinters.js";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono({ strict: false });
|
const app = new OpenAPIHono({ strict: false });
|
||||||
const CreateLog = z.object({
|
const CreateLog = z.object({
|
||||||
@@ -32,6 +33,7 @@ app.openapi(
|
|||||||
const { data: printData, error: printError } = await tryCatch(
|
const { data: printData, error: printError } = await tryCatch(
|
||||||
getPrinters()
|
getPrinters()
|
||||||
);
|
);
|
||||||
|
apiHit(c, { endpoint: "/getprinters" });
|
||||||
|
|
||||||
if (printError) {
|
if (printError) {
|
||||||
return c.json({
|
return c.json({
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
|||||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
import { printerCycle } from "../../controller/printers/printerCycle.js";
|
import { printerCycle } from "../../controller/printers/printerCycle.js";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono({ strict: false });
|
const app = new OpenAPIHono({ strict: false });
|
||||||
|
|
||||||
@@ -22,6 +23,7 @@ app.openapi(
|
|||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
const { data, error } = await tryCatch(printerCycle());
|
const { data, error } = await tryCatch(printerCycle());
|
||||||
|
apiHit(c, { endpoint: "/startsprintercycle" });
|
||||||
const dataError: any = error;
|
const dataError: any = error;
|
||||||
if (error) {
|
if (error) {
|
||||||
return c.json({
|
return c.json({
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
|||||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
import { stopPrinterCycle } from "../../controller/printers/printerCycle.js";
|
import { stopPrinterCycle } from "../../controller/printers/printerCycle.js";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono({ strict: false });
|
const app = new OpenAPIHono({ strict: false });
|
||||||
|
|
||||||
@@ -22,6 +23,7 @@ app.openapi(
|
|||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
const { data, error } = await tryCatch(stopPrinterCycle());
|
const { data, error } = await tryCatch(stopPrinterCycle());
|
||||||
|
apiHit(c, { endpoint: "/stopprintercycle" });
|
||||||
const dataError: any = error;
|
const dataError: any = error;
|
||||||
if (error) {
|
if (error) {
|
||||||
return c.json({
|
return c.json({
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
|||||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
import { updatePrinters } from "../../controller/printers/updatePrinters.js";
|
import { updatePrinters } from "../../controller/printers/updatePrinters.js";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono({ strict: false });
|
const app = new OpenAPIHono({ strict: false });
|
||||||
const CreateLog = z.object({
|
const CreateLog = z.object({
|
||||||
@@ -32,6 +33,7 @@ app.openapi(
|
|||||||
const { data: printData, error: printError } = await tryCatch(
|
const { data: printData, error: printError } = await tryCatch(
|
||||||
updatePrinters()
|
updatePrinters()
|
||||||
);
|
);
|
||||||
|
apiHit(c, { endpoint: "/updateprinters" });
|
||||||
|
|
||||||
if (printError) {
|
if (printError) {
|
||||||
return c.json({
|
return c.json({
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { responses } from "../../../../../globalUtils/routeDefs/responses.js";
|
|||||||
import { authMiddleware } from "../../../../auth/middleware/authMiddleware.js";
|
import { authMiddleware } from "../../../../auth/middleware/authMiddleware.js";
|
||||||
import { tryCatch } from "../../../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../../../globalUtils/tryCatch.js";
|
||||||
import { closeDyco } from "../../../controller/specialProcesses/dyco/plcConnection.js";
|
import { closeDyco } from "../../../controller/specialProcesses/dyco/plcConnection.js";
|
||||||
|
import { apiHit } from "../../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono({ strict: false });
|
const app = new OpenAPIHono({ strict: false });
|
||||||
|
|
||||||
@@ -23,7 +24,7 @@ app.openapi(
|
|||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
//const body = await c.req.json();
|
//const body = await c.req.json();
|
||||||
//apiHit(c, {endpoint: `api/logger/logs/id`});
|
apiHit(c, { endpoint: `dycodisconnect` });
|
||||||
// const authHeader = c.req.header("Authorization");
|
// const authHeader = c.req.header("Authorization");
|
||||||
|
|
||||||
// const token = authHeader?.split("Bearer ")[1] || "";
|
// const token = authHeader?.split("Bearer ")[1] || "";
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { responses } from "../../../../../globalUtils/routeDefs/responses.js";
|
|||||||
import { authMiddleware } from "../../../../auth/middleware/authMiddleware.js";
|
import { authMiddleware } from "../../../../auth/middleware/authMiddleware.js";
|
||||||
import { tryCatch } from "../../../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../../../globalUtils/tryCatch.js";
|
||||||
import { dycoConnect } from "../../../controller/specialProcesses/dyco/plcConnection.js";
|
import { dycoConnect } from "../../../controller/specialProcesses/dyco/plcConnection.js";
|
||||||
|
import { apiHit } from "../../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono({ strict: false });
|
const app = new OpenAPIHono({ strict: false });
|
||||||
|
|
||||||
@@ -22,7 +23,7 @@ app.openapi(
|
|||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
//const body = await c.req.json();
|
//const body = await c.req.json();
|
||||||
//apiHit(c, {endpoint: `api/logger/logs/id`});
|
apiHit(c, { endpoint: `dycoconnect` });
|
||||||
// const authHeader = c.req.header("Authorization");
|
// const authHeader = c.req.header("Authorization");
|
||||||
|
|
||||||
// const token = authHeader?.split("Bearer ")[1] || "";
|
// const token = authHeader?.split("Bearer ")[1] || "";
|
||||||
@@ -37,6 +38,7 @@ app.openapi(
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
const { data, error } = await tryCatch(dycoConnect());
|
const { data, error } = await tryCatch(dycoConnect());
|
||||||
|
|
||||||
const dataError: any = error;
|
const dataError: any = error;
|
||||||
if (error) {
|
if (error) {
|
||||||
return c.json({
|
return c.json({
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
|||||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||||
import { getRequest } from "../controller/getRequests.js";
|
import { getRequest } from "../controller/getRequests.js";
|
||||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||||
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono({ strict: false });
|
const app = new OpenAPIHono({ strict: false });
|
||||||
|
|
||||||
@@ -16,7 +17,7 @@ app.openapi(
|
|||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
const { data, error } = await tryCatch(getRequest());
|
const { data, error } = await tryCatch(getRequest());
|
||||||
|
apiHit(c, { endpoint: "/getrequest" });
|
||||||
if (error) {
|
if (error) {
|
||||||
return c.json({
|
return c.json({
|
||||||
success: false,
|
success: false,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
|||||||
import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
|
import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
|
||||||
import { addNewPallet } from "../controller/addNewPallet.js";
|
import { addNewPallet } from "../controller/addNewPallet.js";
|
||||||
import { verify } from "hono/jwt";
|
import { verify } from "hono/jwt";
|
||||||
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono({ strict: false });
|
const app = new OpenAPIHono({ strict: false });
|
||||||
const Body = z.object({
|
const Body = z.object({
|
||||||
@@ -36,7 +37,7 @@ app.openapi(
|
|||||||
const user: any = payload.user;
|
const user: any = payload.user;
|
||||||
|
|
||||||
const { data: b, error: e } = await tryCatch(c.req.json());
|
const { data: b, error: e } = await tryCatch(c.req.json());
|
||||||
|
apiHit(c, { endpoint: "/newrequest", lastBody: b });
|
||||||
if (e) {
|
if (e) {
|
||||||
return c.json({
|
return c.json({
|
||||||
success: false,
|
success: false,
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
|
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
|
||||||
import {addReader} from "../controller/addReader.js";
|
import { addReader } from "../controller/addReader.js";
|
||||||
import {authMiddleware} from "../../auth/middleware/authMiddleware.js";
|
import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
|
||||||
import {responses} from "../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||||
import type {User} from "../../../types/users.js";
|
import type { User } from "../../../types/users.js";
|
||||||
import {verify} from "hono/jwt";
|
import { verify } from "hono/jwt";
|
||||||
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
export const ReaderBody = z.object({
|
export const ReaderBody = z.object({
|
||||||
reader: z.string().openapi({example: "wrapper1"}),
|
reader: z.string().openapi({ example: "wrapper1" }),
|
||||||
readerIP: z.string().openapi({example: "192.168.1.52"}),
|
readerIP: z.string().openapi({ example: "192.168.1.52" }),
|
||||||
});
|
});
|
||||||
|
|
||||||
app.openapi(
|
app.openapi(
|
||||||
@@ -21,14 +22,14 @@ app.openapi(
|
|||||||
middleware: authMiddleware,
|
middleware: authMiddleware,
|
||||||
description: "Adding in a new reader to add to the network.",
|
description: "Adding in a new reader to add to the network.",
|
||||||
request: {
|
request: {
|
||||||
body: {content: {"application/json": {schema: ReaderBody}}},
|
body: { content: { "application/json": { schema: ReaderBody } } },
|
||||||
},
|
},
|
||||||
responses: responses(),
|
responses: responses(),
|
||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
const body = await c.req.json();
|
const body = await c.req.json();
|
||||||
const authHeader = c.req.header("Authorization");
|
const authHeader = c.req.header("Authorization");
|
||||||
|
apiHit(c, { endpoint: "/addreader", lastBody: body });
|
||||||
const token = authHeader?.split("Bearer ")[1] || "";
|
const token = authHeader?.split("Bearer ")[1] || "";
|
||||||
let user: User;
|
let user: User;
|
||||||
|
|
||||||
@@ -36,14 +37,26 @@ app.openapi(
|
|||||||
const payload = await verify(token, process.env.JWT_SECRET!);
|
const payload = await verify(token, process.env.JWT_SECRET!);
|
||||||
user = payload.user as User;
|
user = payload.user as User;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return c.json({message: "Unauthorized"}, 401);
|
return c.json({ message: "Unauthorized" }, 401);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const addingReader = await addReader(body, user);
|
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) {
|
} 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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
//http://usday1vms006:4000/api/v1/zebra/wrapper1
|
//http://usday1vms006:4000/api/v1/zebra/wrapper1
|
||||||
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
|
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
|
||||||
import {responses} from "../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||||
import {authMiddleware} from "../../auth/middleware/authMiddleware.js";
|
import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
|
||||||
import {manualTag} from "../controller/tags/manualTag.js";
|
import { manualTag } from "../controller/tags/manualTag.js";
|
||||||
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
const RequestBody = z.object({
|
const RequestBody = z.object({
|
||||||
tagNumber: z.string().openapi({example: "2541"}),
|
tagNumber: z.string().openapi({ example: "2541" }),
|
||||||
});
|
});
|
||||||
|
|
||||||
app.openapi(
|
app.openapi(
|
||||||
@@ -18,20 +19,37 @@ app.openapi(
|
|||||||
path: "/manualtag",
|
path: "/manualtag",
|
||||||
middleware: authMiddleware,
|
middleware: authMiddleware,
|
||||||
request: {
|
request: {
|
||||||
body: {content: {"application/json": {schema: RequestBody}}},
|
body: { content: { "application/json": { schema: RequestBody } } },
|
||||||
},
|
},
|
||||||
responses: responses(),
|
responses: responses(),
|
||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
const body =
|
const body =
|
||||||
(await c.req.json()) ??
|
(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 {
|
try {
|
||||||
const tag = await manualTag(body.tag, body.area);
|
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) {
|
} 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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
//http://usday1vms006:4000/api/v1/zebra/wrapper1
|
//http://usday1vms006:4000/api/v1/zebra/wrapper1
|
||||||
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
|
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
|
||||||
import {responses} from "../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||||
import {readTags} from "../controller/readTags.js";
|
import { readTags } from "../controller/readTags.js";
|
||||||
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
@@ -30,10 +31,16 @@ app.openapi(
|
|||||||
responses: responses(),
|
responses: responses(),
|
||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
const {reader} = c.req.valid("param");
|
const { reader } = c.req.valid("param");
|
||||||
const manualTrigger = await readTags(reader);
|
const manualTrigger = await readTags(reader);
|
||||||
|
apiHit(c, { endpoint: `/manualtrigger/${reader}` });
|
||||||
return c.json({success: true, message: `A Manaul trigger was done on ${reader}`}, 200);
|
return c.json(
|
||||||
|
{
|
||||||
|
success: true,
|
||||||
|
message: `A Manaul trigger was done on ${reader}`,
|
||||||
|
},
|
||||||
|
200
|
||||||
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { readTags } from "../controller/readTags.js";
|
|||||||
import { createLog } from "../../logger/logger.js";
|
import { createLog } from "../../logger/logger.js";
|
||||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||||
import { newHeartBeat } from "../controller/readerControl.js";
|
import { newHeartBeat } from "../controller/readerControl.js";
|
||||||
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
let lastGpiTimestamp = 0;
|
let lastGpiTimestamp = 0;
|
||||||
@@ -35,7 +36,7 @@ app.openapi(
|
|||||||
async (c) => {
|
async (c) => {
|
||||||
const { reader } = c.req.valid("param");
|
const { reader } = c.req.valid("param");
|
||||||
const body = await c.req.json();
|
const body = await c.req.json();
|
||||||
|
apiHit(c, { endpoint: `/mgtevents/${reader}` });
|
||||||
if (body.type === "heartbeat") {
|
if (body.type === "heartbeat") {
|
||||||
const heart = await newHeartBeat(reader);
|
const heart = await newHeartBeat(reader);
|
||||||
return c.json(
|
return c.json(
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { badRead, goodRead } from "../controller/readerControl.js";
|
|||||||
import { createLog } from "../../logger/logger.js";
|
import { createLog } from "../../logger/logger.js";
|
||||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||||
import { stopRead } from "../controller/readTags.js";
|
import { stopRead } from "../controller/readTags.js";
|
||||||
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
@@ -40,7 +41,7 @@ app.openapi(
|
|||||||
createLog("info", "rfid", "rfid", `${reader} is sending us data.`);
|
createLog("info", "rfid", "rfid", `${reader} is sending us data.`);
|
||||||
let tagdata: any = [];
|
let tagdata: any = [];
|
||||||
const { data: body, error: bodyError } = await tryCatch(c.req.json());
|
const { data: body, error: bodyError } = await tryCatch(c.req.json());
|
||||||
|
apiHit(c, { endpoint: `/taginfo/${reader}`, lastBody: body });
|
||||||
if (bodyError) {
|
if (bodyError) {
|
||||||
return c.json({ success: false, message: "missing data" }, 400);
|
return c.json({ success: false, message: "missing data" }, 400);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
|
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
|
||||||
import {addReader} from "../controller/addReader.js";
|
import { addReader } from "../controller/addReader.js";
|
||||||
import {authMiddleware} from "../../auth/middleware/authMiddleware.js";
|
import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
|
||||||
import {responses} from "../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||||
import type {User} from "../../../types/users.js";
|
import type { User } from "../../../types/users.js";
|
||||||
import {verify} from "hono/jwt";
|
import { verify } from "hono/jwt";
|
||||||
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
export const ReaderBody = z.object({
|
export const ReaderBody = z.object({
|
||||||
reader: z.string().openapi({example: "wrapper1"}),
|
reader: z.string().openapi({ example: "wrapper1" }),
|
||||||
readerIP: z.string().openapi({example: "192.168.1.52"}),
|
readerIP: z.string().openapi({ example: "192.168.1.52" }),
|
||||||
active: z.boolean().optional().openapi({example: true}),
|
active: z.boolean().optional().openapi({ example: true }),
|
||||||
});
|
});
|
||||||
|
|
||||||
app.openapi(
|
app.openapi(
|
||||||
@@ -22,14 +23,14 @@ app.openapi(
|
|||||||
middleware: authMiddleware,
|
middleware: authMiddleware,
|
||||||
description: "Updates the reader data..",
|
description: "Updates the reader data..",
|
||||||
request: {
|
request: {
|
||||||
body: {content: {"application/json": {schema: ReaderBody}}},
|
body: { content: { "application/json": { schema: ReaderBody } } },
|
||||||
},
|
},
|
||||||
responses: responses(),
|
responses: responses(),
|
||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
const body = await c.req.json();
|
const body = await c.req.json();
|
||||||
const authHeader = c.req.header("Authorization");
|
const authHeader = c.req.header("Authorization");
|
||||||
|
apiHit(c, { endpoint: `/updatereader`, lastBody: body });
|
||||||
const token = authHeader?.split("Bearer ")[1] || "";
|
const token = authHeader?.split("Bearer ")[1] || "";
|
||||||
let user: User;
|
let user: User;
|
||||||
|
|
||||||
@@ -37,14 +38,26 @@ app.openapi(
|
|||||||
const payload = await verify(token, process.env.JWT_SECRET!);
|
const payload = await verify(token, process.env.JWT_SECRET!);
|
||||||
user = payload.user as User;
|
user = payload.user as User;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return c.json({message: "Unauthorized"}, 401);
|
return c.json({ message: "Unauthorized" }, 401);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const addingReader = await addReader(body, user);
|
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) {
|
} 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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,16 +1,23 @@
|
|||||||
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
|
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
|
||||||
import type {User} from "../../../../types/users.js";
|
import type { User } from "../../../../types/users.js";
|
||||||
import {verify} from "hono/jwt";
|
import { verify } from "hono/jwt";
|
||||||
import {authMiddleware} from "../../../auth/middleware/authMiddleware.js";
|
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
||||||
import {addModule} from "../../controller/module/addModule.js";
|
import { addModule } from "../../controller/module/addModule.js";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
// Define the response schema
|
// Define the response schema
|
||||||
const responseSchema = z.object({
|
const responseSchema = z.object({
|
||||||
message: z.string().optional(),
|
message: z.string().optional(),
|
||||||
module_id: z.string().openapi({example: "6c922c6c-7de3-4ec4-acb0-f068abdc"}).optional(),
|
module_id: z
|
||||||
name: z.string().openapi({example: "Production"}).optional(),
|
.string()
|
||||||
active: z.boolean().openapi({example: true}).optional(),
|
.openapi({ example: "6c922c6c-7de3-4ec4-acb0-f068abdc" })
|
||||||
roles: z.string().openapi({example: `["viewer","technician"]`}).optional(),
|
.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 app = new OpenAPIHono();
|
||||||
@@ -29,7 +36,7 @@ const app = new OpenAPIHono();
|
|||||||
// });
|
// });
|
||||||
|
|
||||||
const AddModule = z.object({
|
const AddModule = z.object({
|
||||||
name: z.string().openapi({example: "production"}),
|
name: z.string().openapi({ example: "production" }),
|
||||||
});
|
});
|
||||||
|
|
||||||
app.openapi(
|
app.openapi(
|
||||||
@@ -42,21 +49,26 @@ app.openapi(
|
|||||||
request: {
|
request: {
|
||||||
body: {
|
body: {
|
||||||
content: {
|
content: {
|
||||||
"application/json": {schema: AddModule},
|
"application/json": { schema: AddModule },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
responses: {
|
responses: {
|
||||||
200: {
|
200: {
|
||||||
content: {
|
content: {
|
||||||
"application/json": {schema: responseSchema},
|
"application/json": { schema: responseSchema },
|
||||||
},
|
},
|
||||||
description: "Response message",
|
description: "Response message",
|
||||||
},
|
},
|
||||||
400: {
|
400: {
|
||||||
content: {
|
content: {
|
||||||
"application/json": {
|
"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",
|
description: "Internal Server Error",
|
||||||
@@ -64,7 +76,12 @@ app.openapi(
|
|||||||
401: {
|
401: {
|
||||||
content: {
|
content: {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
schema: z.object({message: z.string().optional().openapi({example: "Unauthenticated"})}),
|
schema: z.object({
|
||||||
|
message: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.openapi({ example: "Unauthenticated" }),
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
description: "Unauthorized",
|
description: "Unauthorized",
|
||||||
@@ -72,7 +89,12 @@ app.openapi(
|
|||||||
500: {
|
500: {
|
||||||
content: {
|
content: {
|
||||||
"application/json": {
|
"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",
|
description: "Internal Server Error",
|
||||||
@@ -92,16 +114,26 @@ app.openapi(
|
|||||||
const payload = await verify(token, process.env.JWT_SECRET!);
|
const payload = await verify(token, process.env.JWT_SECRET!);
|
||||||
user = payload.user as User;
|
user = payload.user as User;
|
||||||
} catch (error) {
|
} 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
|
// now pass all the data over to update the user info
|
||||||
try {
|
try {
|
||||||
const data = await c?.req.json();
|
const data = await c?.req.json();
|
||||||
|
apiHit(c, { endpoint: `/modules`, lastBody: data });
|
||||||
await addModule(data, user.user_id ?? "");
|
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) {
|
} 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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
|
|||||||
import { modules } from "../../../../../database/schema/modules.js";
|
import { modules } from "../../../../../database/schema/modules.js";
|
||||||
import { db } from "../../../../../database/dbclient.js";
|
import { db } from "../../../../../database/dbclient.js";
|
||||||
import { desc } from "drizzle-orm";
|
import { desc } from "drizzle-orm";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
// Define the request body schema
|
// Define the request body schema
|
||||||
const requestSchema = z.object({
|
const requestSchema = z.object({
|
||||||
@@ -45,6 +46,7 @@ app.openapi(
|
|||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
//console.log("system modules");
|
//console.log("system modules");
|
||||||
|
apiHit(c, { endpoint: `/getmodules`, action: "just modules" });
|
||||||
let module: any = [];
|
let module: any = [];
|
||||||
try {
|
try {
|
||||||
module = await db.select().from(modules).orderBy(modules.name); // .where(eq(modules.active, true));
|
module = await db.select().from(modules).orderBy(modules.name); // .where(eq(modules.active, true));
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
|
|||||||
import { modules } from "../../../../../database/schema/modules.js";
|
import { modules } from "../../../../../database/schema/modules.js";
|
||||||
import { db } from "../../../../../database/dbclient.js";
|
import { db } from "../../../../../database/dbclient.js";
|
||||||
import { subModules } from "../../../../../database/schema/subModules.js";
|
import { subModules } from "../../../../../database/schema/subModules.js";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
// Define the request body schema
|
// Define the request body schema
|
||||||
const requestSchema = z.object({
|
const requestSchema = z.object({
|
||||||
@@ -45,6 +46,7 @@ app.openapi(
|
|||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
//console.log("system modules");
|
//console.log("system modules");
|
||||||
|
apiHit(c, { endpoint: `/submodules` });
|
||||||
let module: any = [];
|
let module: any = [];
|
||||||
try {
|
try {
|
||||||
module = await db
|
module = await db
|
||||||
|
|||||||
@@ -1,16 +1,23 @@
|
|||||||
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
|
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
|
||||||
import type {User} from "../../../../types/users.js";
|
import type { User } from "../../../../types/users.js";
|
||||||
import {verify} from "hono/jwt";
|
import { verify } from "hono/jwt";
|
||||||
import {updateModule} from "../../controller/module/updateModule.js";
|
import { updateModule } from "../../controller/module/updateModule.js";
|
||||||
import {authMiddleware} from "../../../auth/middleware/authMiddleware.js";
|
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
// Define the response schema
|
// Define the response schema
|
||||||
const responseSchema = z.object({
|
const responseSchema = z.object({
|
||||||
message: z.string().optional(),
|
message: z.string().optional(),
|
||||||
module_id: z.string().openapi({example: "6c922c6c-7de3-4ec4-acb0-f068abdc"}).optional(),
|
module_id: z
|
||||||
name: z.string().openapi({example: "Production"}).optional(),
|
.string()
|
||||||
active: z.boolean().openapi({example: true}).optional(),
|
.openapi({ example: "6c922c6c-7de3-4ec4-acb0-f068abdc" })
|
||||||
roles: z.string().openapi({example: `["viewer","technician"]`}).optional(),
|
.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 app = new OpenAPIHono();
|
||||||
@@ -41,14 +48,19 @@ app.openapi(
|
|||||||
responses: {
|
responses: {
|
||||||
200: {
|
200: {
|
||||||
content: {
|
content: {
|
||||||
"application/json": {schema: responseSchema},
|
"application/json": { schema: responseSchema },
|
||||||
},
|
},
|
||||||
description: "Response message",
|
description: "Response message",
|
||||||
},
|
},
|
||||||
400: {
|
400: {
|
||||||
content: {
|
content: {
|
||||||
"application/json": {
|
"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",
|
description: "Internal Server Error",
|
||||||
@@ -56,7 +68,12 @@ app.openapi(
|
|||||||
401: {
|
401: {
|
||||||
content: {
|
content: {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
schema: z.object({message: z.string().optional().openapi({example: "Unauthenticated"})}),
|
schema: z.object({
|
||||||
|
message: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.openapi({ example: "Unauthenticated" }),
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
description: "Unauthorized",
|
description: "Unauthorized",
|
||||||
@@ -64,7 +81,12 @@ app.openapi(
|
|||||||
500: {
|
500: {
|
||||||
content: {
|
content: {
|
||||||
"application/json": {
|
"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",
|
description: "Internal Server Error",
|
||||||
@@ -72,7 +94,7 @@ app.openapi(
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
async (c) => {
|
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
|
// make sure we have a vaid user being accessed thats really logged in
|
||||||
const authHeader = c.req.header("Authorization");
|
const authHeader = c.req.header("Authorization");
|
||||||
@@ -84,16 +106,30 @@ app.openapi(
|
|||||||
const payload = await verify(token, process.env.JWT_SECRET!);
|
const payload = await verify(token, process.env.JWT_SECRET!);
|
||||||
user = payload.user as User;
|
user = payload.user as User;
|
||||||
} catch (error) {
|
} 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
|
// now pass all the data over to update the user info
|
||||||
try {
|
try {
|
||||||
const data = await c?.req.json();
|
const data = await c?.req.json();
|
||||||
|
apiHit(c, {
|
||||||
|
endpoint: `/modules/${id}`,
|
||||||
|
action: "just update modules",
|
||||||
|
lastBody: data,
|
||||||
|
});
|
||||||
await updateModule(data, id ?? "");
|
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) {
|
} 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({
|
return c.json({
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { verify } from "hono/jwt";
|
|||||||
|
|
||||||
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
||||||
import { updateSubModule } from "../../controller/module/updateSubModule.js";
|
import { updateSubModule } from "../../controller/module/updateSubModule.js";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
// Define the response schema
|
// Define the response schema
|
||||||
const responseSchema = z.object({
|
const responseSchema = z.object({
|
||||||
@@ -112,6 +113,11 @@ app.openapi(
|
|||||||
// now pass all the data over to update the user info
|
// now pass all the data over to update the user info
|
||||||
try {
|
try {
|
||||||
const data = await c?.req.json();
|
const data = await c?.req.json();
|
||||||
|
apiHit(c, {
|
||||||
|
endpoint: `/submodules/${id}`,
|
||||||
|
action: "just updates submodules",
|
||||||
|
lastBody: data,
|
||||||
|
});
|
||||||
await updateSubModule(data, id ?? "");
|
await updateSubModule(data, id ?? "");
|
||||||
return c.json({ success: true, message: "Module Updated" }, 200);
|
return c.json({ success: true, message: "Module Updated" }, 200);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
|
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
|
||||||
import {db} from "../../../../../database/dbclient.js";
|
import { db } from "../../../../../database/dbclient.js";
|
||||||
import {authMiddleware} from "../../../auth/middleware/authMiddleware.js";
|
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
||||||
import {serverData} from "../../../../../database/schema/serverData.js";
|
import { serverData } from "../../../../../database/schema/serverData.js";
|
||||||
import {eq} from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
// Define the request body schema
|
// Define the request body schema
|
||||||
const requestSchema = z.object({
|
const requestSchema = z.object({
|
||||||
@@ -15,10 +16,16 @@ const requestSchema = z.object({
|
|||||||
// Define the response schema
|
// Define the response schema
|
||||||
const responseSchema = z.object({
|
const responseSchema = z.object({
|
||||||
message: z.string().optional(),
|
message: z.string().optional(),
|
||||||
module_id: z.string().openapi({example: "6c922c6c-7de3-4ec4-acb0-f068abdc"}).optional(),
|
module_id: z
|
||||||
name: z.string().openapi({example: "Production"}).optional(),
|
.string()
|
||||||
active: z.boolean().openapi({example: true}).optional(),
|
.openapi({ example: "6c922c6c-7de3-4ec4-acb0-f068abdc" })
|
||||||
roles: z.string().openapi({example: `["viewer","technician"]`}).optional(),
|
.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 app = new OpenAPIHono();
|
||||||
@@ -33,7 +40,7 @@ app.openapi(
|
|||||||
responses: {
|
responses: {
|
||||||
200: {
|
200: {
|
||||||
content: {
|
content: {
|
||||||
"application/json": {schema: responseSchema},
|
"application/json": { schema: responseSchema },
|
||||||
},
|
},
|
||||||
description: "Response message",
|
description: "Response message",
|
||||||
},
|
},
|
||||||
@@ -41,16 +48,22 @@ app.openapi(
|
|||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
//console.log("system modules");
|
//console.log("system modules");
|
||||||
|
apiHit(c, { endpoint: `/servers` });
|
||||||
let servers: any = [];
|
let servers: any = [];
|
||||||
try {
|
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) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
servers = [];
|
servers = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// sort the servers by there name
|
// 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
|
// Return response with the received data
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
|||||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
import hasCorrectRole from "../../../auth/middleware/roleCheck.js";
|
import hasCorrectRole from "../../../auth/middleware/roleCheck.js";
|
||||||
import { serviceControl } from "../../controller/server/serviceControl.js";
|
import { serviceControl } from "../../controller/server/serviceControl.js";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
// Define the request body schema
|
// Define the request body schema
|
||||||
const requestSchema = z.object({
|
const requestSchema = z.object({
|
||||||
@@ -33,7 +34,7 @@ app.openapi(
|
|||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
const { data, error } = await tryCatch(c.req.json());
|
const { data, error } = await tryCatch(c.req.json());
|
||||||
|
//apiHit(c, { endpoint: `/serviceprocess`, lastBody: data });
|
||||||
if (error) {
|
if (error) {
|
||||||
return c.json({
|
return c.json({
|
||||||
success: false,
|
success: false,
|
||||||
|
|||||||
@@ -1,19 +1,22 @@
|
|||||||
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
|
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||||
import {addSetting} from "../../controller/settings/addSetting.js";
|
import { addSetting } from "../../controller/settings/addSetting.js";
|
||||||
|
|
||||||
import {verify} from "hono/jwt";
|
import { verify } from "hono/jwt";
|
||||||
import type {User} from "../../../../types/users.js";
|
import type { User } from "../../../../types/users.js";
|
||||||
import {authMiddleware} from "../../../auth/middleware/authMiddleware.js";
|
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
|
||||||
import {responses} from "../../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
const AddSetting = z.object({
|
const AddSetting = z.object({
|
||||||
name: z.string().openapi({example: "server"}),
|
name: z.string().openapi({ example: "server" }),
|
||||||
value: z.string().openapi({example: "localhost"}),
|
value: z.string().openapi({ example: "localhost" }),
|
||||||
description: z.string().openapi({example: "The server we are going to connect to"}),
|
description: z
|
||||||
roles: z.string().openapi({example: "admin"}),
|
.string()
|
||||||
module: z.string().openapi({example: "production"}),
|
.openapi({ example: "The server we are going to connect to" }),
|
||||||
|
roles: z.string().openapi({ example: "admin" }),
|
||||||
|
module: z.string().openapi({ example: "production" }),
|
||||||
});
|
});
|
||||||
|
|
||||||
app.openapi(
|
app.openapi(
|
||||||
@@ -26,7 +29,7 @@ app.openapi(
|
|||||||
request: {
|
request: {
|
||||||
body: {
|
body: {
|
||||||
content: {
|
content: {
|
||||||
"application/json": {schema: AddSetting},
|
"application/json": { schema: AddSetting },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -43,16 +46,26 @@ app.openapi(
|
|||||||
const payload = await verify(token, process.env.JWT_SECRET!);
|
const payload = await verify(token, process.env.JWT_SECRET!);
|
||||||
user = payload.user as User;
|
user = payload.user as User;
|
||||||
} catch (error) {
|
} 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
|
// now pass all the data over to update the user info
|
||||||
try {
|
try {
|
||||||
const data = await c?.req.json();
|
const data = await c?.req.json();
|
||||||
|
apiHit(c, { endpoint: `/addsettings`, lastBody: data });
|
||||||
await addSetting(data, user.user_id ?? "");
|
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) {
|
} 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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -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 type { User } from "../../../../types/users.js";
|
||||||
import {verify} from "hono/jwt";
|
import { verify } from "hono/jwt";
|
||||||
import {getSettings} from "../../controller/settings/getSettings.js";
|
import { getSettings } from "../../controller/settings/getSettings.js";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
@@ -17,8 +18,8 @@ app.openapi(
|
|||||||
content: {
|
content: {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
schema: z.object({
|
schema: z.object({
|
||||||
success: z.boolean().openapi({example: true}),
|
success: z.boolean().openapi({ example: true }),
|
||||||
message: z.string().openapi({example: "Starter"}),
|
message: z.string().openapi({ example: "Starter" }),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -27,7 +28,12 @@ app.openapi(
|
|||||||
400: {
|
400: {
|
||||||
content: {
|
content: {
|
||||||
"application/json": {
|
"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",
|
description: "Internal Server Error",
|
||||||
@@ -35,7 +41,12 @@ app.openapi(
|
|||||||
401: {
|
401: {
|
||||||
content: {
|
content: {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
schema: z.object({message: z.string().optional().openapi({example: "Unauthenticated"})}),
|
schema: z.object({
|
||||||
|
message: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.openapi({ example: "Unauthenticated" }),
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
description: "Unauthorized",
|
description: "Unauthorized",
|
||||||
@@ -43,7 +54,12 @@ app.openapi(
|
|||||||
500: {
|
500: {
|
||||||
content: {
|
content: {
|
||||||
"application/json": {
|
"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",
|
description: "Internal Server Error",
|
||||||
@@ -52,13 +68,19 @@ app.openapi(
|
|||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
// make sure we have a vaid user being accessed thats really logged in
|
// 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
|
// now pass all the data over to update the user info
|
||||||
try {
|
try {
|
||||||
const data = await getSettings();
|
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) {
|
} 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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
|
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||||
import type {User} from "../../../../types/users.js";
|
import type { User } from "../../../../types/users.js";
|
||||||
import {verify} from "hono/jwt";
|
import { verify } from "hono/jwt";
|
||||||
import {updateSetting} from "../../controller/settings/updateSetting.js";
|
import { updateSetting } from "../../controller/settings/updateSetting.js";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
const UpdateSetting = z.object({
|
const UpdateSetting = z.object({
|
||||||
name: z.string().openapi({example: "server"}),
|
name: z.string().openapi({ example: "server" }),
|
||||||
value: z.string().openapi({example: "localhost"}),
|
value: z.string().openapi({ example: "localhost" }),
|
||||||
});
|
});
|
||||||
|
|
||||||
app.openapi(
|
app.openapi(
|
||||||
@@ -19,7 +20,7 @@ app.openapi(
|
|||||||
request: {
|
request: {
|
||||||
body: {
|
body: {
|
||||||
content: {
|
content: {
|
||||||
"application/json": {schema: UpdateSetting},
|
"application/json": { schema: UpdateSetting },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -28,8 +29,8 @@ app.openapi(
|
|||||||
content: {
|
content: {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
schema: z.object({
|
schema: z.object({
|
||||||
success: z.boolean().openapi({example: true}),
|
success: z.boolean().openapi({ example: true }),
|
||||||
message: z.string().openapi({example: "Starter"}),
|
message: z.string().openapi({ example: "Starter" }),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -38,7 +39,12 @@ app.openapi(
|
|||||||
400: {
|
400: {
|
||||||
content: {
|
content: {
|
||||||
"application/json": {
|
"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",
|
description: "Internal Server Error",
|
||||||
@@ -46,7 +52,12 @@ app.openapi(
|
|||||||
401: {
|
401: {
|
||||||
content: {
|
content: {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
schema: z.object({message: z.string().optional().openapi({example: "Unauthenticated"})}),
|
schema: z.object({
|
||||||
|
message: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.openapi({ example: "Unauthenticated" }),
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
description: "Unauthorized",
|
description: "Unauthorized",
|
||||||
@@ -54,7 +65,12 @@ app.openapi(
|
|||||||
500: {
|
500: {
|
||||||
content: {
|
content: {
|
||||||
"application/json": {
|
"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",
|
description: "Internal Server Error",
|
||||||
@@ -66,11 +82,17 @@ app.openapi(
|
|||||||
const authHeader = c.req.header("Authorization");
|
const authHeader = c.req.header("Authorization");
|
||||||
|
|
||||||
if (authHeader?.includes("Basic")) {
|
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) {
|
if (!authHeader) {
|
||||||
return c.json({message: "Unauthorized"}, 401);
|
return c.json({ message: "Unauthorized" }, 401);
|
||||||
}
|
}
|
||||||
|
|
||||||
const token = authHeader?.split("Bearer ")[1] || "";
|
const token = authHeader?.split("Bearer ")[1] || "";
|
||||||
@@ -80,16 +102,27 @@ app.openapi(
|
|||||||
const payload = await verify(token, process.env.JWT_SECRET!);
|
const payload = await verify(token, process.env.JWT_SECRET!);
|
||||||
user = payload.user as User;
|
user = payload.user as User;
|
||||||
} catch (error) {
|
} 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
|
// now pass all the data over to update the user info
|
||||||
try {
|
try {
|
||||||
const data = await c?.req.json();
|
const data = await c?.req.json();
|
||||||
|
apiHit(c, { endpoint: `/updatesettings`, lastBody: data });
|
||||||
await updateSetting(data, user.user_id ?? "");
|
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) {
|
} 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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
processAllServers,
|
processAllServers,
|
||||||
updateServer,
|
updateServer,
|
||||||
} from "../../../../scripts/updateServers.js";
|
} from "../../../../scripts/updateServers.js";
|
||||||
|
import { apiHit } from "../../../../globalUtils/apiHits.js";
|
||||||
|
|
||||||
// Define the request body schema
|
// Define the request body schema
|
||||||
const requestSchema = z.object({
|
const requestSchema = z.object({
|
||||||
@@ -80,7 +81,7 @@ app.openapi(
|
|||||||
async (c) => {
|
async (c) => {
|
||||||
const { server } = c.req.valid("param");
|
const { server } = c.req.valid("param");
|
||||||
const body = await c.req.json();
|
const body = await c.req.json();
|
||||||
|
apiHit(c, { endpoint: `/update/${server}`, lastBody: body });
|
||||||
// fire off the update we wont make this way
|
// fire off the update we wont make this way
|
||||||
if (body.all) {
|
if (body.all) {
|
||||||
const update = await processAllServers(body.devDir);
|
const update = await processAllServers(body.devDir);
|
||||||
|
|||||||
Reference in New Issue
Block a user