@simitgroup/simpleapp-generator 1.0.47 → 1.0.49

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.
Files changed (137) hide show
  1. package/README.md +44 -4
  2. package/buildinschemas copy/docnoformat.docno.jsonschema.json +2 -20
  3. package/dist/buildinschemas/autoincreament.js +1 -1
  4. package/dist/buildinschemas/autoincreament.js.map +1 -1
  5. package/dist/buildinschemas/branch.js +1 -1
  6. package/dist/buildinschemas/branch.js.map +1 -1
  7. package/dist/buildinschemas/docnoformat.d.ts.map +1 -1
  8. package/dist/buildinschemas/docnoformat.js +12 -25
  9. package/dist/buildinschemas/docnoformat.js.map +1 -1
  10. package/dist/buildinschemas/user.d.ts.map +1 -1
  11. package/dist/buildinschemas/user.js +1 -0
  12. package/dist/buildinschemas/user.js.map +1 -1
  13. package/dist/framework.d.ts.map +1 -1
  14. package/dist/framework.js +10 -2
  15. package/dist/framework.js.map +1 -1
  16. package/dist/generate.js +24 -13
  17. package/dist/generate.js.map +1 -1
  18. package/dist/index.js +1 -1
  19. package/dist/index.js.map +1 -1
  20. package/dist/type.d.ts +1 -0
  21. package/dist/type.d.ts.map +1 -1
  22. package/dist/type.js.map +1 -1
  23. package/package.json +1 -1
  24. package/src/buildinschemas/autoincreament.ts +1 -1
  25. package/src/buildinschemas/branch.ts +1 -1
  26. package/src/buildinschemas/docnoformat.ts +13 -27
  27. package/src/buildinschemas/user.ts +1 -0
  28. package/src/framework.ts +10 -2
  29. package/src/generate.ts +26 -13
  30. package/src/index.ts +1 -1
  31. package/src/type.ts +1 -0
  32. package/templates/basic/nest/processor.ts.eta +2 -2
  33. package/templates/basic/nest/service.ts.eta +2 -4
  34. package/templates/basic/nuxt/pages.crud.vue.eta +2 -2
  35. package/templates/nest/src/app.controller.ts.eta +6 -0
  36. package/templates/nest/src/app.module.ts.eta +9 -1
  37. package/templates/nest/src/app.service.ts.eta +6 -0
  38. package/templates/nest/src/main.ts.eta +7 -0
  39. package/templates/nest/src/simpleapp/generate/apischemas/index.ts.eta +6 -2
  40. package/templates/nest/src/simpleapp/generate/commons/audittrail.service.ts.eta +17 -0
  41. package/templates/nest/src/simpleapp/generate/commons/decorators/appuser.decorator.ts.eta +6 -0
  42. package/templates/nest/src/simpleapp/generate/commons/dicts/documents.ts.eta +14 -0
  43. package/templates/nest/src/simpleapp/generate/commons/dicts/foreignkeys.ts.eta +6 -0
  44. package/templates/nest/src/simpleapp/generate/commons/docnogenerator.service.ts.eta +9 -3
  45. package/templates/nest/src/simpleapp/generate/commons/exceptions/SimpleAppExceptionFilter.ts.eta +23 -3
  46. package/templates/nest/src/simpleapp/generate/commons/interceptors/response.interceptor.ts.eta +52 -10
  47. package/templates/nest/src/simpleapp/generate/commons/middlewares/tenant.middleware.ts.eta +6 -0
  48. package/templates/nest/src/simpleapp/generate/commons/providers/workflow.provider.ts.etax +6 -0
  49. package/templates/nest/src/simpleapp/generate/commons/roles/roles.decorator.ts.eta +6 -1
  50. package/templates/nest/src/simpleapp/generate/commons/roles/roles.enum.ts.eta +6 -0
  51. package/templates/nest/src/simpleapp/generate/commons/roles/roles.group.ts.eta +6 -0
  52. package/templates/nest/src/simpleapp/generate/commons/roles/roles.guard.ts.eta +6 -1
  53. package/templates/nest/src/simpleapp/generate/commons/user.context.ts.eta +15 -7
  54. package/templates/nest/src/simpleapp/generate/controllers/simpleapp.controller.ts.eta +6 -0
  55. package/templates/nest/src/simpleapp/generate/models/apievent.model.ts.eta +27 -0
  56. package/templates/nest/src/simpleapp/generate/models/perm.model.ts.eta +3 -4
  57. package/templates/nest/src/simpleapp/generate/models/tenant.model.ts.eta +3 -5
  58. package/templates/nest/src/simpleapp/generate/models/user.model.ts.eta +3 -4
  59. package/templates/nest/src/simpleapp/generate/processors/simpleapp.processor.ts.eta +42 -11
  60. package/templates/nest/src/simpleapp/generate/types/apievent.type.ts.eta +22 -0
  61. package/templates/nest/src/simpleapp/generate/types/index.ts.eta +6 -0
  62. package/templates/nest/src/simpleapp/profile/profile.apischema.ts.eta +6 -0
  63. package/templates/nest/src/simpleapp/profile/profile.controller.ts.eta +6 -0
  64. package/templates/nest/src/simpleapp/profile/profile.service.ts.eta +6 -0
  65. package/templates/nest/src/simpleapp/profile/profile.types.ts.eta +6 -0
  66. package/templates/nest/src/simpleapp/services/autoinc.service.ts.eta +5 -6
  67. package/templates/nest/src/simpleapp/services/branch.service.ts.eta +50 -10
  68. package/templates/nest/src/simpleapp/services/docno.service.ts.eta +5 -7
  69. package/templates/nest/src/simpleapp/services/org.service.ts.eta +4 -6
  70. package/templates/nest/src/simpleapp/services/perm.service.ts.eta +6 -7
  71. package/templates/nest/src/simpleapp/services/tenant.service.ts.eta +5 -6
  72. package/templates/nest/src/simpleapp/services/user.service.ts.eta +5 -6
  73. package/templates/nest/src/simpleapp/simpleapp.module.ts.eta +6 -8
  74. package/templates/nuxt/app.vue.eta +6 -1
  75. package/templates/nuxt/assets/css/style.css._eta +12 -0
  76. package/templates/nuxt/assets/css/tailwind.css._eta +10 -0
  77. package/templates/nuxt/assets/primevue/passthrough.ts._eta +37 -0
  78. package/templates/nuxt/components/ButtonCreateTenant.vue.eta +68 -0
  79. package/templates/nuxt/components/ButtonHome.vue.eta +10 -0
  80. package/templates/nuxt/components/ButtonLogout.vue.eta +9 -0
  81. package/templates/nuxt/components/ButtonMenuPicker.vue.eta +55 -0
  82. package/templates/nuxt/components/ButtonPermissionInfo.vue.eta +113 -0
  83. package/templates/nuxt/components/ButtonProfile.vue.eta +52 -0
  84. package/templates/nuxt/components/CrudNestedDoc.vue.eta +11 -7
  85. package/templates/nuxt/components/CrudSimple.vue.eta +13 -11
  86. package/templates/nuxt/components/DebugDocumentData.vue.eta +1 -1
  87. package/templates/nuxt/components/HeaderBar.vue.eta +39 -0
  88. package/templates/nuxt/components/Invitation.vue.eta +2 -2
  89. package/templates/nuxt/components/Menus.vue.eta +7 -7
  90. package/templates/nuxt/components/SelectBranch.vue.eta +35 -0
  91. package/templates/nuxt/components/SimpleAppAutocomplete.vue.eta +1 -1
  92. package/templates/nuxt/components/SimpleAppDatatable.vue.eta +0 -1
  93. package/templates/nuxt/components/SimpleAppDocumentNo.vue.eta +1 -1
  94. package/templates/nuxt/components/SimpleAppForm.vue.eta +1 -1
  95. package/templates/nuxt/components/SimpleAppInputTable.vue.eta +2 -2
  96. package/templates/nuxt/components/SimpleFieldContainer.vue.eta +18 -12
  97. package/templates/nuxt/components/Spinner.vue.eta +9 -0
  98. package/templates/nuxt/composables/getMenus.generate.ts.eta +5 -4
  99. package/templates/nuxt/layouts/default.vue.eta +3 -12
  100. package/templates/nuxt/middleware/{10.acl.global.ts.eta → 30.acl.global.ts.eta} +6 -0
  101. package/templates/nuxt/nuxt.config.ts.eta +55 -12
  102. package/templates/nuxt/pages/[xorg]/branch/{index.vue.eta → index.vue.etax} +1 -4
  103. package/templates/nuxt/pages/[xorg]/docnoformat/index.vue.eta +83 -113
  104. package/templates/nuxt/pages/[xorg]/index.vue._eta +13 -0
  105. package/templates/nuxt/pages/[xorg]/organization/index.vue.eta +89 -69
  106. package/templates/nuxt/pages/[xorg]/permission/index.vue.eta +7 -7
  107. package/templates/nuxt/pages/[xorg]/tenant/index.vue.eta +0 -4
  108. package/templates/nuxt/pages/[xorg]/user/index.vue.eta +33 -33
  109. package/templates/nuxt/pages/index.vue.eta +10 -85
  110. package/templates/nuxt/pages/login.vue.eta +9 -3
  111. package/templates/nuxt/plugins/10.simpleapp-event.ts.eta +16 -19
  112. package/templates/nuxt/plugins/20.simpleapp-userstore.ts.eta +19 -3
  113. package/templates/nuxt/plugins/50.simpleapp-client.ts.eta +4 -4
  114. package/templates/nuxt/server/api/[xorg]/[...].ts.eta +4 -4
  115. package/templates/nuxt/server/api/auth/[...].ts.eta +6 -0
  116. package/templates/nuxt/server/api/auth/logout.ts.eta +6 -1
  117. package/templates/nuxt/server/api/profile/[...].ts.eta +4 -5
  118. package/templates/nuxt/server/api/profile/index.ts.eta +4 -6
  119. package/templates/nuxt/simpleapp/generate/clients/SimpleAppClient.ts.eta +9 -2
  120. package/templates/nuxt/simpleapp/generate/commons/documents.ts.eta +12 -3
  121. package/templates/nuxt/simpleapp/generate/commons/events.ts.eta +6 -0
  122. package/templates/nuxt/simpleapp/generate/commons/groups.ts.eta +6 -0
  123. package/templates/nuxt/simpleapp/generate/commons/roles.ts.eta +6 -0
  124. package/templates/nuxt/tailwind.config.ts._eta +66 -0
  125. package/templates/nuxt/types/index.ts.eta +22 -1
  126. package/templates/project/build.sh.eta +4 -4
  127. package/templates/project/schemas/invoice.ts.eta +1 -0
  128. package/templates/project/schemas/product.ts.eta +1 -1
  129. package/tsconfig.tsbuildinfo +1 -1
  130. package/templates/nuxt/assets/css/tailwind.css.eta +0 -35
  131. package/templates/nuxt/components/PermissionInfo.vue.eta +0 -92
  132. package/templates/nuxt/components/XorgPicker.vue.eta +0 -66
  133. package/templates/nuxt/pages/[xorg]/index.vue.eta +0 -36
  134. package/templates/nuxt/tailwind.config.ts.eta +0 -9
  135. /package/templates/nest/{.env.eta → .env._eta} +0 -0
  136. /package/templates/nuxt/{.env.eta → .env._eta} +0 -0
  137. /package/templates/project/{config.json.eta → config.json._eta} +0 -0
