-
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.
* feat : add preparator user * fix eslint compliance * update: change order splitting method (now by needsPreparation) * Update src/controllers/order/create.ts Co-authored-by: Zalko <88582103+Zalk0@users.noreply.github.com> --------- Co-authored-by: Zalko <88582103+Zalk0@users.noreply.github.com>
- Loading branch information
Showing
6 changed files
with
40 additions
and
4 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Response, NextFunction, Request } from 'express'; | ||
import jwt from 'jsonwebtoken'; | ||
import getToken from '../utils/getToken'; | ||
import { Token, Permission } from '../types'; | ||
import { unauthorized, unauthenticated } from '../utils/responses'; | ||
import errorHandler from '../utils/errorHandler'; | ||
|
||
export default (permissions: Array<string>) => async (req: Request, res: Response, next: NextFunction) => { | ||
try { | ||
const token = getToken(req); | ||
if (token) { | ||
const decoded = jwt.verify(token, process.env.APP_TOKEN_SECRET) as Token; | ||
|
||
req.user = decoded; | ||
|
||
if (!permissions) { | ||
return next(); | ||
} | ||
|
||
if (decoded.permissions === Permission.ADMIN) { | ||
return next(); | ||
} | ||
|
||
const hasPermission: boolean = permissions.some((perm) => perm === decoded.permissions) | ||
if (hasPermission) return next(); | ||
return unauthorized(res); | ||
} | ||
|
||
return unauthenticated(res); | ||
} catch (err) { | ||
return errorHandler(res, err); | ||
} | ||
}; |
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