From b9f19095cbd86569b58bec99575d924db997e385 Mon Sep 17 00:00:00 2001 From: Blake Matthes Date: Tue, 25 Mar 2025 07:54:00 -0500 Subject: [PATCH] refactor(ocme): clean up on the getInfo endpoint --- server/services/ocme/route/getInfo.ts | 86 +++++++-------------------- 1 file changed, 21 insertions(+), 65 deletions(-) diff --git a/server/services/ocme/route/getInfo.ts b/server/services/ocme/route/getInfo.ts index a65b71d..35da0b4 100644 --- a/server/services/ocme/route/getInfo.ts +++ b/server/services/ocme/route/getInfo.ts @@ -1,80 +1,36 @@ -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"; +import { responses } from "../../../globalUtils/routeDefs/responses.js"; -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"}), -}); +const app = new OpenAPIHono({ strict: false }); app.openapi( 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", - // }, - }, + path: "/getInfo", + + responses: responses(), }), async (c) => { // 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 { - 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) { - 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 + ); } } );