Files

45 lines
1.3 KiB
TypeScript

import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
import {apiHit} from "../../../globalUtils/apiHits.js";
import {responses} from "../../../globalUtils/routeDefs/responses.js";
import {clearLog} from "../controller/clearLog.js";
const app = new OpenAPIHono({strict: false});
const ParamsSchema = z.object({
id: z
.string()
.min(3)
.openapi({
param: {
name: "id",
in: "path",
},
example: "1212121",
}),
});
app.openapi(
createRoute({
tags: ["server:logger"],
summary: "Marks the select log id as cleared out.",
method: "patch",
path: "/logs/{id}",
request: {
params: ParamsSchema,
},
responses: responses(),
}),
async (c) => {
const {id} = c.req.valid("param");
//const body = await c.req.json();
// make sure we have a vaid user being accessed thats really logged in
apiHit(c, {endpoint: `api/logger/logs/id`});
try {
const clear = await clearLog(id);
return c.json({success: clear.success, message: clear.message, data: []}, 200);
} catch (error) {
return c.json({success: false, message: "There was an error clearing the log.", data: error}, 400);
}
}
);
export default app;