@avleon/cli 0.0.42 → 0.0.44
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/.github/workflows/publish.yml +69 -0
- package/dist/cli.js +53 -49
- package/dist/commands.js +10 -10
- package/dist/create.js +178 -148
- package/dist/scripts/serve.js +290 -0
- package/dist/serve.js +305 -0
- package/package.json +15 -8
- package/readme.md +66 -66
- package/stubs/app/app-controller.stub +11 -11
- package/stubs/app/app-minimal.stub +17 -17
- package/stubs/basic-controller.stub +7 -7
- package/stubs/config.stub +11 -11
- package/stubs/controllers/basic-controller.stub +12 -12
- package/stubs/controllers/orm-rest-controller.stub +52 -52
- package/stubs/controllers/rest-controller.stub +34 -34
- package/stubs/models/basic-model.stub +6 -6
- package/stubs/models/entity-model.stub +23 -23
- package/stubs/serve.stub +10 -10
- package/stubs/services/basic-service.stub +8 -8
- package/stubs/services/orm-rest-service.stub +73 -73
- package/stubs/services/rest-service.stub +71 -71
- package/tsconfig.json +16 -15
- package/pnpm-workspace.yaml +0 -2
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
import { AppService, Collection } from '@avleon/core';
|
|
2
|
-
import { {Model} } from '../models/{model}.model';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
@AppService
|
|
6
|
-
export class {Service}Service{
|
|
7
|
-
|
|
8
|
-
constructor(
|
|
9
|
-
private readonly {model}Collection:Collection.from<{Model}>([])
|
|
10
|
-
){}
|
|
11
|
-
|
|
12
|
-
async findAll(options:any={}){
|
|
13
|
-
return this.{model}Collection.find(options);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async paginate(current:number = 1, options:any={}){
|
|
17
|
-
const take = 10;
|
|
18
|
-
const skip = current > 1 ? ( current -1 ) * 10 : 0;
|
|
19
|
-
const total = await this.{model}Collection.count(options);
|
|
20
|
-
const totalPage = Math.ceil(total / take);
|
|
21
|
-
const next = current < totalPage ? current + 1 : null;
|
|
22
|
-
const prev = current > 1 ? current - 1 : null;
|
|
23
|
-
const data = await this.{model}Collection.find({
|
|
24
|
-
...options,
|
|
25
|
-
take,
|
|
26
|
-
skip
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
total,
|
|
31
|
-
totalPage,
|
|
32
|
-
current,
|
|
33
|
-
next,
|
|
34
|
-
prev,
|
|
35
|
-
data
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async findByPk(id:number){
|
|
40
|
-
return this.{model}Collection.findOne({id});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async findBy(options:any){
|
|
44
|
-
return this.{model}Collection.findBy(options);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async findOneBy(options:any){
|
|
48
|
-
return this.{model}Collection.findOneBy(options);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
async findOne(id:number){
|
|
53
|
-
return this.{model}Collection.findOne({where:{id}}) ;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async create(createBody:any){
|
|
57
|
-
const savedItem = await this.{model}Collection.save(createBody);
|
|
58
|
-
return savedItem;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async update(id:number, updateBody:any){
|
|
62
|
-
const isUpdate = await this.{model}Collection.update(id, updateBody);
|
|
63
|
-
return isUpdate;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async delete(id:number){
|
|
67
|
-
const isDeleted = await this.{model}Collection.delete(id);
|
|
68
|
-
return isDeleted > 0;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
}
|
|
1
|
+
import { AppService, Collection } from '@avleon/core';
|
|
2
|
+
import { {Model} } from '../models/{model}.model';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@AppService
|
|
6
|
+
export class {Service}Service{
|
|
7
|
+
|
|
8
|
+
constructor(
|
|
9
|
+
private readonly {model}Collection:Collection.from<{Model}>([])
|
|
10
|
+
){}
|
|
11
|
+
|
|
12
|
+
async findAll(options:any={}){
|
|
13
|
+
return this.{model}Collection.find(options);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async paginate(current:number = 1, options:any={}){
|
|
17
|
+
const take = 10;
|
|
18
|
+
const skip = current > 1 ? ( current -1 ) * 10 : 0;
|
|
19
|
+
const total = await this.{model}Collection.count(options);
|
|
20
|
+
const totalPage = Math.ceil(total / take);
|
|
21
|
+
const next = current < totalPage ? current + 1 : null;
|
|
22
|
+
const prev = current > 1 ? current - 1 : null;
|
|
23
|
+
const data = await this.{model}Collection.find({
|
|
24
|
+
...options,
|
|
25
|
+
take,
|
|
26
|
+
skip
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
total,
|
|
31
|
+
totalPage,
|
|
32
|
+
current,
|
|
33
|
+
next,
|
|
34
|
+
prev,
|
|
35
|
+
data
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async findByPk(id:number){
|
|
40
|
+
return this.{model}Collection.findOne({id});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async findBy(options:any){
|
|
44
|
+
return this.{model}Collection.findBy(options);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async findOneBy(options:any){
|
|
48
|
+
return this.{model}Collection.findOneBy(options);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
async findOne(id:number){
|
|
53
|
+
return this.{model}Collection.findOne({where:{id}}) ;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async create(createBody:any){
|
|
57
|
+
const savedItem = await this.{model}Collection.save(createBody);
|
|
58
|
+
return savedItem;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async update(id:number, updateBody:any){
|
|
62
|
+
const isUpdate = await this.{model}Collection.update(id, updateBody);
|
|
63
|
+
return isUpdate;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async delete(id:number){
|
|
67
|
+
const isDeleted = await this.{model}Collection.delete(id);
|
|
68
|
+
return isDeleted > 0;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "
|
|
4
|
-
"module": "CommonJS",
|
|
5
|
-
"moduleResolution": "node",
|
|
6
|
-
"outDir": "./dist",
|
|
7
|
-
"rootDir": "./src",
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "CommonJS",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"rootDir": "./src",
|
|
8
|
+
"allowJs": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"allowSyntheticDefaultImports": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"skipLibCheck": true
|
|
13
|
+
},
|
|
14
|
+
"include": ["src/**/*", "src/stubs","scripts"],
|
|
15
|
+
"exclude": ["node_modules", "dist", "src/**/*.(spec|test).ts"]
|
|
16
|
+
}
|
package/pnpm-workspace.yaml
DELETED