refactor(ocme): clean up on the getInfo endpoint
This commit is contained in:
@@ -1,80 +1,36 @@
|
|||||||
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
|
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||||
import {getInfo} from "../controller/getInfo.js";
|
import { getInfo } from "../controller/getInfo.js";
|
||||||
import {apiHit} from "../../../globalUtils/apiHits.js";
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
|
import { responses } from "../../../globalUtils/routeDefs/responses.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"}),
|
|
||||||
});
|
|
||||||
|
|
||||||
app.openapi(
|
app.openapi(
|
||||||
createRoute({
|
createRoute({
|
||||||
tags: ["ocme"],
|
tags: ["ocme"],
|
||||||
summary: "Get all current info",
|
summary: "Get all current info",
|
||||||
method: "get",
|
method: "get",
|
||||||
path: "/getinfo",
|
path: "/getInfo",
|
||||||
request: {
|
|
||||||
body: {
|
responses: responses(),
|
||||||
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",
|
|
||||||
// },
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
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: "api/auth/register" });
|
||||||
try {
|
try {
|
||||||
return c.json({success: true, message: "Ocme Info", data: await getInfo()}, 200);
|
return c.json(
|
||||||
|
{ success: true, message: "Ocme Info", data: await getInfo() },
|
||||||
|
200
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return c.json({success: false, message: "There was an error getting ocmeInfo data", data: error}, 400);
|
return c.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: "There was an error getting ocmeInfo data",
|
||||||
|
data: error,
|
||||||
|
},
|
||||||
|
400
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user