a lot of things
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { ContentfulStatusCode } from "hono/utils/http-status";
|
||||
import { apiResponse } from "../../modules/api-utils/apiResponse";
|
||||
import { createRoute } from "../../modules/api-utils/createRoute";
|
||||
import { authMiddleware } from "../middleware/authorization";
|
||||
import { users } from "../../managers/users";
|
||||
import GenericError from "../../Errors/GenericError";
|
||||
|
||||
/* DELETE /v1/user/users/:identifier */
|
||||
export default createRoute(
|
||||
"delete",
|
||||
["/users/:identifier"],
|
||||
|
||||
async (c) => {
|
||||
const identifier = c.req.param("identifier");
|
||||
|
||||
const user = await users.fetchUser({ id: identifier });
|
||||
if (!user)
|
||||
throw new GenericError({
|
||||
name: "UserNotFound",
|
||||
message: `User with identifier '${identifier}' was not found.`,
|
||||
status: 404,
|
||||
});
|
||||
|
||||
const userData = user.toJson();
|
||||
await users.deleteUser(user.id);
|
||||
|
||||
const response = apiResponse.successful(
|
||||
"User Deleted Successfully!",
|
||||
userData,
|
||||
);
|
||||
return c.json(response, response.status as ContentfulStatusCode);
|
||||
},
|
||||
authMiddleware({ permissions: ["user.delete.other"] }),
|
||||
);
|
||||
Reference in New Issue
Block a user