@@ -1,10 +1,9 @@
1
1
  /**
2
- * todo
3
- * 1.base on xorg get current role and group
4
- * 2. get profile want to obtain branchlist and invitation list
5
- * 3. xorglist to user shall display appropriate tenant/org/branch name
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2023-10-28
5
+ * Author: Ks Tan
6
6
  */
7
-
8
7
  import { Injectable, Scope,Inject,Logger, BadRequestException } from '@nestjs/common';
9
8
  import { Model, model, connect, PipelineStage } from 'mongoose';
10
9
  import _ from 'lodash'
@@ -39,6 +38,8 @@ export class UserContext {
39
38
  protected group: string = '';
40
39
  protected branchCode: string = '';
41
40
  protected branchName: string = '';
41
+ protected orgCode: string = '';
42
+ protected orgName: string = '';
42
43
  protected branches: any[] = []
43
44
  protected invites: any[] = [] //User + field tenant:Tenant[]
44
45
  protected roles: string[] = [];
@@ -133,7 +134,8 @@ export class UserContext {
133
134
  orgId:this.orgId,
134
135
  branchId:this.branchId,
135
136
  }},
136
- {$lookup:{from: 'branch',localField: 'branchId',foreignField:'branchId',as: 'currentbranch'}}
137
+ {$lookup:{from: 'branch',localField: 'branchId',foreignField:'branchId',as: 'currentbranch'}},
138
+ {$lookup:{from: 'organization',localField: 'orgId',foreignField:'orgId',as: 'currentorg'}}
137
139
  ]
