🚩 (user) create soft delete controller boilerplate

create basic boilerplate for soft delete user including make middleware that only admin and owner can access
This commit is contained in:
2025-07-06 23:40:05 +07:00
parent 2b2776307b
commit 2fe34034a5
3 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,26 @@
import { Context } from "elysia";
import { getCookie } from "../../helpers/http/userHeader/cookies/getCookies";
import { jwtDecode } from "../../helpers/http/jwt/decode";
import { returnErrorResponse } from "../../helpers/callback/httpResponse";
import { mainErrorHandler } from "../../helpers/error/handler";
export const isOwnerOrAdminMiddleware = (ctx: Context) => {
try {
const clientCookie = getCookie(ctx);
const clientToken = jwtDecode(clientCookie.auth_token!);
const clientUsername = clientToken.user.username;
// const isClientAdmin = clientToken.user.username
const targetUsername = ctx.params.username;
if (targetUsername !== clientUsername)
return returnErrorResponse(
ctx.set,
401,
"You don't have access to this resource"
);
// Pass
} catch (error) {
return mainErrorHandler(ctx.set, error);
}
};