damex 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -15
- package/package.json +1 -1
package/README.md
CHANGED
@@ -14,6 +14,12 @@ Receives a string indicating the route of the controller.
|
|
14
14
|
|
15
15
|
Receives an array with all the middleware methods that will be applied to all the methods of the controller.
|
16
16
|
|
17
|
+
|
18
|
+
```typescript
|
19
|
+
@Inject
|
20
|
+
```
|
21
|
+
Used on classes that required DI. If the class Already has a decorator (as @Controller), the @Inject is not required.
|
22
|
+
|
17
23
|
### Used in Methods
|
18
24
|
|
19
25
|
```typescript
|
@@ -31,29 +37,22 @@ Receives an array with all the middleware methods that will be applied to all th
|
|
31
37
|
@Controller('/users')
|
32
38
|
@GlobalMiddleware([auth])
|
33
39
|
export class UsersController {
|
34
|
-
constructor() {}
|
40
|
+
constructor(private userService: UserService) {}
|
35
41
|
|
36
42
|
@Get()
|
37
43
|
@Middleware([logger])
|
38
|
-
getAll(req: Request, res: Response) {
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
]);
|
44
|
+
async getAll(req: Request, res: Response) {
|
45
|
+
const users = await this.userService.all()
|
46
|
+
|
47
|
+
res.status(200).send(users);
|
43
48
|
}
|
44
49
|
|
45
50
|
@Get('/:id')
|
46
51
|
@Middleware([anotherLogger])
|
47
|
-
getById(req: Request, res: Response) {
|
48
|
-
|
52
|
+
async getById(req: Request, res: Response) {
|
53
|
+
const users = await this.userService.findById(req.params.id!)
|
49
54
|
|
50
|
-
res.status(200).send(
|
51
|
-
{ id: 1, user: 'admin' },
|
52
|
-
{ id: 2, user: 'default' },
|
53
|
-
]);
|
55
|
+
res.status(200).send(users);
|
54
56
|
}
|
55
57
|
}
|
56
58
|
```
|
57
|
-
|
58
|
-
# Warning!
|
59
|
-
This package doesn't work with dependency injection for now. Because of this, and due to the way the routes are implemented, all services used inside controllers or other services must implement as static methods.
|