Skip to content

Commit 5de58b5

Browse files
Sascha DobschalSascha Dobschal
authored andcommitted
destruct params
1 parent 4b8a245 commit 5de58b5

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

index.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
import routeLoader from "./src/routeLoader";
2+
import {NextFunction, Request, Response} from "express";
3+
4+
export interface RouteParams<BodyType> {
5+
req: Request,
6+
res: Response,
7+
next: NextFunction,
8+
body: BodyType,
9+
query: unknown,
10+
params: unknown,
11+
}
212

313
export {routeLoader};

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"Route Loader"
99
],
1010
"license": "ISC",
11-
"version": "1.1.1",
11+
"version": "1.2.1",
1212
"main": "index.js",
1313
"repository": {
1414
"type": "git",

src/routeLoader.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@ function routeLoader(pathToRoutes) {
2020
function _wrapRouteHandler(method) {
2121
return async (req, res, next) => {
2222
try {
23-
let response = method(req.body, req, res, next);
23+
let response = method({
24+
body: req.body,
25+
params: req.params,
26+
query: req.query,
27+
req,
28+
res,
29+
next
30+
});
2431
if (_isPromise(response)) {
2532
response = await response;
2633
}

tests/routes/testRouter.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ function get() {
1010
return "Yeah!";
1111
}
1212

13-
function post({message}) {
14-
return {message};
13+
function post({body}) {
14+
return {message: body.message};
1515
}
1616

17-
function put(body, req, res) {
17+
function put({res}) {
1818
res.send({worked: "yes"});
1919
}
2020

0 commit comments

Comments
 (0)