test(ocme): lots of changes to get it working in production

This commit is contained in:
2025-03-24 15:31:31 -05:00
parent 0c5fc1dfb0
commit 6dd9ed848b
14 changed files with 957 additions and 779 deletions

View File

@@ -1,81 +1,96 @@
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
import {getInfo} from "../controller/getInfo.js";
import {apiHit} from "../../../globalUtils/apiHits.js";
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { getInfo } from "../controller/getInfo.js";
import { apiHit } from "../../../globalUtils/apiHits.js";
const app = new OpenAPIHono({strict: false});
const app = new OpenAPIHono({ strict: false });
const AddSetting = z.object({
name: z.string().openapi({example: "server"}),
value: z.string().openapi({example: "localhost"}),
description: z.string().openapi({example: "The server we are going to connect to"}),
roles: z.string().openapi({example: "admin"}),
module: z.string().openapi({example: "production"}),
name: z.string().openapi({ example: "server" }),
value: z.string().openapi({ example: "localhost" }),
description: z
.string()
.openapi({ example: "The server we are going to connect to" }),
roles: z.string().openapi({ example: "admin" }),
module: z.string().openapi({ example: "production" }),
});
app.openapi(
createRoute({
tags: ["ocme"],
summary: "Get all current info",
method: "get",
path: "/getinfo",
request: {
body: {
content: {
"application/json": {schema: AddSetting},
},
},
createRoute({
tags: ["ocme"],
summary: "Get all current info",
method: "get",
path: "/getInfo",
request: {
body: {
content: {
"application/json": { schema: AddSetting },
},
responses: {
200: {
content: {
"application/json": {
schema: z.object({
success: z.boolean().openapi({example: true}),
message: z.string().openapi({example: "Starter"}),
data: z.array(z.object({})).optional().openapi({example: []}),
}),
},
},
description: "Response message",
},
400: {
content: {
"application/json": {
schema: z.object({
success: z.boolean().openapi({example: false}),
message: z.string().optional().openapi({example: "Internal Server error"}),
data: z.array(z.object({})).optional().openapi({example: []}),
}),
},
},
description: "Internal Server Error",
},
// 401: {
// content: {
// "application/json": {
// schema: z.object({message: z.string().optional().openapi({example: "Unauthenticated"})}),
// },
// },
// description: "Unauthorized",
// },
// 500: {
// content: {
// "application/json": {
// schema: z.object({message: z.string().optional().openapi({example: "Internal Server error"})}),
// },
// },
// description: "Internal Server Error",
// },
},
},
responses: {
200: {
content: {
"application/json": {
schema: z.object({
success: z.boolean().openapi({ example: true }),
message: z.string().openapi({ example: "Starter" }),
data: z.array(z.object({})).optional().openapi({ example: [] }),
}),
},
},
}),
async (c) => {
// make sure we have a vaid user being accessed thats really logged in
apiHit(c, {endpoint: "api/auth/register"});
try {
return c.json({success: true, message: "Ocme Info", data: await getInfo()}, 200);
} catch (error) {
return c.json({success: false, message: "There was an error getting ocmeInfo data", data: error}, 400);
}
description: "Response message",
},
400: {
content: {
"application/json": {
schema: z.object({
success: z.boolean().openapi({ example: false }),
message: z
.string()
.optional()
.openapi({ example: "Internal Server error" }),
data: z.array(z.object({})).optional().openapi({ example: [] }),
}),
},
},
description: "Internal Server Error",
},
// 401: {
// content: {
// "application/json": {
// schema: z.object({message: z.string().optional().openapi({example: "Unauthenticated"})}),
// },
// },
// description: "Unauthorized",
// },
// 500: {
// content: {
// "application/json": {
// schema: z.object({message: z.string().optional().openapi({example: "Internal Server error"})}),
// },
// },
// description: "Internal Server Error",
// },
},
}),
async (c) => {
// make sure we have a vaid user being accessed thats really logged in
apiHit(c, { endpoint: "api/auth/register" });
try {
return c.json(
{ success: true, message: "Ocme Info", data: await getInfo() },
200
);
} catch (error) {
return c.json(
{
success: false,
message: "There was an error getting ocmeInfo data",
data: error,
},
400
);
}
}
);
export default app;