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,
|
@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 },
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue