feat(lstv2 move): moved lstv2 into this app to keep them combined and easier to maintain
This commit is contained in:
8
lstV2/server/globalUtils/routeDefs/options.ts
Normal file
8
lstV2/server/globalUtils/routeDefs/options.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
export const apiOptions = () => {
|
||||
return {
|
||||
tags: ["rfid"],
|
||||
summary: "Add new reader",
|
||||
method: "post",
|
||||
path: "/addreader",
|
||||
};
|
||||
};
|
||||
45
lstV2/server/globalUtils/routeDefs/responses.ts
Normal file
45
lstV2/server/globalUtils/routeDefs/responses.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import {z} from "@hono/zod-openapi";
|
||||
|
||||
const responseSchema = z.object({
|
||||
success: z.boolean().openapi({example: true}),
|
||||
message: z.string().optional(),
|
||||
data: z
|
||||
.array(z.object({}).optional())
|
||||
.optional()
|
||||
.openapi({example: [{data: "hi"}]}),
|
||||
});
|
||||
|
||||
export const responses = () => {
|
||||
return {
|
||||
200: {
|
||||
content: {
|
||||
"application/json": {schema: responseSchema},
|
||||
},
|
||||
description: "Response message",
|
||||
},
|
||||
400: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({message: z.string().optional().openapi({example: "Internal Server error"})}),
|
||||
},
|
||||
},
|
||||
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",
|
||||
},
|
||||
};
|
||||
};
|
||||
49
lstV2/server/globalUtils/routeDefs/returnRes.ts
Normal file
49
lstV2/server/globalUtils/routeDefs/returnRes.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { createLog } from "../../services/logger/logger.js";
|
||||
|
||||
export function returnRes<T>(
|
||||
success: true,
|
||||
message: string,
|
||||
service: string,
|
||||
user: string,
|
||||
level: "info" | "error",
|
||||
data: T
|
||||
): { success: true; message: string; data: T };
|
||||
|
||||
export function returnRes<T>(
|
||||
success: false,
|
||||
message: string,
|
||||
service: string,
|
||||
user: string,
|
||||
level: "info" | "error",
|
||||
data?: T
|
||||
): { success: false; message: string; error: T | string };
|
||||
|
||||
export function returnRes<T>(
|
||||
success: boolean,
|
||||
message: string,
|
||||
service: string,
|
||||
user: string,
|
||||
level: "info" | "error",
|
||||
data?: T
|
||||
) {
|
||||
createLog(level, user, service, message);
|
||||
|
||||
if (success) {
|
||||
return { success: true, message, data: data as T };
|
||||
} else {
|
||||
return {
|
||||
success: false,
|
||||
message,
|
||||
error: data ?? "An unknown error occurred",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// export const returnApi = (c:Context,success: boolean, message: string, data?: any, code: number)=>{
|
||||
// /**
|
||||
// * just a simple return to reduce the typing and make sure we are always consitant with our returns.
|
||||
// *
|
||||
// * data can be an error as well.
|
||||
// */
|
||||
// return c.json({success, message, data}, code);
|
||||
// }
|
||||
Reference in New Issue
Block a user