@galeh/chuka 1.0.10 → 1.0.11
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 +43 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,6 +37,49 @@ app.listen(8080, () => {
|
|
|
37
37
|
console.log('🚀 Running @galeh/chuka application on port 8080!');
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
// a typical controller
|
|
44
|
+
|
|
45
|
+
@injectable()
|
|
46
|
+
export class CatsController extends Controller {
|
|
47
|
+
constructor(@inject('catservice') service: CatsServiceInterface) {
|
|
48
|
+
super();
|
|
49
|
+
|
|
50
|
+
const intercepted = this.middleware(
|
|
51
|
+
createLogger()
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
intercepted.middleware(
|
|
55
|
+
bodyValidator<CatModel>({
|
|
56
|
+
name: and(isDefined(), isString()),
|
|
57
|
+
country: isNumber(),
|
|
58
|
+
age: custom(model => Promise.resolve(!!(model.age && model.age > 2))),
|
|
59
|
+
parents: {
|
|
60
|
+
name: isString(),
|
|
61
|
+
parents: {
|
|
62
|
+
country: isString(),
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
).post('/', async (req, res) => {{
|
|
67
|
+
const allcats = await service.add(req.body.name);
|
|
68
|
+
res.send(allcats);
|
|
69
|
+
}});
|
|
70
|
+
|
|
71
|
+
intercepted.get('/', async (req, res) => {{
|
|
72
|
+
const allcats = await service.findAll();
|
|
73
|
+
res.send(allcats);
|
|
74
|
+
}});
|
|
75
|
+
|
|
76
|
+
intercepted.get('/:id', async (req, res) => {
|
|
77
|
+
const onecat = await service.findOne(+req.params.id);
|
|
78
|
+
res.send(onecat);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
40
83
|
```
|
|
41
84
|
Explore the possibilities and experience a new level of Express.js development with [@galeh/chuka](https://www.npmjs.com/package/@galeh/chuka). 🌟
|
|
42
85
|
|