refactor: use helper function

This commit is contained in:
Methapon Metanipat 2024-09-12 09:06:12 +07:00
parent 7b002451c3
commit 0570956850

View file

@ -280,25 +280,12 @@ export class BranchUserController extends Controller {
@Path() userId: string, @Path() userId: string,
) { ) {
const branch = await prisma.branch.findUnique({ const branch = await prisma.branch.findUnique({
include: { include: branchRelationPermInclude(req.user),
user: {
where: { userId: req.user.sub },
},
},
where: { id: branchId }, where: { id: branchId },
}); });
if ( await permissionCheck(req.user, branch);
!globalAllow(req.user) &&
branch?.createdByUserId !== req.user.sub &&
!branch?.user.find((v) => v.userId === req.user.sub)
) {
throw new HttpError(
HttpStatus.FORBIDDEN,
"You do not have permission to perform this action.",
"noPermission",
);
}
await prisma.branchUser.deleteMany({ await prisma.branchUser.deleteMany({
where: { branchId, userId }, where: { branchId, userId },
}); });