@simitgroup/simpleapp-generator 2.0.0-c-alpha → 2.0.0-d-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,6 @@
1
+ [2.0.0d-alpha]
2
+ 1. provide tenantInfo, orgInfo, branchInfo to frontend
3
+
1
4
  [2.0.0c-alpha]
2
5
  1. fix profile session keeping error
3
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simitgroup/simpleapp-generator",
3
- "version": "2.0.0c-alpha",
3
+ "version": "2.0.0d-alpha",
4
4
  "description": "frontend nuxtjs and backend nests code generator using jsonschema",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -29,7 +29,7 @@ export class MiniAppManagerPolicyService {
29
29
  }
30
30
 
31
31
  hasRequiredPlan(appUser: UserContext, miniApp: MiniApp) {
32
- const currentPlan = appUser.getPackage();
32
+ const currentPlan = appUser.tenantInfo.package;
33
33
  const requiredPlans = miniApp.access.requiredPlans ?? [];
34
34
 
35
35
  if (_.isEmpty(requiredPlans)) return true;
@@ -28,7 +28,7 @@ export class PolicyService {
28
28
  * - plans/enterprise.ts
29
29
  */
30
30
  hasFeature(appUser: UserContext, feature: keyof typeof this._FEATURES): boolean {
31
- const appPackage = appUser.getPackage();
31
+ const appPackage = appUser.tenantInfo.package
32
32
  const allowedPlans = this._FEATURES[feature];
33
33
 
34
34
  return allowedPlans.includes(appPackage);
@@ -3,6 +3,8 @@ import { ForeignKey } from '../../framework/schemas';
3
3
  import { Branch } from 'src/simple-app/.core/resources/branch/branch.schema';
4
4
  import { Permission } from 'src/simple-app/.core/resources/permission/permission.schema';
5
5
  import { Role } from '../auth/role-guard/roles.enum';
6
+ import { Organization } from '../../resources/organization/organization.schema';
7
+ import { Tenant } from '../../resources/tenant/tenant.schema';
6
8
 
7
9
  export class UserContextInfo {
8
10
  @ApiProperty({ type: String })
@@ -13,7 +15,6 @@ export class UserContextInfo {
13
15
  sessionId: string;
14
16
  @ApiProperty({ type: String })
15
17
  xOrg: string;
16
-
17
18
  @ApiProperty({ type: Number })
18
19
  tenantId: number;
19
20
  @ApiProperty({ type: Number })
@@ -58,6 +59,13 @@ export class UserContextInfo {
58
59
  @ApiProperty({ type: () => [ProfileUserBranch], description: 'List of branch the user can access in current tenant' })
59
60
  branches: ProfileUserBranch[];
60
61
 
62
+ @ApiProperty({ type: ()=>Tenant, description: 'List of task, or authority of the user can do' })
63
+ tenantInfo:Tenant;
64
+ @ApiProperty({ type: ()=>Organization, description: 'List of task, or authority of the user can do' })
65
+ orgInfo:Organization;
66
+ @ApiProperty({ type: ()=>Branch, description: 'List of task, or authority of the user can do' })
67
+ branchInfo:Branch;
68
+
61
69
  @ApiProperty({ type: () => Object, description: 'Store all the rest of useful fields regarding user or branch' })
62
70
  moreProps?: Record<string, any>;
63
71
  }
@@ -75,11 +83,11 @@ export class ProfileUserInvites {
75
83
 
76
84
  export class BranchMinInfo {
77
85
  @ApiProperty({ type: String })
78
- branchId:string
86
+ branchId: string;
79
87
  @ApiProperty({ type: String })
80
- branchCode:string
88
+ branchCode: string;
81
89
  @ApiProperty({ type: String })
82
- branchName:string
90
+ branchName: string;
83
91
  }
84
92
  export class ProfileUserBranch {
85
93
  @ApiProperty({ type: String })
@@ -106,7 +106,7 @@ export class UserContext extends UserContextInfo {
106
106
 
107
107
  // protected moreProps: Record<string, any> = {};
108
108
 
109
- protected package: string = '';
109
+ // protected package: string = '';
110
110
 
111
111
  protected webhooks: Webhook[] = []; //systemWebHooks;
112
112
  protected clientSetting: TenantClientSetting = {
@@ -186,7 +186,7 @@ export class UserContext extends UserContextInfo {
186
186
 
187
187
  getMoreProps = () => this.moreProps;
188
188
 
189
- getPackage = () => this.package;
189
+ // getPackage = () => this.package;
190
190
 
191
191
  getRoles = () => this.roles;
192
192
 
@@ -220,9 +220,9 @@ export class UserContext extends UserContextInfo {
220
220
  // if (Array.isArray(wh) && wh.length > 0) this.webhooks = this.webhooks.concat(wh);
221
221
  };
222
222
 
223
- setPackage = (packageName: string) => {
224
- this.package = packageName;
225
- };
223
+ // setPackage = (packageName: string) => {
224
+ // this.package = packageName;
225
+ // };
226
226
 
227
227
  setTimeZone = (timeZone: string) => {
228
228
  this.timeZone = timeZone;
@@ -270,6 +270,16 @@ export class UserContext extends UserContextInfo {
270
270
  const pipelines: PipelineStage[] = [
271
271
  //get profile
272
272
  { $match: { uid: this.uid, tenantId: this.tenantId } },
273
+ {
274
+ $lookup: {
275
+ from: 'tenant',
276
+ as: 'tenantInfo',
277
+ localField: 'tenantId',
278
+ foreignField: 'tenantId',
279
+ pipeline: [{ $project:{ created:0,updated:0,createdBy:0,updatedBy:0,__v:0} }],
280
+ },
281
+ },
282
+ {$unwind:{path:'$tenantInfo',preserveNullAndEmptyArrays:true}},
273
283
  {
274
284
  $lookup: {
275
285
  from: 'permission',
@@ -286,13 +296,13 @@ export class UserContext extends UserContextInfo {
286
296
  },
287
297
  },
288
298
  {
289
- $project: {
290
- uid: 1,
291
- fullName: 1,
292
- email: 1,
293
- tenantId: 1,
294
- orgId: 1,
295
- branchId: 1,
299
+ $addFields: {
300
+ // uid: 1,
301
+ // fullName: 1,
302
+ // email: 1,
303
+ // tenantId: 1,
304
+ // orgId: 1,
305
+ // branchId: 1,
296
306
  groups: '$perm.groups',
297
307
  },
298
308
  },
@@ -327,6 +337,36 @@ export class UserContext extends UserContextInfo {
327
337
  preserveNullAndEmptyArrays: true,
328
338
  },
329
339
  },
340
+ {
341
+ $lookup: {
342
+ from: 'tenant',
343
+ as: 'tenantInfo',
344
+ localField: 'tenantId',
345
+ foreignField: 'tenantId',
346
+ pipeline: [{ $project:{ created:0,updated:0,createdBy:0,updatedBy:0,__v:0} }],
347
+ },
348
+ },
349
+ {$unwind:{path:'$tenantInfo',preserveNullAndEmptyArrays:true}},
350
+ {
351
+ $lookup: {
352
+ from: 'organization',
353
+ as: 'orgInfo',
354
+ localField: 'orgId',
355
+ foreignField: 'orgId',
356
+ pipeline: [{ $project:{ created:0,updated:0,createdBy:0,updatedBy:0,__v:0} }],
357
+ },
358
+ },
359
+ {$unwind:{path:'$orgInfo',preserveNullAndEmptyArrays:true}},
360
+ {
361
+ $lookup: {
362
+ from: 'branch',
363
+ as: 'branchInfo',
364
+ localField: 'branchId',
365
+ foreignField: 'branchId',
366
+ pipeline: [{ $project:{ created:0,updated:0,createdBy:0,updatedBy:0,__v:0} }],
367
+ },
368
+ },
369
+ {$unwind:{path:'$branchInfo',preserveNullAndEmptyArrays:true}},
330
370
  {
331
371
  $project: {
332
372
  uid: 1,
@@ -346,6 +386,9 @@ export class UserContext extends UserContextInfo {
346
386
  timeZone: '$b.o.timeZone',
347
387
  currency: '$b.o.currency',
348
388
  country: '$b.o.country',
389
+ tenantInfo:1,
390
+ orgInfo:1,
391
+ branchInfo:1,
349
392
  },
350
393
  },
351
394
 
@@ -400,8 +443,40 @@ export class UserContext extends UserContextInfo {
400
443
  ],
401
444
  },
402
445
  },
403
- ];
446
+
447
+ //get invites
448
+ {
449
+ $lookup: {
450
+ from: 'user',
451
+ localField: 'email',
452
+ foreignField: 'email',
453
+ as: 'invites',
454
+ pipeline: [
455
+ { $match: { uid: '' } },
456
+ {
457
+ $lookup: {
458
+ from: 'tenant',
459
+ localField: 'tenantId',
460
+ foreignField: 'tenantId',
461
+ as: 'tenant',
462
+ },
463
+ },
464
+ {$unwind:'$tenant'},
465
+ {
466
+ $project:{
467
+ _id:1,
468
+ created:1,
469
+ tenantId: 1,
470
+ tenantName:'$tenant.tenantName'
471
+ }
472
+ }
473
+ ],
474
+ },
475
+ }
476
+ ];
477
+
404
478
  const userProfiles: UserContextInfo[] = await this.userModel.aggregate(pipelines).exec();
479
+ // console.log("userProfiles",userProfiles)
405
480
  return userProfiles[0];
406
481
  }
407
482
 
@@ -418,13 +493,16 @@ export class UserContext extends UserContextInfo {
418
493
  this.logger.debug(`User found ${this.uid}`);
419
494
 
420
495
  const userProfile = await this.obtainProfileFromDB();
421
- // console.log('userProfile', userProfile);
496
+ // console.log('userProfile', JSON.stringify(userProfile,null,2));
422
497
  if (userProfile) {
423
498
  this.logger.debug(`User ${this.uid} exists in tenant (${this.tenantId})`);
424
499
 
425
500
  this._id = userProfile._id;
426
501
  this.branchCode = userProfile['branchCode'] ?? '';
427
502
  this.branchName = userProfile['branchName'] ?? '';
503
+ this.tenantInfo = userProfile.tenantInfo;
504
+ this.orgInfo = userProfile.orgInfo;
505
+ this.branchInfo = userProfile.branchInfo;
428
506
  this.orgCode = userProfile['orgCode'] ?? '';
429
507
  this.orgName = userProfile['orgName'] ?? '';
430
508
  this.timeZone = userProfile['timeZone'] ?? '';
@@ -433,6 +511,7 @@ export class UserContext extends UserContextInfo {
433
511
  this.offsetMinute = userProfile['offsetMinute'] ?? 0;
434
512
  this.orgRecordId = userProfile['orgRecordId'] ?? '';
435
513
  this.branchRecordId = userProfile['branchRecordId'] ?? '';
514
+ this.invites = userProfile.invites;
436
515
  userProfile['branches'].forEach((b) => {
437
516
  b.xOrg = this.generateXOrg(b.tenantId, b.orgId, b.branchId);
438
517
  });
@@ -445,8 +524,8 @@ export class UserContext extends UserContextInfo {
445
524
  support: false,
446
525
  };
447
526
  this.roles = userProfile['roles'] ?? [Role.Everyone, Role.User];
448
- // this.moreProps = this.setMoreProps(userProfile);
449
- this.package = userProfile['package'];
527
+ this.moreProps = this.setMoreProps(userProfile);
528
+ // this.package = userProfile['package'];
450
529
  // this.appintegration = await this.setAppIntegration();
451
530
  } else {
452
531
  this.logger.debug(`User ${this.uid} not exists in tenant (${this.tenantId})`);
@@ -600,6 +679,9 @@ export class UserContext extends UserContextInfo {
600
679
  branchId: this.branchId,
601
680
  //branch id in string (branch._id)
602
681
  branchRecordId: this.branchRecordId,
682
+ tenantInfo: this.tenantInfo,
683
+ orgInfo: this.orgInfo,
684
+ branchInfo: this.branchInfo,
603
685
 
604
686
  branchCode: this.branchCode,
605
687
  branchName: this.branchName,
@@ -980,7 +1062,7 @@ export class UserContext extends UserContextInfo {
980
1062
  /**
981
1063
  * Define additional properties from user into moreProps
982
1064
  */
983
- setMoreProps(userProfile: UserProfile): Record<string, any> {
1065
+ setMoreProps(userProfile: UserContextInfo): Record<string, any> {
984
1066
  const allprops = Object.keys(userProfile);
985
1067
  const excludekeys = [
986
1068
  'created',
@@ -1003,6 +1085,9 @@ export class UserContext extends UserContextInfo {
1003
1085
  'country',
1004
1086
  'offsetMinute',
1005
1087
  'tenantId',
1088
+ 'tenantInfo',
1089
+ 'orgInfo',
1090
+ 'branchInfo',
1006
1091
  // 'lastActivity',
1007
1092
  'group',
1008
1093
  '__v',
@@ -1017,9 +1102,9 @@ export class UserContext extends UserContextInfo {
1017
1102
  }
1018
1103
  }
1019
1104
 
1020
- if (!data['package']) {
1021
- data['package'] = 'free';
1022
- }
1105
+ // if (!data['package']) {
1106
+ // data['package'] = 'free';
1107
+ // }
1023
1108
  return data;
1024
1109
  }
1025
1110
 
@@ -1054,7 +1139,7 @@ type UserProfile = {
1054
1139
  groups: string[];
1055
1140
  roles: Role[];
1056
1141
  tenantRecordId?: string;
1057
- package?: string;
1142
+ // package?: string;
1058
1143
  branchRecordId?: string;
1059
1144
  branchCode?: string;
1060
1145
  branchName?: string;
@@ -1092,7 +1177,7 @@ type UserProfile = {
1092
1177
  currentTenant: {
1093
1178
  _id: string;
1094
1179
  tenantName: string;
1095
- package: string;
1180
+ // package: string;
1096
1181
  clientSetting: TenantClientSetting;
1097
1182
  owner: {
1098
1183
  uid: string;
@@ -5,7 +5,7 @@
5
5
  * Author: Ks Tan
6
6
  */
7
7
  import { defineNuxtPlugin } from "#app";
8
- import { PROFILEApi,ProfileUserBranch,UserContextInfo } from "../simpleapp/generate/openapi";
8
+ import { PROFILEApi,ProfileUserBranch,UserContextInfo , Branch, Tenant,Organization} from "../simpleapp/generate/openapi";
9
9
  import { UserProfile } from "~/types";
10
10
  import axios, { Axios, AxiosError, AxiosResponse } from "axios";
11
11
  import _ from "lodash";
@@ -30,6 +30,9 @@ export default defineNuxtPlugin(async (nuxtApp) => {
30
30
  currency: ref(""),
31
31
  country: ref(""),
32
32
  offsetMinute: ref(0),
33
+ tenantInfo: ref<Tenant>(),
34
+ orgInfo: ref<Organization>(),
35
+ branchInfo: ref<Branch>(),
33
36
  uid: ref(""),
34
37
  email: ref(""),
35
38
  fullName: ref(""),