@galeh/chuka 1.0.10 → 1.0.12
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
|
+
intercepted = this.middleware(
|
|
48
|
+
createLogger()
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
postCat = this.intercepted.middleware(
|
|
52
|
+
bodyValidator<CatModel>({
|
|
53
|
+
name: and(isDefined(), isString()),
|
|
54
|
+
country: isNumber(),
|
|
55
|
+
age: custom(model => Promise.resolve(!!(model.age && model.age > 2))),
|
|
56
|
+
parents: {
|
|
57
|
+
name: isString(),
|
|
58
|
+
parents: {
|
|
59
|
+
country: isString(),
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
).post('/', async (req, res) => {{
|
|
64
|
+
const allcats = await this.service.add(req.body.name);
|
|
65
|
+
res.send(allcats);
|
|
66
|
+
}});
|
|
67
|
+
|
|
68
|
+
getAllCats = this.intercepted.get('/', async (req, res) => {{
|
|
69
|
+
const allcats = await this.service.findAll();
|
|
70
|
+
res.send(allcats);
|
|
71
|
+
}});
|
|
72
|
+
|
|
73
|
+
getCatById = this.intercepted.get('/:id', async (req, res) => {
|
|
74
|
+
const onecat = await this.service.findOne(+req.params.id);
|
|
75
|
+
res.send(onecat);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
constructor(@inject('catservice') private service: CatsServiceInterface) {
|
|
79
|
+
super();
|
|
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
|
|