@simitgroup/simpleapp-generator 1.0.46 → 1.0.48

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 (147) hide show
  1. package/README.md +35 -1
  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 +11 -3
  15. package/dist/framework.js.map +1 -1
  16. package/dist/generate.js +33 -22
  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/processors/jsonschemabuilder.d.ts.map +1 -1
  21. package/dist/processors/jsonschemabuilder.js +10 -0
  22. package/dist/processors/jsonschemabuilder.js.map +1 -1
  23. package/dist/type.d.ts +115 -22
  24. package/dist/type.d.ts.map +1 -1
  25. package/dist/type.js.map +1 -1
  26. package/package.json +1 -1
  27. package/src/buildinschemas/autoincreament.ts +1 -1
  28. package/src/buildinschemas/branch.ts +1 -1
  29. package/src/buildinschemas/docnoformat.ts +13 -27
  30. package/src/buildinschemas/user.ts +1 -0
  31. package/src/framework.ts +11 -3
  32. package/src/generate.ts +35 -22
  33. package/src/index.ts +1 -1
  34. package/src/processors/jsonschemabuilder.ts +14 -1
  35. package/src/type.ts +137 -22
  36. package/templates/basic/nest/processor.ts.eta +5 -3
  37. package/templates/basic/nest/service.ts.eta +2 -4
  38. package/templates/basic/nuxt/pages.crud.vue.eta +3 -2
  39. package/templates/basic/nuxt/simpleapp.generate.client.ts.eta +18 -2
  40. package/templates/nest/src/app.controller.ts.eta +6 -0
  41. package/templates/nest/src/app.module.ts.eta +9 -1
  42. package/templates/nest/src/app.service.ts.eta +6 -0
  43. package/templates/nest/src/main.ts.eta +7 -0
  44. package/templates/nest/src/simpleapp/generate/apischemas/index.ts.eta +6 -2
  45. package/templates/nest/src/simpleapp/generate/commons/audittrail.service.ts.eta +17 -0
  46. package/templates/nest/src/simpleapp/generate/commons/decorators/appuser.decorator.ts.eta +6 -0
  47. package/templates/nest/src/simpleapp/generate/commons/dicts/documents.ts.eta +14 -0
  48. package/templates/nest/src/simpleapp/generate/commons/dicts/foreignkeys.ts.eta +6 -0
  49. package/templates/nest/src/simpleapp/generate/commons/docnogenerator.service.ts.eta +9 -3
  50. package/templates/nest/src/simpleapp/generate/commons/exceptions/SimpleAppExceptionFilter.ts.eta +23 -3
  51. package/templates/nest/src/simpleapp/generate/commons/interceptors/response.interceptor.ts.eta +52 -10
  52. package/templates/nest/src/simpleapp/generate/commons/middlewares/tenant.middleware.ts.eta +6 -0
  53. package/templates/nest/src/simpleapp/generate/commons/providers/workflow.provider.ts.etax +6 -0
  54. package/templates/nest/src/simpleapp/generate/commons/roles/roles.decorator.ts.eta +6 -1
  55. package/templates/nest/src/simpleapp/generate/commons/roles/roles.enum.ts.eta +6 -0
  56. package/templates/nest/src/simpleapp/generate/commons/roles/roles.group.ts.eta +6 -0
  57. package/templates/nest/src/simpleapp/generate/commons/roles/roles.guard.ts.eta +6 -1
  58. package/templates/nest/src/simpleapp/generate/commons/user.context.ts.eta +15 -7
  59. package/templates/nest/src/simpleapp/generate/controllers/simpleapp.controller.ts.eta +6 -0
  60. package/templates/nest/src/simpleapp/generate/models/apievent.model.ts.eta +27 -0
  61. package/templates/nest/src/simpleapp/generate/models/perm.model.ts.eta +3 -4
  62. package/templates/nest/src/simpleapp/generate/models/tenant.model.ts.eta +3 -5
  63. package/templates/nest/src/simpleapp/generate/models/user.model.ts.eta +3 -4
  64. package/templates/nest/src/simpleapp/generate/processors/simpleapp.processor.ts.eta +54 -12
  65. package/templates/nest/src/simpleapp/generate/types/apievent.type.ts.eta +22 -0
  66. package/templates/nest/src/simpleapp/generate/types/index.ts.eta +6 -0
  67. package/templates/nest/src/simpleapp/profile/profile.apischema.ts.eta +6 -0
  68. package/templates/nest/src/simpleapp/profile/profile.controller.ts.eta +6 -0
  69. package/templates/nest/src/simpleapp/profile/profile.service.ts.eta +6 -0
  70. package/templates/nest/src/simpleapp/profile/profile.types.ts.eta +6 -0
  71. package/templates/nest/src/simpleapp/services/autoinc.service.ts.eta +5 -6
  72. package/templates/nest/src/simpleapp/services/branch.service.ts.eta +50 -10
  73. package/templates/nest/src/simpleapp/services/docno.service.ts.eta +9 -10
  74. package/templates/nest/src/simpleapp/services/org.service.ts.eta +4 -6
  75. package/templates/nest/src/simpleapp/services/perm.service.ts.eta +6 -7
  76. package/templates/nest/src/simpleapp/services/tenant.service.ts.eta +5 -6
  77. package/templates/nest/src/simpleapp/services/user.service.ts.eta +5 -6
  78. package/templates/nest/src/simpleapp/simpleapp.module.ts.eta +6 -8
  79. package/templates/nuxt/app.vue.eta +6 -1
  80. package/templates/nuxt/assets/css/style.css._eta +12 -0
  81. package/templates/nuxt/assets/css/tailwind.css._eta +10 -0
  82. package/templates/nuxt/assets/primevue/passthrough.ts._eta +37 -0
  83. package/templates/nuxt/components/ButtonCreateTenant.vue.eta +68 -0
  84. package/templates/nuxt/components/ButtonHome.vue.eta +10 -0
  85. package/templates/nuxt/components/ButtonLogout.vue.eta +9 -0
  86. package/templates/nuxt/components/ButtonMenuPicker.vue.eta +55 -0
  87. package/templates/nuxt/components/ButtonPermissionInfo.vue.eta +113 -0
  88. package/templates/nuxt/components/ButtonProfile.vue.eta +52 -0
  89. package/templates/nuxt/components/CrudNestedDoc.vue.eta +16 -8
  90. package/templates/nuxt/components/CrudSimple.vue.eta +13 -11
  91. package/templates/nuxt/components/DebugDocumentData.vue.eta +1 -1
  92. package/templates/nuxt/components/HeaderBar.vue.eta +39 -0
  93. package/templates/nuxt/components/Invitation.vue.eta +2 -2
  94. package/templates/nuxt/components/ListView.vue.eta +52 -0
  95. package/templates/nuxt/components/Menus.vue.eta +6 -6
  96. package/templates/nuxt/components/SelectBranch.vue.eta +35 -0
  97. package/templates/nuxt/components/SimpleAppDatatable.vue.eta +0 -1
  98. package/templates/nuxt/components/SimpleAppDocumentNo.vue.eta +2 -2
  99. package/templates/nuxt/components/SimpleAppInputTable.vue.eta +2 -2
  100. package/templates/nuxt/components/SimpleFieldContainer.vue.eta +18 -12
  101. package/templates/nuxt/components/Spinner.vue.eta +9 -0
  102. package/templates/nuxt/composables/getMenus.generate.ts.eta +5 -4
  103. package/templates/nuxt/layouts/default.vue.eta +3 -12
  104. package/templates/nuxt/layouts/sidelistcrud.vue.eta +43 -0
  105. package/templates/nuxt/middleware/{10.acl.global.ts.eta → 30.acl.global.ts.eta} +6 -0
  106. package/templates/nuxt/nuxt.config.ts.eta +55 -12
  107. package/templates/nuxt/pages/[xorg]/docnoformat/index.vue.eta +274 -247
  108. package/templates/nuxt/pages/[xorg]/index.vue._eta +13 -0
  109. package/templates/nuxt/pages/[xorg]/organization/index.vue.eta +89 -65
  110. package/templates/nuxt/pages/[xorg]/permission/index.vue.eta +7 -7
  111. package/templates/nuxt/pages/[xorg]/user/index.vue.eta +33 -33
  112. package/templates/nuxt/pages/index.vue.eta +10 -85
  113. package/templates/nuxt/pages/login.vue.eta +9 -3
  114. package/templates/nuxt/plugins/10.simpleapp-event.ts.eta +16 -19
  115. package/templates/nuxt/plugins/20.simpleapp-userstore.ts.eta +19 -3
  116. package/templates/nuxt/plugins/50.simpleapp-client.ts.eta +4 -4
  117. package/templates/nuxt/server/api/[xorg]/[...].ts.eta +4 -4
  118. package/templates/nuxt/server/api/auth/[...].ts.eta +6 -0
  119. package/templates/nuxt/server/api/auth/logout.ts.eta +6 -1
  120. package/templates/nuxt/server/api/profile/[...].ts.eta +4 -5
  121. package/templates/nuxt/server/api/profile/index.ts.eta +4 -6
  122. package/templates/nuxt/simpleapp/generate/clients/SimpleAppClient.ts.eta +9 -2
  123. package/templates/nuxt/simpleapp/generate/commons/documents.ts.eta +12 -3
  124. package/templates/nuxt/simpleapp/generate/commons/events.ts.eta +6 -0
  125. package/templates/nuxt/simpleapp/generate/commons/groups.ts.eta +6 -0
  126. package/templates/nuxt/simpleapp/generate/commons/roles.ts.eta +6 -0
  127. package/templates/nuxt/tailwind.config.ts._eta +66 -0
  128. package/templates/nuxt/types/index.ts.eta +22 -1
  129. package/templates/project/build.sh.eta +4 -4
  130. package/templates/project/schemas/category.ts.eta +40 -27
  131. package/templates/project/schemas/customer.ts.eta +35 -0
  132. package/templates/project/schemas/index.ts.eta +4 -4
  133. package/templates/project/schemas/invoice.ts.eta +56 -0
  134. package/templates/project/schemas/product.ts.eta +41 -57
  135. package/templates/project/sharelibs/index.ts.eta +2 -0
  136. package/templates/project/sharelibs/money.ts.eta +17 -0
  137. package/tsconfig.tsbuildinfo +1 -1
  138. package/templates/nuxt/assets/css/tailwind.css.eta +0 -35
  139. package/templates/nuxt/components/PermissionInfo.vue.eta +0 -92
  140. package/templates/nuxt/pages/[xorg]/index.vue.eta +0 -36
  141. package/templates/nuxt/tailwind.config.ts.eta +0 -9
  142. package/templates/project/shares/index.ts.eta +0 -2
  143. /package/templates/nest/{.env.eta → .env._eta} +0 -0
  144. /package/templates/nuxt/{.env.eta → .env._eta} +0 -0
  145. /package/templates/nuxt/pages/[xorg]/branch/{index.vue.eta → index.vue.etax} +0 -0
  146. /package/templates/project/{config.json.eta → config.json._eta} +0 -0
  147. /package/templates/project/{shares → sharelibs}/hello.ts.eta +0 -0