138
140
  }}
139
141
 
@@ -160,6 +162,8 @@ export class UserContext {
160
162
  userinfo.roles = rolegroups[userinfo.group]
161
163
  userinfo.branchCode = myperm.currentbranch[0].branchCode
162
164
  userinfo.branchName = myperm.currentbranch[0].branchName
165
+ userinfo.orgCode = myperm.currentorg[0].orgCode
166
+ userinfo.orgName = myperm.currentorg[0].orgName
163
167
  }
164
168
  }else{
165
169
  userinfo.group = ''
@@ -192,6 +196,8 @@ export class UserContext {
192
196
  this._id = userinfo._id.toString()
193
197
  this.branchCode = userinfo['branchCode'] ?? ''
194
198
  this.branchName = userinfo['branchName'] ?? ''
199
+ this.orgCode = userinfo['orgCode'] ?? ''
200
+ this.orgName = userinfo['orgName'] ?? ''
195
201
  this.group = userinfo['group'] ?? ''
196
202
  this.roles = userinfo['roles'] ?? [Role.Everyone,Role.User]
197
203
  }else{
@@ -199,7 +205,7 @@ export class UserContext {
199
205
  // this.group = ''
200
206
  // this.tenantId=0
201
207
  // this.orgId=0
202
- // this.branchId=0
208
+ // this.orgCode=0
203
209
  this.roles = [Role.Everyone,Role.Unknown]
204
210
  }
205
211
  this.logger.debug(`${this.uid} have _id (${this.getId()}), group (${this.group}) and role (${this.getRoles()})` )
@@ -289,6 +295,8 @@ export class UserContext {
289
295
  branchId: this.getBranchId(),
290
296
  branchCode: this.branchCode,
291
297
  branchName: this.branchName,
298
+ orgCode:this.orgCode,
299
+ orgName:this.orgName,
292
300
  email: this.getEmail(),
293
301
  uid: this.getUid(),
294
302
  fullName: this.getFullname(),
@@ -1,3 +1,9 @@
1
+ /**
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2023-10-28
5
+ * Author: Ks Tan
6
+ */
1
7
  import {
2
8
  Controller,
3
9
  Get,
@@ -0,0 +1,27 @@
1
+ /**
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2023-10-28
5
+ * Author: Ks Tan
6
+ */
7
+
8
+ import { Schema } from 'mongoose';
9
+ import { BranchOrganization, Branch, } from '../types/branch.type';
10
+ const schemasetting = {
11
+ _id: {type:String},
12
+ created: {type: String},
13
+ updated: {type: String},
14
+ duration:{type: Number},
15
+ createdby: {type: String},
16
+ path:{type:String},
17
+ ip:{type:String},
18
+ method:{type:String},
19
+ headers:{type: Object},
20
+ data: {type: Object},
21
+ statusCode: {type: Number},
22
+ status:{type:String},
23
+ errMsg:{type:String},
24
+ errData: {type: Object},
25
+ };
26
+
27
+ export const ApiEventMongoSchema = new Schema(schemasetting,{collection: 'apievent'})
@@ -1,8 +1,7 @@
1
1
  /**
2
- * This file was automatically generated by simpleapp generator.
3
- * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
4
- * and regenerate this file.
5
- * last change 2023-09-09
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2023-10-28
6
5
  * Author: Ks Tan
7
6
  */
8
7
 
@@ -1,11 +1,9 @@
1
1
  /**
2
- * This file was automatically generated by simpleapp generator.
3
- * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
4
- * and regenerate this file.
5
- * last change 2023-09-09
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2023-10-28
6
5
  * Author: Ks Tan
7
6
  */
8
-
9
7
  import { Schema } from 'mongoose';
10
8
  import { TenantOwner, Tenant } from '../types/tenant.type';
11
9
  const schemasetting = {
@@ -1,8 +1,7 @@
1
1
  /**
2
- * This file was automatically generated by simpleapp generator.
3
- * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
4
- * and regenerate this file.
5
- * last change 2023-09-09
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2023-10-28
6
5
  * Author: Ks Tan
7
6
  */
8
7
 
@@ -1,8 +1,14 @@
1
+ /**
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2023-10-28
5
+ * Author: Ks Tan
6
+ */
1
7
  import { Injectable, Logger,Inject } from '@nestjs/common';
2
8
  import { InjectModel } from '@nestjs/mongoose';
3
9
  import * as jsonpath from 'jsonpath'
4
10
  import { uniq } from 'lodash';
5
-
11
+ import { AuditTrail } from '../commons/audittrail.service';
6
12
  import {foreignkeys} from '../commons/dicts/foreignkeys'
7
13
  import { Model,Types,PipelineStage,mongo, FilterQuery, ProjectionType} from 'mongoose';
8
14
  import Ajv from 'ajv';
@@ -60,14 +66,21 @@ export class SimpleAppService<T extends { _id?: string }> {
60
66
  protected errorlist = [];
61
67
  protected withDocNumberFormat=false
62
68
  protected foreignkeys = {}
69
+
70
+ @Inject(AuditTrail)
71
+ protected audittrail: AuditTrail
72
+
73
+ @Inject(DocNumberFormatGenerator)
74
+ protected docnogenerator: DocNumberFormatGenerator
75
+
76
+
63
77
  // protected userprovider = new UserContext() ;
64
78
 
65
79
  constructor(
66
80
  doctype: string,
67
81
  docname: string,
68
82
  newdoc: Model<T>,
69
- isolationtype: IsolationType = IsolationType.org,
70
- private docnogenerator:DocNumberFormatGenerator
83
+ isolationtype: IsolationType = IsolationType.org
71
84
  ) {
72
85
  // console.log("-------init simpleapp service abstract class -------userprovider=",typeof this.userprovider)
73
86
  this.documentType = doctype.toUpperCase();
@@ -251,10 +264,16 @@ export class SimpleAppService<T extends { _id?: string }> {
251
264
 
252
265
 
253
266
  async create(appuser:UserContext, data:T) {
267
+ this.audittrail.addEvent(data)
254
268
  let result;
255
269
  if(!data._id){
256
270
  data._id = crypto.randomUUID()
257
271
  }
272
+ const dbsession = appuser.getDBSession()
273
+ if(!dbsession.inTransaction()){
274
+ dbsession.startTransaction()
275
+ }
276
+
258
277
 
259
278
  this.logger.debug('this.withDocNumberFormat :' + this.withDocNumberFormat + ' && ' + '!data[this.documentIdentityCode] ==' + !data[this.documentIdentityCode])
260
279
  if(this.withDocNumberFormat && !data[this.documentIdentityCode]){
@@ -280,7 +299,7 @@ export class SimpleAppService<T extends { _id?: string }> {
280
299
  const newdoc = new this.doc(data);
281
300
 
282
301
  try{
283
- result = await newdoc.save({session:appuser.getDBSession()})
302
+ result = await newdoc.save({session:dbsession})
284
303
  }catch(err){
285
304
  this.logger.error(err)
286
305
  throw new InternalServerErrorException(err)
@@ -392,6 +411,11 @@ export class SimpleAppService<T extends { _id?: string }> {
392
411
  }
393
412
  async findIdThenDelete(appuser:UserContext,id: string): Promise<any> {
394
413
  const deletedata = await this.findById(appuser,id);
414
+ const dbsession = appuser.getDBSession()
415
+ if(!dbsession.inTransaction()){
416
+ dbsession.startTransaction()
417
+ }
418
+
395
419
  let dependency
396
420
  try {
397
421
  await this.hook(appuser,HookType.beforeDelete, id);
@@ -404,7 +428,7 @@ export class SimpleAppService<T extends { _id?: string }> {
404
428
 
405
429
  filterIsolation['_id'] = id;
406
430
  this.logger.debug('delete filter', filterIsolation);
407
- const result = await this.doc.deleteOne(filterIsolation).session(appuser.getDBSession());
431
+ const result = await this.doc.deleteOne(filterIsolation).session(dbsession);
408
432
  const deleteresult = {result:result, data: deletedata}
409
433
  this.logger.debug(deleteresult, " delete result" +this.doc.collection.name,)
410
434
  // this.doc.findByIdAndDelete(id)
@@ -431,6 +455,12 @@ export class SimpleAppService<T extends { _id?: string }> {
431
455
  findIdThenUpdate = async (appuser:UserContext,id: string, data: T,session:mongo.ClientSession=undefined) => {
432
456
  const existingdata = await this.findById(appuser,id);
433
457
  await this.hook(appuser,HookType.beforeUpdate, data);
458
+
459
+ const dbsession = appuser.getDBSession()
460
+ if(!dbsession.inTransaction()){
461
+ dbsession.startTransaction()
462
+ }
463
+
434
464
  // try {
435
465
  Object.assign(data, appuser.getUpdateFilter());
436
466
  Object.assign(existingdata, data);
@@ -444,12 +474,13 @@ export class SimpleAppService<T extends { _id?: string }> {
444
474
 
445
475
  isolationFilter['_id'] = id;
446
476
  this.applyNestedDateTime(appuser,data,'update')
447
- const result = await this.doc.findOneAndUpdate(isolationFilter, data).session(appuser.getDBSession());
448
- await this.hook(appuser,HookType.afterUpdate, data);
449
- return result;
450
- // } catch (err) {
451
- // throw new InternalServerErrorException(err.message);
452
- // }
477
+ try{
478
+ const result = await this.doc.findOneAndUpdate(isolationFilter, data).session(dbsession);
479
+ await this.hook(appuser,HookType.afterUpdate, data);
480
+ return result;
481
+ } catch (err) {
482
+ throw new InternalServerErrorException(err.message);
483
+ }
453
484
  };
454
485
 
455
486
  //find what foreign key constraint
@@ -0,0 +1,22 @@
1
+ /**
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2023-10-28
5
+ * Author: Ks Tan
6
+ */
7
+ export type ApiEvent = {
8
+ _id: string
9
+ created: string
10
+ updated?:string
11
+ duration: number
12
+ createdby: string
13
+ path: string
14
+ ip: string
15
+ method: string
16
+ headers: any
17
+ data?: any
18
+ statusCode:number
19
+ status:string
20
+ errMsg?:string
21
+ errData?: any
22
+ }
@@ -1,3 +1,9 @@
1
+ /**
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2023-10-28
5
+ * Author: Ks Tan
6
+ */
1
7
  export type ForeignKey = {
2
8
  _id: string
3
9
  label: string
@@ -1,3 +1,9 @@
1
+ /**
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2023-10-28
5
+ * Author: Ks Tan
6
+ */
1
7
  import { ApiProperty } from '@nestjs/swagger';
2
8
  import {ProfileUserInvites,ProfileUserBranch} from './profile.types'
3
9
  export class RegTenantApiSchema {
@@ -1,3 +1,9 @@
1
+ /**
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2023-10-28
5
+ * Author: Ks Tan
6
+ */
1
7
  import {
2
8
  Controller,
3
9
  Get,
@@ -1,3 +1,9 @@
1
+ /**
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2023-10-28
5
+ * Author: Ks Tan
6
+ */
1
7
  import { UserService, User } from './../services/user.service';
2
8
  import {
3
9
  Injectable,
@@ -1,3 +1,9 @@
1
+ /**
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2023-10-28
5
+ * Author: Ks Tan
6
+ */
1
7
  export type RegTenant = {
2
8
  tenantName: string;
3
9
  };
@@ -1,14 +1,14 @@
1
1
  /**
2
- * This file was automatically generated by simpleapp generator.
3
- * It will not override by generator
4
- * last change 2023-09-23
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2023-10-28
5
5
  * Author: Ks Tan
6
6
  */
7
7
  import { InjectModel } from '@nestjs/mongoose';
8
8
  import { Model } from 'mongoose';
9
9
  import { Injectable } from '@nestjs/common';
10
10
  import { AutoincreamentProcessor } from '../generate/processors/autoinc.processor';
11
- import { DocNumberFormatGenerator } from '../generate/commons/docnogenerator.service';
11
+
12
12
  import { Autoincreament } from '../generate/types/autoinc.type';
13
13
  import { UserContext } from '../generate/commons/user.context';
14
14
  export { Autoincreament } from '../generate/types/autoinc.type';
@@ -17,9 +17,8 @@ export { Autoincreament } from '../generate/types/autoinc.type';
17
17
  export class AutoincreamentService extends AutoincreamentProcessor {
18
18
  constructor(
19
19
  @InjectModel('Autoincreament') mydoc: Model<Autoincreament>,
20
- docnogenerator: DocNumberFormatGenerator,
21
20
  ) {
22
- super(mydoc,docnogenerator);
21
+ super(mydoc);
23
22
  }
24
23
 
25
24
  // hook = async (appuser:UserContext,type: string, data?: any) => {
@@ -1,27 +1,29 @@
1
1
  /**
2
- * This file was automatically generated by simpleapp generator.
3
- * It will not override by generator
4
- * last change 2023-09-23
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2023-10-28
5
5
  * Author: Ks Tan
6
6
  */
7
7
  import { InjectModel } from '@nestjs/mongoose';
8
8
  import { Model } from 'mongoose';
9
- import { Injectable } from '@nestjs/common';
9
+ import { Injectable, InternalServerErrorException } from '@nestjs/common';
10
10
  import { BranchProcessor } from '../generate/processors/branch.processor';
11
11
  import { Branch } from '../generate/types/branch.type';
12
+ import {alldocuments} from '../generate/commons/dicts/documents'
12
13
  export { Branch } from '../generate/types/branch.type';
13
14
  import { AutoincreamentService } from './autoinc.service';
14
15
  import { UserContext } from '../generate/commons/user.context';
15
- import { DocNumberFormatGenerator } from '../generate/commons/docnogenerator.service';
16
+ import { Docnoformat,DocnoformatService } from './docno.service';
17
+ // import { Docnoformat } from '../generate/types/docno.type';
16
18
  @Injectable()
17
19
  export class BranchService extends BranchProcessor {
18
20
  protected strictIsolation = false;
19
21
  constructor(
20
22
  @InjectModel('Branch') mydoc: Model<Branch>,
21
- private increament: AutoincreamentService,
22
- docnogenerator: DocNumberFormatGenerator,
23
+ private increament: AutoincreamentService,
24
+ private docnoservice:DocnoformatService
23
25
  ) {
24
- super(mydoc,docnogenerator);
26
+ super(mydoc);
25
27
  }
26
28
 
27
29
  hook = async (appuser: UserContext, type: string, data?: any) => {
@@ -44,8 +46,9 @@ export class BranchService extends BranchProcessor {
44
46
  );
45
47
  data.branchId = searchresult.nextno;
46
48
  break;
47
- // case 'afterCreate':
48
- // break;
49
+ case 'afterCreate':
50
+ await this.generateDefaultDocNumbers(appuser,data);
51
+ break;
49
52
  // case 'beforeUpdate':
50
53
  // break;
51
54
  // case 'afterUpdate':
@@ -63,4 +66,41 @@ export class BranchService extends BranchProcessor {
63
66
  }
64
67
  return true;
65
68
  };
69
+
70
+ generateDefaultDocNumbers =async (appuser,data) => {
71
+ const branchName = data.branchName
72
+ const branchCode = data.branchCode
73
+ const recordId = data._id
74
+ const branchId= data.branchId
75
+ const orgId = data.orgId
76
+ const tenantId = data.tenantId
77
+ const docformats = alldocuments.filter((item)=>item.docNumber)
78
+ for(let i=0; i< docformats.length; i++){
79
+ const doc = docformats[i]
80
+ const pattern = `${doc.docType}-${branchCode}-[00000]`
81
+ const formatdata:Docnoformat = {
82
+ _id:crypto.randomUUID(),
83
+ docNoFormatNo:'Default',
84
+ docNoFormatName:'Default',
85
+ docNoType: doc.docType,
86
+ docNoPattern: pattern,
87
+ branch:{_id:recordId,branchId:branchId,label:branchName},
88
+ branchId:branchId,
89
+ orgId:orgId,
90
+ tenantId:tenantId,
91
+ nextNumber:1,
92
+ } as Docnoformat
93
+ try{
94
+ const result = await this.docnoservice.create(appuser,formatdata)
95
+ if(!result){
96
+ throw new InternalServerErrorException(`Generate default document number for "${branchCode}" failed. Pattern: ${pattern}`,'generateDefaultDocNumbers')
97
+ }
98
+
99
+ }catch(err){
100
+ this.logger.error(err)
101
+ throw new InternalServerErrorException(err)
102
+ }
103
+
104
+ }
105
+ }
66
106
  }
@@ -1,8 +1,7 @@
1
- import { BadRequestException } from '@nestjs/common';
2
1
  /**
3
- * This file was automatically generated by simpleapp generator.
4
- * It will not override by generator
5
- * last change 2023-09-23
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2023-10-28
6
5
  * Author: Ks Tan
7
6
  */
8
7
  import { InjectModel } from '@nestjs/mongoose';
@@ -17,11 +16,11 @@ export { Docnoformat } from '../generate/types/docno.type';
17
16
 
18
17
  @Injectable()
19
18
  export class DocnoformatService extends DocnoformatProcessor {
19
+ protected strictIsolation = false;
20
20
  constructor(
21
21
  @InjectModel('Docnoformat') mydoc: Model<Docnoformat>,
22
- docnogenerator: DocNumberFormatGenerator,
23
22
  ) {
24
- super(mydoc, docnogenerator);
23
+ super(mydoc);
25
24
  }
26
25
 
27
26
  // hook = async (type: string, data?: any) => {
@@ -82,7 +81,6 @@ export class DocnoformatService extends DocnoformatProcessor {
82
81
  docNoFormatNo: s.docNoFormatNo,
83
82
  docNoFormatName: s.docNoFormatName,
84
83
  docNoPattern: s.docNoPattern,
85
- isMonthly: s.isMonthly,
86
84
  nextNumber: s.nextNumber,
87
85
  default: s.default,
88
86
  sample: DocNumberFormatGenerator.previewDocNo(s),
@@ -1,7 +1,7 @@
1
1
  /**
2
- * This file was automatically generated by simpleapp generator.
3
- * It will not override by generator
4
- * last change 2023-09-23
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2023-10-28
5
5
  * Author: Ks Tan
6
6
  */
7
7
  import { InjectModel } from '@nestjs/mongoose';
@@ -11,7 +11,6 @@ import { OrganizationProcessor } from '../generate/processors/org.processor';
11
11
  import { Organization } from '../generate/types/org.type';
12
12
  export { Organization } from '../generate/types/org.type';
13
13
  import { AutoincreamentService } from './autoinc.service';
14
- import { DocNumberFormatGenerator } from '../generate/commons/docnogenerator.service';
15
14
  import { UserContext } from '../generate/commons/user.context';
16
15
 
17
16
  @Injectable()
@@ -20,9 +19,8 @@ export class OrganizationService extends OrganizationProcessor {
20
19
  constructor(
21
20
  @InjectModel('Organization') mydoc: Model<Organization>,
22
21
  private increament: AutoincreamentService,
23
- docnogenerator: DocNumberFormatGenerator,
24
22
  ) {
25
- super(mydoc,docnogenerator);
23
+ super(mydoc);
26
24
  }
27
25
 
28
26
  hook = async (appuser: UserContext, type: string, data?: any) => {
@@ -1,7 +1,7 @@
1
1
  /**
2
- * This file was automatically generated by simpleapp generator.
3
- * It will not override by generator
4
- * last change 2023-09-23
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2023-10-28
5
5
  * Author: Ks Tan
6
6
  */
7
7
  import { InjectModel } from '@nestjs/mongoose';
@@ -10,17 +10,16 @@ import { Injectable } from '@nestjs/common';
10
10
  import { PermissionProcessor } from '../generate/processors/perm.processor';
11
11
  import { Permission } from '../generate/types/perm.type';
12
12
  import { UserContext } from '../generate/commons/user.context';
13
- import { DocNumberFormatGenerator } from '../generate/commons/docnogenerator.service';
13
+
14
14
  export { Permission } from '../generate/types/perm.type';
15
15
 
16
16
  @Injectable()
17
17
  export class PermissionService extends PermissionProcessor {
18
18
  protected strictIsolation = false;
19
19
  constructor(
20
- @InjectModel('Permission') mydoc: Model<Permission>,
21
- docnogenerator: DocNumberFormatGenerator,
20
+ @InjectModel('Permission') mydoc: Model<Permission>,
22
21
  ) {
23
- super(mydoc,docnogenerator);
22
+ super(mydoc);
24
23
  }
25
24
 
26
25
  hook = async (appuser: UserContext, type: string, data?: any) => {
@@ -1,7 +1,7 @@
1
1
  /**
2
- * This file was automatically generated by simpleapp generator.
3
- * It will not override by generator
4
- * last change 2023-09-23
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2023-10-28
5
5
  * Author: Ks Tan
6
6
  */
7
7
 
@@ -12,7 +12,6 @@ import { TenantProcessor } from '../generate/processors/tenant.processor';
12
12
  import { Tenant } from '../generate/types/tenant.type';
13
13
  import { AutoincreamentService } from './autoinc.service';
14
14
  import { UserContext } from '../generate/commons/user.context';
15
- import { DocNumberFormatGenerator } from '../generate/commons/docnogenerator.service';
16
15
  export { Tenant } from '../generate/types/tenant.type';
17
16
 
18
17
  @Injectable()
@@ -20,9 +19,9 @@ export class TenantService extends TenantProcessor {
20
19
  constructor(
21
20
  @InjectModel('Tenant') mydoc: Model<Tenant>,
22
21
  private increament: AutoincreamentService,
23
- docnogenerator: DocNumberFormatGenerator,
22
+
24
23
  ) {
25
- super(mydoc,docnogenerator);
24
+ super(mydoc);
26
25
  }
27
26
 
28
27
  hook = async (appuser: UserContext, type: string, data?: any) => {
@@ -1,7 +1,7 @@
1
1
  /**
2
- * This file was automatically generated by simpleapp generator.
3
- * It will not override by generator
4
- * last change 2023-09-23
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2023-10-28
5
5
  * Author: Ks Tan
6
6
  */
7
7
  import { InjectModel } from '@nestjs/mongoose';
@@ -11,7 +11,7 @@ import { Injectable } from '@nestjs/common';
11
11
  import { UserProcessor } from '../generate/processors/user.processor';
12
12
  import { Permission } from '../generate/types/perm.type';
13
13
  import { User } from '../generate/types/user.type';
14
- import { DocNumberFormatGenerator } from '../generate/commons/docnogenerator.service';
14
+
15
15
  export { User } from '../generate/types/user.type';
16
16
 
17
17
 
@@ -21,9 +21,8 @@ export class UserService extends UserProcessor {
21
21
  constructor(
22
22
  @InjectModel('User') mydoc: Model<User>,
23
23
  @InjectModel('Permission') private permdoc: Model<Permission>,
24
- docnogenerator: DocNumberFormatGenerator,
25
24
  ) {
26
- super(mydoc,docnogenerator);
25
+ super(mydoc);
27
26
  }
28
27
 
29
28
  hook = async (appuser: UserContext, type: string, data?: any) => {
@@ -1,15 +1,13 @@
1
-
2
1
  /**
3
- * This file was automatically generated by simpleapp generator.
4
- * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
5
- * and regenerate this file.
6
- * last change 2023-09-09
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2023-10-28
7
5
  * Author: Ks Tan
8
6
  */
9
7
  import { Module } from '@nestjs/common';
10
8
  import { MongooseModule } from '@nestjs/mongoose';
11
9
  import {DocNumberFormatGenerator} from './generate/commons/docnogenerator.service'
12
-
10
+ import { AuditTrail } from './generate/commons/audittrail.service';
13
11
  // auto import modules
14
12
  <% for(let i=0;i<it.modules.length; i++){ %>
15
13
  <% let obj = it.modules[i]%>
@@ -37,7 +35,7 @@ import { ProfileService } from './profile/profile.service';
37
35
  ]),
38
36
  ],
39
37
  controllers: [<% for(let i=0;i<it.modules.length; i++){ %><%= it.modules[i].docname %>Controller,<%}%> ProfileController],
40
- providers: [DocNumberFormatGenerator,<% for(let i=0;i<it.modules.length; i++){ %><%= it.modules[i].docname %>Service,<%}%> ProfileService,],
41
- exports:[DocNumberFormatGenerator,<% for(let i=0;i<it.modules.length; i++){ %><%= it.modules[i].docname %>Service,<%}%> ProfileService,]
38
+ providers: [AuditTrail,DocNumberFormatGenerator,<% for(let i=0;i<it.modules.length; i++){ %><%= it.modules[i].docname %>Service,<%}%> ProfileService,],
39
+ exports:[AuditTrail,DocNumberFormatGenerator,<% for(let i=0;i<it.modules.length; i++){ %><%= it.modules[i].docname %>Service,<%}%> ProfileService,]
42
40
  })
43
41
  export class GenerateModule {}