feat: add module auto check
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
5d8e818a5c
commit
fd6c0e74cb
@ -2,6 +2,7 @@ import {
|
|||||||
controller, response, requestBody, httpGet, httpPost, queryParam, requestParam
|
controller, response, requestBody, httpGet, httpPost, queryParam, requestParam
|
||||||
} from 'inversify-express-utils';
|
} from 'inversify-express-utils';
|
||||||
import { inject, postConstruct } from 'inversify';
|
import { inject, postConstruct } from 'inversify';
|
||||||
|
import { Vaild, NotBlank, NotNull } from 'cc-server-binding'
|
||||||
import { DBClient } from 'cc-server-db'
|
import { DBClient } from 'cc-server-db'
|
||||||
import 'cc-server-db-mongo'
|
import 'cc-server-db-mongo'
|
||||||
|
|
||||||
@ -10,10 +11,12 @@ import 'cc-server-db-mongo'
|
|||||||
|
|
||||||
const TABLE = 'users'
|
const TABLE = 'users'
|
||||||
|
|
||||||
interface ExampleModel {
|
class ExampleModel {
|
||||||
_id: string;
|
_id: string;
|
||||||
|
@NotBlank("用户名不得为空!")
|
||||||
username: string;
|
username: string;
|
||||||
password: string;
|
password: string;
|
||||||
|
@NotNull()
|
||||||
age: number;
|
age: number;
|
||||||
email: string;
|
email: string;
|
||||||
}
|
}
|
||||||
@ -44,9 +47,10 @@ export class Controller {
|
|||||||
|
|
||||||
@httpPost('/')
|
@httpPost('/')
|
||||||
public async create(
|
public async create(
|
||||||
@requestBody() model: Model
|
@Vaild() @requestBody() model: ExampleModel
|
||||||
): Promise<Model> {
|
): Promise<ExampleModel> {
|
||||||
return this.client.insertOne(model);
|
//return this.client.insertOne(model);
|
||||||
|
return this.client.findOneById('5d0af7c039179a28de618cb8');
|
||||||
}
|
}
|
||||||
|
|
||||||
@httpPost('/:id')
|
@httpPost('/:id')
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import 'reflect-metadata';
|
import 'reflect-metadata';
|
||||||
import { InversifyExpressServer, getRouteInfo } from 'inversify-express-utils';
|
import { InversifyExpressServer, getRouteInfo } from 'inversify-express-utils';
|
||||||
import * as bodyParser from 'body-parser';
|
import * as bodyParser from 'body-parser';
|
||||||
|
import { rebuildServer } from 'cc-server-binding'
|
||||||
import { container, buildProviderModule } from 'cc-server-ioc';
|
import { container, buildProviderModule } from 'cc-server-ioc';
|
||||||
import * as prettyjson from "prettyjson";
|
import * as prettyjson from "prettyjson";
|
||||||
|
|
||||||
@ -16,11 +17,13 @@ server.setConfig((app) => {
|
|||||||
extended: true
|
extended: true
|
||||||
}));
|
}));
|
||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
app.use(bodyParser.raw())
|
app.use(bodyParser.raw());
|
||||||
});
|
});
|
||||||
|
|
||||||
let serverInstance = server.build();
|
let serverInstance = server.build();
|
||||||
|
|
||||||
|
rebuildServer(container);
|
||||||
|
|
||||||
const routeInfo = getRouteInfo(container);
|
const routeInfo = getRouteInfo(container);
|
||||||
|
|
||||||
console.log(prettyjson.render({ routes: routeInfo }));
|
console.log(prettyjson.render({ routes: routeInfo }));
|
||||||
|
Loading…
Reference in New Issue
Block a user