feat(rfid): front end view of the readers and there status

This commit is contained in:
2025-07-10 21:29:01 -05:00
parent 6584b37cb0
commit f7b4de8130
15 changed files with 533 additions and 36 deletions

View File

@@ -1,23 +1,43 @@
import type { Context } from "hono";
import { createLog } from "../../services/logger/logger.js";
export type ReturnRes<T> =
| { success: true; message: string; data: T }
| { success: false; message: string; error: any };
export function returnRes<T>(
success: true,
message: string,
service: string,
user: string,
level: "info" | "error",
data: T
): { success: true; message: string; data: T };
export const returnRes = <T>(
success: boolean,
message: string,
data: T | null = null
): ReturnRes<T> => {
/**
* 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 success
? { success, message, data: data as T }
: { success, message, error: data ?? "An unknown error occurred" };
};
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)=>{
// /**