diff --git a/package.json b/package.json index 1fc06fa..e1f5efb 100755 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "my-midway-project", + "name": "cool-admin-next", "version": "1.0.0", "description": "", "private": true, diff --git a/src/configuration.ts b/src/configuration.ts index a9bc959..0dd5c11 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -13,7 +13,7 @@ import * as cool from 'midwayjs-cool-core'; // 必须,不可移除, cool-admin 官方组件 https://www.cool-js.com cool, //redis - + ] }) export class ContainerLifeCycle implements ILifeCycle { @@ -22,9 +22,19 @@ export class ContainerLifeCycle implements ILifeCycle { app: Application; // 应用启动完成 async onReady(container?: IMidwayContainer) { - this.app.use(async (ctx, next)=>{ - console.log('执行了') - }); + // this.app.use(async (ctx, next)=>{ + // console.log('执行了') + // }); + this.app.router.get('/dev', (ctx, next) => { + console.log('进来中间件了'); + ctx.status = 200 + ctx.body = { + a: 1, + b: 2 + }; + }, (ctx) => { + console.log('调用路由') + }) } // 应用停止 async onStop() { diff --git a/src/controller/home.ts b/src/controller/home.ts index 7f7aa0c..aa7fe3d 100755 --- a/src/controller/home.ts +++ b/src/controller/home.ts @@ -1,8 +1,11 @@ import { Get, Provide, Inject, Query } from '@midwayjs/decorator'; import { CoolController, CoolCache } from 'midwayjs-cool-core'; +//import { InjectEntityModel } from '@midwayjs/orm'; +import { User } from '../entity/user'; + @Provide() -@CoolController() +@CoolController({ api: ['add'], model: User }) export class HomeController { @Inject('cool:cache') coolCache: CoolCache; diff --git a/src/dto/test.ts b/src/dto/test.ts new file mode 100644 index 0000000..7b03358 --- /dev/null +++ b/src/dto/test.ts @@ -0,0 +1,15 @@ +import { Rule, RuleType } from "@midwayjs/decorator"; + +export class UserDTO { + @Rule(RuleType.number().required()) + id: number; + + @Rule(RuleType.string().required()) + firstName: string; + + @Rule(RuleType.string().max(10)) + lastName: string; + + @Rule(RuleType.number().max(60)) + age: number; +} \ No newline at end of file diff --git a/src/entity/user.ts b/src/entity/user.ts new file mode 100644 index 0000000..6bbf62e --- /dev/null +++ b/src/entity/user.ts @@ -0,0 +1,17 @@ +import { EntityModel } from '@midwayjs/orm'; +import { BaseModel } from 'midwayjs-cool-core'; +import { Column } from 'typeorm'; +import { Rule, RuleType } from "@midwayjs/decorator"; + +@EntityModel('user') +export class User extends BaseModel { + + @Rule(RuleType.number().required()) + @Column() + name: string; + + @Rule(RuleType.number().max(60)) + @Column('int') + age: number; + +} \ No newline at end of file