cc-core-cli 1.0.33 → 1.0.34
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/package.json +1 -1
- package/template/module/README.md +20 -0
- package/template/module/demo.module.ts +3 -1
- package/template/module/example/example.layout.ts +6 -0
- package/template/module/example/example.schema.ts +13 -0
- package/template/module/example/example.service.ts +30 -0
- package/template/module/setting/setting.service.ts +41 -0
package/package.json
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# How to install
|
|
2
|
+
|
|
3
|
+
- Create demo folder under src/modules
|
|
4
|
+
- Pull CC Demo Module under demo folder
|
|
5
|
+
- Add this code in src/modules/modules.ts file
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
import { DemoExampleService } from "./demo/example/example.service";
|
|
9
|
+
import { DemoSettingService } from "./demo/setting/setting.service";
|
|
10
|
+
|
|
11
|
+
const CUSTOM_MODULES = [
|
|
12
|
+
{
|
|
13
|
+
module: DemoModule,
|
|
14
|
+
services: [
|
|
15
|
+
DemoExampleService,
|
|
16
|
+
DemoSettingService
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
```
|
|
@@ -4,6 +4,8 @@ import * as moduleConfig from "./module.json";
|
|
|
4
4
|
import { Module } from "@nestjs/common";
|
|
5
5
|
import { EntitiesModule, SettingModule } from "@shopstack/cc-core-lib/core";
|
|
6
6
|
import { ClsModule } from "nestjs-cls";
|
|
7
|
+
import { DemoExampleService } from "./example/example.service";
|
|
8
|
+
import { DemoSettingService } from "./setting/setting.service";
|
|
7
9
|
|
|
8
10
|
const { code } = moduleConfig;
|
|
9
11
|
|
|
@@ -14,6 +16,6 @@ const { code } = moduleConfig;
|
|
|
14
16
|
SettingModule,
|
|
15
17
|
],
|
|
16
18
|
controllers: [],
|
|
17
|
-
providers: [],
|
|
19
|
+
providers: [DemoExampleService,DemoSettingService],
|
|
18
20
|
})
|
|
19
21
|
export class DemoModule {}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as mongoose from "mongoose";
|
|
2
|
+
import { Prop, Schema } from "@nestjs/mongoose";
|
|
3
|
+
import { BaseSchema, BaseSchemaFactory } from "@shopstack/cc-core-lib/core";
|
|
4
|
+
|
|
5
|
+
@Schema({ strict: false, timestamps: true })
|
|
6
|
+
export class Example extends BaseSchema {
|
|
7
|
+
|
|
8
|
+
@Prop({ is_unique: true, required: true })
|
|
9
|
+
name: string;
|
|
10
|
+
|
|
11
|
+
}
|
|
12
|
+
export const ExampleSchema = BaseSchemaFactory.createForClass(Example);
|
|
13
|
+
ExampleSchema.index({ name: 1 }, { unique: true });
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as mongoose from "mongoose";
|
|
2
|
+
import * as _ from "lodash";
|
|
3
|
+
import * as moduleConfig from "../module.json";
|
|
4
|
+
|
|
5
|
+
import { Injectable, Inject, Scope } from "@nestjs/common";
|
|
6
|
+
import { InjectModel } from "@nestjs/mongoose";
|
|
7
|
+
import { EntitiesService, BaseService } from "@shopstack/cc-core-lib/core";
|
|
8
|
+
import { ClsService } from "nestjs-cls";
|
|
9
|
+
import { Example, ExampleSchema } from "./example.schema";
|
|
10
|
+
import { ExampleLayout } from "./example.layout";
|
|
11
|
+
|
|
12
|
+
const { code, name } = moduleConfig;
|
|
13
|
+
|
|
14
|
+
@Injectable()
|
|
15
|
+
export class DemoExampleService extends BaseService<Example> {
|
|
16
|
+
constructor(
|
|
17
|
+
readonly cls: ClsService,
|
|
18
|
+
private entitiesService: EntitiesService,
|
|
19
|
+
@InjectModel(`${code}_${_.snakeCase(Example.name)}`)
|
|
20
|
+
protected model: mongoose.Model<Example>
|
|
21
|
+
) {
|
|
22
|
+
super(cls, model);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public async init(): Promise<string> {
|
|
26
|
+
DemoExampleService.prefix = code;
|
|
27
|
+
await this.entitiesService.refreshSystemSchema(DemoExampleService, this.model, Example, ExampleSchema, { layouts: ExampleLayout });
|
|
28
|
+
return `[${_.toUpper(name)} MODULE] ${_.snakeCase(Example.name)}`;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as _ from "lodash";
|
|
2
|
+
import { Inject, Injectable, Logger, Scope } from "@nestjs/common";
|
|
3
|
+
|
|
4
|
+
import { IModuleSetting, BaseModuleSettingService, SettingService, UserPermission, loadEntity } from "@shopstack/cc-core-lib/core";
|
|
5
|
+
|
|
6
|
+
import { ClsService } from "nestjs-cls";
|
|
7
|
+
|
|
8
|
+
import * as moduleConfig from "../module.json";
|
|
9
|
+
const { code, name } = moduleConfig;
|
|
10
|
+
|
|
11
|
+
@Injectable()
|
|
12
|
+
export class DemoSettingService extends BaseModuleSettingService implements IModuleSetting {
|
|
13
|
+
constructor(readonly cls: ClsService, protected setting: SettingService) {
|
|
14
|
+
super(code, setting, cls);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public async defaultPermission(): Promise<any> {
|
|
18
|
+
return {
|
|
19
|
+
manage_example: false,
|
|
20
|
+
manage_setting: false,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
public async setPermission(permission: any): Promise<any> {
|
|
24
|
+
const result = [];
|
|
25
|
+
result.push({
|
|
26
|
+
permission: permission.manage_example ? [UserPermission.creator] : [UserPermission.access_denied],
|
|
27
|
+
entity: await loadEntity(`${code}_example`),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public async getSetting(key?: string): Promise<any> {
|
|
34
|
+
const data = await super.getSetting(key);
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
37
|
+
public async setSetting(data: any, key?: string): Promise<any> {
|
|
38
|
+
const result = await super.setSetting(data, key);
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
}
|