@simitgroup/simpleapp-generator 2.0.0-p-alpha → 2.0.0-r-alpha

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/ReleaseNote.md CHANGED
@@ -1,3 +1,11 @@
1
+ [2.0.0r-alpha]
2
+
3
+ 1. Fix Developer Portal
4
+
5
+ [2.0.0q-alpha]
6
+
7
+ 1. Fixed ts log version
8
+
1
9
  [2.0.0p-alpha]
2
10
 
3
11
  1. Test
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simitgroup/simpleapp-generator",
3
- "version": "2.0.0p-alpha",
3
+ "version": "2.0.0r-alpha",
4
4
  "description": "frontend nuxtjs and backend nests code generator using jsonschema",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -36,7 +36,7 @@
36
36
  "lodash": "^4.17.21",
37
37
  "moddle-xml": "^10.1.0",
38
38
  "path": "^0.12.7",
39
- "tslog": "^4.9.1"
39
+ "tslog": "4.9.1"
40
40
  },
41
41
  "bin": {
42
42
  "simpleapp-generator": "./dist/index.js"
@@ -4,8 +4,8 @@
4
4
  const apiName = it.typename.toUpperCase() + 'Api';
5
5
  const titleName = titleCase(pascalName);
6
6
  const uglyName = upperFirstCase(it.name ?? '');
7
- const schemaName = `SimtrainSchema.${uglyName}`;
8
- const schemaAutoCompleteName = `SimtrainSchema.${uglyName}AutoComplete`;
7
+ const schemaName = `SimtrainSchema.${pascalName}Dto`;
8
+ const schemaAutoCompleteName = `SimtrainSchema.${pascalName}AutoCompleteDto`;
9
9
 
10
10
  const serviceVariable = it.resourceName + 'Service';
11
11
 
@@ -15,15 +15,19 @@
15
15
 
16
16
  if(systemTypes.includes(tmpTypeName.toLowerCase())){
17
17
  tmpTypeName = upperFirstCase(tmpTypeName.toLowerCase());
18
+ if(typeName.includes('[')){
19
+ return `[${tmpTypeName}]`;
20
+ }
21
+
22
+ return tmpTypeName;
18
23
  } else {
19
24
  tmpTypeName = `SimtrainSchema.${tmpTypeName}`;
20
- }
25
+ if(typeName.includes('[')){
26
+ return `[${tmpTypeName}Dto]`;
27
+ }
21
28
 
22
- if(typeName.includes('[')){
23
- return `[${tmpTypeName}]`;
29
+ return `${tmpTypeName}Dto`;
24
30
  }
25
-
26
- return tmpTypeName;
27
31
  }
28
32
  %>
29
33
 
@@ -43,7 +47,7 @@ import { ApiTags, ApiBody, ApiResponse, ApiOperation, ApiQuery, PartialType } fr
43
47
  import { ApiHeader } from 'src/types/api';
44
48
  import { <%= pascalName %>Service } from './<%= kebabName %>.service';
45
49
  import { ResourceApiListDto } from '../../dto/resource-api.schema';
46
- import * as SimtrainSchema from '../../simtrain-schema';
50
+ import * as SimtrainSchema from '../../../../openapi/backend-dto/dtos/Api';
47
51
  import { Filter } from 'mongodb';
48
52
 
49
53
  @ApiTags('<%= titleName %>')
@@ -161,7 +165,7 @@ export class <%= pascalName %>Controller {
161
165
  const partstr = subpath[a];
162
166
  if(partstr.includes(':')) {
163
167
  const paraname = partstr.replace(':','');
164
- paramsWithType.push(`${paraname}: string`);
168
+ paramsWithType.push(`@Param('${paraname}') ${paraname}: string`);
165
169
  paramsWithoutType.push(paraname);
166
170
  }
167
171
  }
