-
Notifications
You must be signed in to change notification settings - Fork 5
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
26d1863
commit f5526de
Showing
4 changed files
with
35 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ declare global { | |
namespace Express { | ||
interface Request { | ||
accessLevel?: number | ||
cost?: number | ||
} | ||
} | ||
} |
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,15 @@ | ||
import type { NextFunction, Request, Response } from 'express' | ||
|
||
/** | ||
* Middleware function to be used when defining API routes and pointing them to their internal functions | ||
* If not set, cost calculator after route completion will consider cost as 1 | ||
* | ||
* @param cost | ||
* @returns | ||
*/ | ||
export function setRouteCost(cost: number) { | ||
return (req: Request, _res: Response, next: NextFunction) => { | ||
req.cost = cost | ||
next() | ||
} | ||
} |