-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
634bbb0
commit 590f0ac
Showing
3 changed files
with
30 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { NextFunction } from "express"; | ||
import { AuthenticatedRequest } from "../../.."; | ||
import { Request, Response } from 'express'; | ||
import { Roles } from "../../enums/Roles"; | ||
import Animal from "../../database/models/Animal"; | ||
|
||
export default function CheckAclAnimalsPermission(role: Roles) { | ||
return async function (req: Request, res: Response, next: NextFunction) { | ||
const authenticatedRequest = req as unknown as AuthenticatedRequest; | ||
const { userRoles } = authenticatedRequest.user!; | ||
const id = req.params.id || req.body.id; | ||
|
||
const animal = await Animal.findByPk(id); | ||
if (userRoles.some(x => | ||
x.idRole && x.idRole >= role && | ||
x.idInstitution?.toString() === animal?.idInstitution | ||
)) { | ||
return next(); | ||
} | ||
|
||
return res.status(401).json({ message: 'Not allowed profile!' }); | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters