refactor: use helper function
This commit is contained in:
parent
7b002451c3
commit
0570956850
1 changed files with 3 additions and 16 deletions
|
|
@ -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 },
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue