koatty_cli
Advanced tools
Comparing version 1.11.0 to 1.12.0
@@ -396,3 +396,21 @@ #!/usr/bin/env node | ||
/** | ||
* | ||
* | ||
* @param {*} dto(dto)ct | ||
*/ | ||
const createDto = function (dto) { | ||
_checkEnv(); | ||
dto = helper.camelCase(dto, { pascalCase: true }); | ||
APP_PATH = getProjectAppPath(projectRootPath); | ||
helper.mkDir(APP_PATH + path.sep + 'dto' + path.sep + module); | ||
copyFile('dto' + path.sep + 'NewDTO.ts', APP_PATH + path.sep + 'model' + path.sep + 'dto' + path.sep + dto + 'DTO.ts', { | ||
'<Path>': '..', | ||
'<DTO>': dto + 'DTO' | ||
}); | ||
}; | ||
//================================================================================================== | ||
@@ -410,6 +428,6 @@ | ||
//create controlelr | ||
program.command('controller <controllerName>').description('add controller').action(function (controller) { | ||
program.command('controller <controllerName>').description('add controller class').action(function (controller) { | ||
createController(controller); | ||
}); | ||
program.command('ctl <controllerName>').description('add controller').action(function (controller) { | ||
program.command('ctl <controllerName>').description('add controller class').action(function (controller) { | ||
createController(controller); | ||
@@ -419,6 +437,6 @@ }); | ||
//create middleware | ||
program.command('middleware <middlewareName>').description('add middleware').action(function (middleware) { | ||
program.command('middleware <middlewareName>').description('add middleware class').action(function (middleware) { | ||
createMiddleware(middleware); | ||
}); | ||
program.command('mw <middlewareName>').description('add middleware').action(function (middleware) { | ||
program.command('mw <middlewareName>').description('add middleware class').action(function (middleware) { | ||
createMiddleware(middleware); | ||
@@ -428,6 +446,6 @@ }); | ||
//create service | ||
program.command('service <serviceName>').description('add service').action(function (service) { | ||
program.command('service <serviceName>').description('add service class').action(function (service) { | ||
createService(service); | ||
}); | ||
program.command('sev <serviceName>').description('add service').action(function (service) { | ||
program.command('sev <serviceName>').description('add service class').action(function (service) { | ||
createService(service); | ||
@@ -437,6 +455,6 @@ }); | ||
//create model | ||
program.command('model <modelName>').description('add model').action(function (model) { | ||
program.command('model <modelName>').description('add model class').action(function (model) { | ||
createModel(model); | ||
}); | ||
program.command('mo <modelName>').description('add model').action(function (model) { | ||
program.command('mo <modelName>').description('add model class').action(function (model) { | ||
createModel(model); | ||
@@ -446,6 +464,11 @@ }); | ||
//create aspect | ||
program.command('aspect <aspectName>').description('add aspect').action(function (aspect) { | ||
program.command('aspect <aspectName>').description('add aspect class').action(function (aspect) { | ||
createAspect(aspect); | ||
}); | ||
//create dto | ||
program.command('dto <dtoName>').description('add dto class').action(function (dto) { | ||
createDto(dto); | ||
}); | ||
program.parse(process.argv); |
{ | ||
"name": "koatty_cli", | ||
"version": "1.11.0", | ||
"version": "1.12.0", | ||
"description": "Koatty command line tool.", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -49,2 +49,70 @@ # koatty_cli | ||
``` | ||
### 5.Create a Aspect | ||
定义切面类: | ||
```shell | ||
koatty aspect test | ||
``` | ||
使用切面: | ||
```js | ||
@Controller() | ||
@BeforeEach("TestAspect") //类的每一个方法执行之前执行 | ||
export class TestController extends BaseController { | ||
app: App; | ||
@RequestMapping("/test", RequestMethod.ALL) | ||
@After("TestAspect") //test方法执行之前执行 | ||
async test() { | ||
const info = await this.testService.test(); | ||
return this.body(info); | ||
} | ||
} | ||
``` | ||
### 5.Create a DTO class | ||
定义数据验证类: | ||
```shell | ||
koatty dto test | ||
``` | ||
修改数据验证类: | ||
``` | ||
export class TestDTO { | ||
@IsNotEmpty() | ||
name: string; | ||
@Min(0) | ||
@Max(120) | ||
age: number; | ||
} | ||
``` | ||
使用实体类进行验证: | ||
```js | ||
@Controller() | ||
export class TestController extends BaseController { | ||
app: App; | ||
@RequestMapping("/test", RequestMethod.ALL) | ||
@Validated() // <== 开启验证 | ||
async test(@Get() param: TestDTO) { // <== 指定DTO | ||
const info = await this.testService.test(); | ||
return this.body(info); | ||
} | ||
} | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47048
28
752
117