feat(produser): added the ability to add a prod user by default roles and update if already there
This commit is contained in:
43
server/services/prodUser/routes/addProdRole.ts
Normal file
43
server/services/prodUser/routes/addProdRole.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
// 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;
|
||||
45
server/services/prodUser/routes/produser.ts
Normal file
45
server/services/prodUser/routes/produser.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
// 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:
|
||||
"Runs a full crud on the user plus added icons if pc name provided and is online",
|
||||
method: "post",
|
||||
path: "/produser",
|
||||
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: "/newuser" });
|
||||
if (error) {
|
||||
console.log(error);
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "Error processing create user.",
|
||||
});
|
||||
}
|
||||
|
||||
return c.json({
|
||||
success: data.succes,
|
||||
message: data.message,
|
||||
data: data.data,
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
Reference in New Issue
Block a user