1
0
Fork 0

feat: add module auto check

Signed-off-by: MiaoWoo <admin@yumc.pw>
master
MiaoWoo 2019-06-20 18:25:48 +08:00
parent 5d8e818a5c
commit fd6c0e74cb
2 changed files with 12 additions and 5 deletions

View File

@ -2,6 +2,7 @@ import {
controller, response, requestBody, httpGet, httpPost, queryParam, requestParam
} from 'inversify-express-utils';
import { inject, postConstruct } from 'inversify';
import { Vaild, NotBlank, NotNull } from 'cc-server-binding'
import { DBClient } from 'cc-server-db'
import 'cc-server-db-mongo'
@ -10,10 +11,12 @@ import 'cc-server-db-mongo'
const TABLE = 'users'
interface ExampleModel {
class ExampleModel {
_id: string;
@NotBlank("用户名不得为空!")
username: string;
password: string;
@NotNull()
age: number;
email: string;
}
@ -44,9 +47,10 @@ export class Controller {
@httpPost('/')
public async create(
@requestBody() model: Model
): Promise<Model> {
return this.client.insertOne(model);
@Vaild() @requestBody() model: ExampleModel
): Promise<ExampleModel> {
//return this.client.insertOne(model);
return this.client.findOneById('5d0af7c039179a28de618cb8');
}
@httpPost('/:id')

View File

@ -1,6 +1,7 @@
import 'reflect-metadata';
import { InversifyExpressServer, getRouteInfo } from 'inversify-express-utils';
import * as bodyParser from 'body-parser';
import { rebuildServer } from 'cc-server-binding'
import { container, buildProviderModule } from 'cc-server-ioc';
import * as prettyjson from "prettyjson";
@ -16,11 +17,13 @@ server.setConfig((app) => {
extended: true
}));
app.use(bodyParser.json());
app.use(bodyParser.raw())
app.use(bodyParser.raw());
});
let serverInstance = server.build();
rebuildServer(container);
const routeInfo = getRouteInfo(container);
console.log(prettyjson.render({ routes: routeInfo }));