@@ -170,13 +174,13 @@ export class <%= pascalName %>Controller {
170
174
  if(api.queryPara && api.queryPara.length > 0) {
171
175
  for(let q=0; q < api.queryPara.length; q++) {
172
176
  const qp = api['queryPara'][q];
173
- paramsWithType.push(`${qp}: string`);
177
+ paramsWithType.push(`@Query('${qp}') ${qp}: string`);
174
178
  paramsWithoutType.push(qp);
175
179
  }
176
180
  }
177
181
 
178
182
  if(hasBody) {
179
- paramsWithType.push(`data: ${getTypeName(api.schema)}`);
183
+ paramsWithType.push(`@Body() data: ${getTypeName(api.schema)}`);
180
184
  paramsWithoutType.push('data');
181
185
  }
182
186
  %>
@@ -196,7 +200,7 @@ export class <%= pascalName %>Controller {
196
200
  @ApiResponse({ status: 500, description: 'Internal Error' })
197
201
  async <%= action %>(
198
202
  @Headers() headers: ApiHeader,
199
- <%= paramsWithType.join(',') %>
203
+ <%~ paramsWithType.join(',') %>
200
204
  ){
201
205
  return await this.<%= serviceVariable %>.<%= action %>(
202
206
  headers,
@@ -2,8 +2,8 @@
2
2
  const pascalName = upperFirstCase(it.resourceName);
3
3
  const apiName = it.typename.toUpperCase() + 'Api';
4
4
  const uglyName = upperFirstCase(it.name ?? '');
5
- const schemaName = `SimtrainSchema.${uglyName}`;
6
- const schemaAutoCompleteName = `SimtrainSchema.${uglyName}AutoComplete`;
5
+ const schemaName = `SimtrainSchema.${pascalName}Dto`;
6
+ const schemaAutoCompleteName = `SimtrainSchema.${pascalName}AutoCompleteDto`;
7
7
 
8
8
  const getTypeName = (typeName) => {
9
9
  const systemTypes = ['boolean', 'string', 'number', 'object', 'integer'];
@@ -11,15 +11,19 @@
11
11
 
12
12
  if(systemTypes.includes(tmpTypeName.toLowerCase())){
13
13
  tmpTypeName = upperFirstCase(tmpTypeName.toLowerCase());
14
+ if(typeName.includes('[')){
15
+ return `[${tmpTypeName}]`;
16
+ }
17
+
18
+ return tmpTypeName;
14
19
  } else {
15
20
  tmpTypeName = `SimtrainSchema.${tmpTypeName}`;
16
- }
21
+ if(typeName.includes('[')){
22
+ return `[${tmpTypeName}Dto]`;
23
+ }
17
24
 
18
- if(typeName.includes('[')){
19
- return `[${tmpTypeName}]`;
25
+ return `${tmpTypeName}Dto`;
20
26
  }
21
-
22
- return tmpTypeName;
23
27
  }
24
28
  %>
25
29
 
@@ -29,7 +33,7 @@ import { <%= apiName %> } from 'src/openapi/backend-api';
29
33
  import { ApiHeader } from 'src/types/api';
30
34
  import { getOpenApiConfig } from 'src/utils/api';
31
35
  import { ResourceApiListDto } from '../../dto/resource-api.schema';
32
- import * as SimtrainSchema from '../../simtrain-schema';
36
+ import * as SimtrainSchema from '../../../../openapi/backend-dto/dtos/Api';
33
37
 
34
38
  @Injectable()
35
39
  export class <%= pascalName %>Service {
@@ -7,26 +7,37 @@ import { InjectModel } from '@nestjs/mongoose';
7
7
  import { Model } from 'mongoose';
8
8
  import { UserContext } from 'src/simple-app/_core/features/user-context/user.context';
9
9
  import { MiniAppEnvEnum } from 'src/simple-app/_core/resources/mini-app/mini-app.enum';
10
+ import { MiniAppInstallationService } from '@resources/mini-app-installation/mini-app-installation.service';
11
+ import { MiniAppService } from '@resources/mini-app/mini-app.service';
12
+ import { BranchService } from '@resources/branch/branch.service';
10
13
 
11
14
  @Injectable()
12
15
  export class DeveloperPortalService {
13
16
  constructor(
14
- @InjectModel('Miniapp')
15
- protected miniAppDoc: Model<MiniApp>,
17
+ // @InjectModel('Miniapp')
18
+ // protected miniAppDoc: Model<MiniApp>,
19
+ protected miniAppService: MiniAppService,
16
20
 
17
- @InjectModel('Miniappinstallation')
18
- protected miniAppInstallationDoc: Model<MiniAppInstallation>,
21
+ // @InjectModel('Miniappinstallation')
22
+ // protected miniAppInstallationDoc: Model<MiniAppInstallation>,
23
+ protected miniAppInstallationService: MiniAppInstallationService,
19
24
 
20
- @InjectModel('Branch')
21
- protected branchDoc: Model<Branch>,
25
+ // @InjectModel('Branch')
26
+ // protected branchDoc: Model<Branch>,
27
+ protected branchService: BranchService,
22
28
  ) {}
23
29
 
24
- async getDemoCompany(developerPortalAppId: string) {
30
+ async getDemoCompany(appUser: UserContext, developerPortalAppId: string) {
25
31
  // Only dev got development.demoXOrg field
26
- const miniApp = await this.miniAppDoc.findOne({
32
+ // const miniApp = await this.miniAppDoc.findOne({
33
+ // 'developerPortal.appId': developerPortalAppId,
34
+ // env: MiniAppEnvEnum.DEV,
35
+ // });
36
+ const miniApps = await this.miniAppService.search(appUser, {
27
37
  'developerPortal.appId': developerPortalAppId,
28
38
  env: MiniAppEnvEnum.DEV,
29
39
  });
40
+ const miniApp = miniApps[0];
30
41
  if (miniApp && !_.isEmpty(miniApp?.development?.demoXOrg)) {
31
42
  return miniApp.development.demoXOrg;
32
43
  }
@@ -35,10 +46,14 @@ export class DeveloperPortalService {
35
46
  }
36
47
 
37
48
  async getInstalledMiniAppXOrgs(appUser: UserContext, developerPortalAppId: string) {
38
- const demoXOrg = await this.getDemoCompany(developerPortalAppId);
49
+ const demoXOrg = await this.getDemoCompany(appUser, developerPortalAppId);
39
50
 
40
51
  // Only get env === prod one
41
- const miniAppInstallations = await this.miniAppInstallationDoc.find({
52
+ // const miniAppInstallations = await this.miniAppInstallationDoc.find({
53
+ // 'miniApp.developerPortalAppId': developerPortalAppId,
54
+ // 'miniApp.env': MiniAppEnvEnum.PROD,
55
+ // });
56
+ const miniAppInstallations = await this.miniAppInstallationService.search(appUser, {
42
57
  'miniApp.developerPortalAppId': developerPortalAppId,
43
58
  'miniApp.env': MiniAppEnvEnum.PROD,
44
59
  });
@@ -67,7 +82,8 @@ export class DeveloperPortalService {
67
82
  };
68
83
 
69
84
  // Step 3: Run one query to get all branches
70
- const allBranches = await this.branchDoc.find(branchFilter);
85
+ // const allBranches = await this.branchDoc.find(branchFilter);
86
+ const allBranches = await this.branchService.search(appUser, branchFilter);
71
87
 
72
88
  // Step 4: Build a lookup map: `${tenantId}-${orgId}-${branchId}` → branch
73
89
  const branchMap = new Map<string, Branch>();
@@ -14,11 +14,39 @@ import { SimpleAppSoftwarePolicyModule } from '../policy/policy.module';
14
14
  import { MiniAppManagerBridgeService } from './mini-app-manager/mini-app-manager-bridge.service';
15
15
  import { MiniAppManagerEnvProductionService } from './mini-app-manager/mini-app-manager-env-production.service';
16
16
  import { MiniAppManagerEnvDevelopmentService } from './mini-app-manager/mini-app-manager-env-development.service';
17
+ import { DeveloperPortalController } from './developer-portal/developer-portal.controller';
18
+ import { DeveloperPortalEnvProductionService } from './developer-portal/developer-portal-env-production.service';
19
+ import { DeveloperPortalEnvDevelopmentService } from './developer-portal/developer-portal-env-development.service';
20
+ import { DeveloperPortalBridgeService } from './developer-portal/developer-portal-bridge.service';
21
+ import { DeveloperPortalService } from './developer-portal/developer-portal.service';
22
+ import { BranchModule } from '@resources/branch/branch.module';
23
+ import { PermissionModule } from '@resources/permission/permission.module';
24
+ import { UserModule } from '@resources/user/user.module';
17
25
 
18
26
  @Module({
19
- imports: [SimpleAppSoftwarePolicyModule,MiniAppInstallationModule,MiniAppModule],
20
- controllers: [MiniAppManagerController],
21
- providers: [MiniAppManagerService,MiniAppManagerPolicyService,MiniAppManagerEnvProductionService,MiniAppManagerEnvDevelopmentService,MiniAppManagerBridgeService],
22
- exports: [MiniAppManagerService,MiniAppManagerPolicyService,MiniAppManagerEnvProductionService,MiniAppManagerEnvDevelopmentService,MiniAppManagerBridgeService],
27
+ imports: [SimpleAppSoftwarePolicyModule, MiniAppInstallationModule, MiniAppModule, BranchModule, PermissionModule, UserModule],
28
+ controllers: [MiniAppManagerController, DeveloperPortalController],
29
+ providers: [
30
+ MiniAppManagerService,
31
+ MiniAppManagerPolicyService,
32
+ MiniAppManagerEnvProductionService,
33
+ MiniAppManagerEnvDevelopmentService,
34
+ MiniAppManagerBridgeService,
35
+ DeveloperPortalService,
36
+ DeveloperPortalBridgeService,
37
+ DeveloperPortalEnvDevelopmentService,
38
+ DeveloperPortalEnvProductionService,
39
+ ],
40
+ exports: [
41
+ MiniAppManagerService,
42
+ MiniAppManagerPolicyService,
43
+ MiniAppManagerEnvProductionService,
44
+ MiniAppManagerEnvDevelopmentService,
45
+ MiniAppManagerBridgeService,
46
+ DeveloperPortalService,
47
+ DeveloperPortalBridgeService,
48
+ DeveloperPortalEnvDevelopmentService,
49
+ DeveloperPortalEnvProductionService,
50
+ ],
23
51
  })
24
52
  export class SimpleAppMiniAppModule {}
@@ -526,7 +526,7 @@ export class UserContext extends UserContextInfo {
526
526
 
527
527
  // console.log("rolegroups",rolegroups)
528
528
  for (const group of this.groups) {
529
- const roles: Role[] = rolegroups[group]()
529
+ const roles: Role[] = rolegroups[group]();
530
530
  //(<() => Role[]>rolegroups[group])();
531
531
  for (let r = 0; r < roles.length; r++) {
532
532
  if (!this.roles.includes(roles[r])) {
@@ -535,7 +535,6 @@ export class UserContext extends UserContextInfo {
535
535
  }
536
536
  }
537
537
 
538
-
539
538
  this.moreProps = this.setMoreProps(userProfile);
540
539
  // this.package = userProfile['package'];
541
540
  // this.appintegration = await this.setAppIntegration();
@@ -1022,39 +1021,61 @@ export class UserContext extends UserContextInfo {
1022
1021
  }
1023
1022
 
1024
1023
  async setUserProfileFromDB() {
1025
- // const userProfile = await this.obtainProfileFromDB();
1026
- // if (userProfile) {
1027
- // this.logger.debug(`User ${this.uid} exists in tenant (${this.tenantId})`);
1028
- // this._id = userProfile._id.toString();
1029
- // this.email = userProfile.email ?? '';
1030
- // this.uName = userProfile.uname ?? '';
1031
- // this.fullName = userProfile.fullname ?? '';
1032
- // this.branchCode = userProfile['branchCode'] ?? '';
1033
- // this.branchName = userProfile['branchName'] ?? '';
1034
- // this.orgCode = userProfile['orgCode'] ?? '';
1035
- // this.orgName = userProfile['orgName'] ?? '';
1036
- // this.timeZone = userProfile['timeZone'] ?? '';
1037
- // this.currency = userProfile['currency'] ?? '';
1038
- // this.country = userProfile['country'] ?? '';
1039
- // this.offsetMinute = userProfile['offsetMinute'] ?? 0;
1040
- // this.orgRecordId = userProfile['orgRecordId'] ?? '';
1041
- // this.branchRecordId = userProfile['branchRecordId'] ?? '';
1042
- // this.groups = userProfile['groups'] ?? [];
1043
- // this.roles = userProfile['roles'] ?? [Role.Everyone, Role.User];
1044
- // //more complex
1045
- // this.clientSetting = userProfile['clientSetting'] ?? {};
1046
- // this.moreProps = this.setMoreProps(userProfile);
1047
- // this.package = userProfile['package'];
1048
- // // this.appintegration = await this.setAppIntegration();
1049
- // } else {
1050
- // this.logger.debug(`User ${this.uid} not exists in tenant (${this.tenantId})`);
1051
- // this.logger.debug(`Set unknown id of current user`);
1052
- // this.roles = [Role.Everyone, Role.Unknown];
1053
- // }
1054
- // if (this.isRealmAdmin() && !this.roles.includes(Role.SuperAdmin)) {
1055
- // this.roles.push(Role.SuperAdmin);
1056
- // }
1057
- // this.logger.verbose(`User ${this.uid} have _id (${this.getId()}), groups (${this.groups.join(',')}) and roles (${this.getRoles().join(',')}).`);
1024
+ const userProfile = await this.obtainProfileFromDB();
1025
+ if (userProfile) {
1026
+ this.logger.debug(`User ${this.uid} exists in tenant (${this.tenantId})`);
1027
+
1028
+ this._id = userProfile._id;
1029
+ this.email = userProfile.email ?? '';
1030
+ this.uName = userProfile.uName ?? '';
1031
+ this.fullName = userProfile.fullName ?? '';
1032
+
1033
+ this.branchCode = userProfile['branchCode'] ?? '';
1034
+ this.branchName = userProfile['branchName'] ?? '';
1035
+ this.tenantInfo = userProfile.tenantInfo;
1036
+ this.orgInfo = userProfile.orgInfo;
1037
+ this.branchInfo = userProfile.branchInfo;
1038
+ this.orgCode = userProfile['orgCode'] ?? '';
1039
+ this.orgName = userProfile['orgName'] ?? '';
1040
+ this.timeZone = userProfile['timeZone'] ?? '';
1041
+ this.currency = userProfile['currency'] ?? '';
1042
+ this.country = userProfile['country'] ?? '';
1043
+ this.offsetMinute = userProfile['offsetMinute'] ?? 0;
1044
+ this.orgRecordId = userProfile['orgRecordId'] ?? '';
1045
+ this.branchRecordId = userProfile['branchRecordId'] ?? '';
1046
+ this.invites = userProfile.invites;
1047
+ userProfile['branches'].forEach((b) => {
1048
+ b.xOrg = this.generateXOrg(b.tenantId, b.orgId, b.branchId);
1049
+ });
1050
+ this.branches = userProfile['branches'];
1051
+ this.groups = userProfile['groups'] ?? [];
1052
+ this.clientSetting = userProfile['clientSetting'] ?? {
1053
+ auditTrail: false,
1054
+ disableClassReminder: true,
1055
+ webhook: false,
1056
+ support: false,
1057
+ };
1058
+ this.roles = userProfile['roles'] ?? [Role.Everyone, Role.User];
1059
+
1060
+ for (const group of this.groups) {
1061
+ const roles: Role[] = rolegroups[group]();
1062
+ for (let r = 0; r < roles.length; r++) {
1063
+ if (!this.roles.includes(roles[r])) {
1064
+ this.roles.push(roles[r]);
1065
+ }
1066
+ }
1067
+ }
1068
+
1069
+ this.moreProps = this.setMoreProps(userProfile);
1070
+ } else {
1071
+ this.logger.debug(`User ${this.uid} not exists in tenant (${this.tenantId})`);
1072
+ this.logger.debug(`Set unknown id of current user`);
1073
+ this.roles = [Role.Everyone, Role.Unknown];
1074
+ }
1075
+ if (this.isRealmAdmin() && !this.roles.includes(Role.SuperAdmin)) {
1076
+ this.roles.push(Role.SuperAdmin);
1077
+ }
1078
+ this.logger.verbose(`User ${this.uid} have _id (${this.getId()}), groups (${this.groups.join(',')}) and roles (${this.getRoles().join(',')}).`);
1058
1079
  }
1059
1080
 
1060
1081
  // getAppIntegration = () => this.appintegration;
@@ -12,6 +12,8 @@ import {SimpleAppFeaturesModule} from './features/features.module'
12
12
 
13
13
  import { SimpleAppResourceApiModule } from './apis/resource-api.module';
14
14
  import { SimpleAppMiniAppsModule } from './mini-apps/mini-apps.module';
15
+ import { SimpleAppQueueConsumersModule } from './queues/queues.module';
16
+ import { SimpleAppMiniAppScopeModule } from '@core-features/mini-app/mini-app-scope/mini-app-scope.module';
15
17
 
16
18
  @Module({
17
19
  imports: [
@@ -20,7 +22,9 @@ import { SimpleAppMiniAppsModule } from './mini-apps/mini-apps.module';
20
22
  SimpleAppEventsModule,
21
23
  SimpleAppResourceApiModule,
22
24
  SimpleAppFeaturesModule,
23
- SimpleAppMiniAppsModule
25
+ SimpleAppMiniAppsModule,
26
+ SimpleAppQueueConsumersModule,
27
+ SimpleAppMiniAppScopeModule,
24
28
  ],
25
29
  controllers: [],
26
30
  providers: [],
@@ -30,7 +34,9 @@ import { SimpleAppMiniAppsModule } from './mini-apps/mini-apps.module';
30
34
  SimpleAppEventsModule,
31
35
  SimpleAppResourceApiModule,
32
36
  SimpleAppFeaturesModule,
33
- SimpleAppMiniAppsModule
37
+ SimpleAppMiniAppsModule,
38
+ SimpleAppQueueConsumersModule,
39
+ SimpleAppMiniAppScopeModule,
34
40
  ]
35
41
  })
36
42
  export class SimpleAppModule {}