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,
) {
const branch = await prisma.branch.findUnique({
include: {
user: {
where: { userId: req.user.sub },
},
},
include: branchRelationPermInclude(req.user),
where: { id: branchId },
});
if (
!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 permissionCheck(req.user, branch);
await prisma.branchUser.deleteMany({
where: { branchId, userId },
});