44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
// an external way to creating logs
|
|
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
|
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
|
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
|
import { prodUser } from "../controller/produser.js";
|
|
|
|
const app = new OpenAPIHono({ strict: false });
|
|
|
|
app.openapi(
|
|
createRoute({
|
|
tags: ["admin"],
|
|
summary: "Creates a new prod role",
|
|
method: "post",
|
|
path: "/prodrole",
|
|
responses: responses(),
|
|
}),
|
|
async (c) => {
|
|
const { data: body, error: be } = await tryCatch(c.req.json());
|
|
|
|
if (be) {
|
|
return c.json({
|
|
success: false,
|
|
message: "Missing data.",
|
|
});
|
|
}
|
|
const { data, error } = await tryCatch(prodUser(body));
|
|
apiHit(c, { endpoint: "/prodrole" });
|
|
if (error) {
|
|
return c.json({
|
|
success: false,
|
|
message: "Error creating new role.",
|
|
});
|
|
}
|
|
|
|
return c.json({
|
|
success: data.succes,
|
|
message: data.message,
|
|
data: data.data,
|
|
});
|
|
}
|
|
);
|
|
export default app;
|