@@ -1,4 +1,9 @@
1
-
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
+ */
2
7
  import { Injectable, Inject, CanActivate, ExecutionContext, Scope } from '@nestjs/common';
3
8
  import { Reflector } from '@nestjs/core';
4
9
  import { Role } from './roles.enum'
@@ -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,18 @@ 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
+
277
+
278
+ this.logger.debug('this.withDocNumberFormat :' + this.withDocNumberFormat + ' && ' + '!data[this.documentIdentityCode] ==' + !data[this.documentIdentityCode])
258
279
  if(this.withDocNumberFormat && !data[this.documentIdentityCode]){
259
280
  await this.genNewDocNo(appuser,data)
260
281
  }
@@ -277,7 +298,14 @@ export class SimpleAppService<T extends { _id?: string }> {
277
298
  this.applyNestedDateTime(appuser,data,'create')
278
299
  const newdoc = new this.doc(data);
279
300
 
280
- result = await newdoc.save({session:appuser.getDBSession()})
301
+ try{
302
+ result = await newdoc.save({session:dbsession})
303
+ }catch(err){
304
+ this.logger.error(err)
305
+ throw new InternalServerErrorException(err)
306
+ }
307
+
308
+
281
309
 
282
310
  // this.doc.create(data)
283
311
  // this.doc
@@ -327,7 +355,7 @@ export class SimpleAppService<T extends { _id?: string }> {
327
355
 
328
356
  ajv.addKeyword({ keyword: 'x-foreignkey', schemaType: 'string' });
329
357
  ajv.addKeyword({ keyword: 'x-simpleapp-config', schemaType: 'object' });
330
-
358
+
331
359
  const issuccess = await this.hook(appuser,HookType.beforeValidation, data);
332
360
  if (!issuccess) {
333
361
  const errormsg: string[] = [];
@@ -383,6 +411,11 @@ export class SimpleAppService<T extends { _id?: string }> {
383
411
  }
384
412
  async findIdThenDelete(appuser:UserContext,id: string): Promise<any> {
385
413
  const deletedata = await this.findById(appuser,id);
414
+ const dbsession = appuser.getDBSession()
415
+ if(!dbsession.inTransaction()){
416
+ dbsession.startTransaction()
417
+ }
418
+
386
419
  let dependency
387
420
  try {
388
421
  await this.hook(appuser,HookType.beforeDelete, id);
@@ -395,7 +428,7 @@ export class SimpleAppService<T extends { _id?: string }> {
395
428
 
396
429
  filterIsolation['_id'] = id;
397
430
  this.logger.debug('delete filter', filterIsolation);
398
- const result = await this.doc.deleteOne(filterIsolation).session(appuser.getDBSession());
431
+ const result = await this.doc.deleteOne(filterIsolation).session(dbsession);
399
432
  const deleteresult = {result:result, data: deletedata}
400
433
  this.logger.debug(deleteresult, " delete result" +this.doc.collection.name,)
401
434
  // this.doc.findByIdAndDelete(id)
@@ -422,6 +455,12 @@ export class SimpleAppService<T extends { _id?: string }> {
422
455
  findIdThenUpdate = async (appuser:UserContext,id: string, data: T,session:mongo.ClientSession=undefined) => {
423
456
  const existingdata = await this.findById(appuser,id);
424
457
  await this.hook(appuser,HookType.beforeUpdate, data);
458
+
459
+ const dbsession = appuser.getDBSession()
460
+ if(!dbsession.inTransaction()){
461
+ dbsession.startTransaction()
462
+ }
463
+
425
464
  // try {
426
465
  Object.assign(data, appuser.getUpdateFilter());
427
466
  Object.assign(existingdata, data);
@@ -435,12 +474,13 @@ export class SimpleAppService<T extends { _id?: string }> {
435
474
 
436
475
  isolationFilter['_id'] = id;
437
476
  this.applyNestedDateTime(appuser,data,'update')
438
- const result = await this.doc.findOneAndUpdate(isolationFilter, data).session(appuser.getDBSession());
439
- await this.hook(appuser,HookType.afterUpdate, data);
440
- return result;
441
- // } catch (err) {
442
- // throw new InternalServerErrorException(err.message);
443
- // }
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
+ }
444
484
  };
445
485
 
446
486
  //find what foreign key constraint
@@ -522,7 +562,9 @@ export class SimpleAppService<T extends { _id?: string }> {
522
562
 
523
563
 
524
564
  async genNewDocNo(appuser:UserContext,data:T){
565
+ this.logger.debug("genNewDocNo")
525
566
  const result = await this.docnogenerator.generateNextNumberFromDocument(appuser,this.documentType,data)
567
+ this.logger.debug(result,"genNewDocNo")
526
568
  data[this.documentIdentityCode]=result
527
569
  }
528
570
 
@@ -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) => {
@@ -68,10 +67,11 @@ export class DocnoformatService extends DocnoformatProcessor {
68
67
  doctype = doctype.toUpperCase();
69
68
  const searchresult = await this.search(
70
69
  appuser,
71
- { docNoType: doctype },
72
- { default: 'desc' },
70
+ { docNoType:doctype},
71
+ undefined,
72
+ {default:'desc'}
73
73
  );
74
- console.log(searchresult);
74
+ console.log('searchresult',searchresult);
75
75
  let data: any = [];
76
76
  for (let i = 0; i < searchresult.length; i++) {
77
77
  const s = searchresult[i];
@@ -81,7 +81,6 @@ export class DocnoformatService extends DocnoformatProcessor {
81
81
  docNoFormatNo: s.docNoFormatNo,
82
82
  docNoFormatName: s.docNoFormatName,
83
83
  docNoPattern: s.docNoPattern,
84
- isMonthly: s.isMonthly,
85
84
  nextNumber: s.nextNumber,
86
85
  default: s.default,
87
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) => {