@simitgroup/simpleapp-generator 1.5.1-alpha → 1.6.1-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.
Files changed (147) hide show
  1. package/dist/buildinschemas/branch.d.ts.map +1 -1
  2. package/dist/buildinschemas/branch.js +10 -0
  3. package/dist/buildinschemas/branch.js.map +1 -1
  4. package/dist/buildinschemas/index.d.ts +2 -0
  5. package/dist/buildinschemas/index.d.ts.map +1 -1
  6. package/dist/buildinschemas/index.js +5 -1
  7. package/dist/buildinschemas/index.js.map +1 -1
  8. package/dist/buildinschemas/keyvaluepair.d.ts +3 -0
  9. package/dist/buildinschemas/keyvaluepair.d.ts.map +1 -0
  10. package/dist/buildinschemas/keyvaluepair.js +28 -0
  11. package/dist/buildinschemas/keyvaluepair.js.map +1 -0
  12. package/dist/buildinschemas/message.d.ts +3 -0
  13. package/dist/buildinschemas/message.d.ts.map +1 -0
  14. package/dist/buildinschemas/message.js +34 -0
  15. package/dist/buildinschemas/message.js.map +1 -0
  16. package/dist/buildinschemas/organization.d.ts.map +1 -1
  17. package/dist/buildinschemas/organization.js +18 -1
  18. package/dist/buildinschemas/organization.js.map +1 -1
  19. package/dist/buildinschemas/systemmessage.d.ts +3 -0
  20. package/dist/buildinschemas/systemmessage.d.ts.map +1 -0
  21. package/dist/buildinschemas/systemmessage.js +43 -0
  22. package/dist/buildinschemas/systemmessage.js.map +1 -0
  23. package/dist/framework.d.ts.map +1 -1
  24. package/dist/framework.js +4 -2
  25. package/dist/framework.js.map +1 -1
  26. package/dist/generate.d.ts.map +1 -1
  27. package/dist/generate.js +37 -9
  28. package/dist/generate.js.map +1 -1
  29. package/dist/processors/bpmnbuilder.d.ts.map +1 -1
  30. package/dist/processors/bpmnbuilder.js +23 -32
  31. package/dist/processors/bpmnbuilder.js.map +1 -1
  32. package/dist/processors/jrxmlbuilder.d.ts +3 -0
  33. package/dist/processors/jrxmlbuilder.d.ts.map +1 -0
  34. package/dist/processors/jrxmlbuilder.js +57 -0
  35. package/dist/processors/jrxmlbuilder.js.map +1 -0
  36. package/dist/type.d.ts +6 -0
  37. package/dist/type.d.ts.map +1 -1
  38. package/package.json +1 -1
  39. package/src/buildinschemas/branch.ts +10 -0
  40. package/src/buildinschemas/index.ts +2 -0
  41. package/src/buildinschemas/keyvaluepair.ts +26 -0
  42. package/src/buildinschemas/organization.ts +18 -1
  43. package/src/buildinschemas/systemmessage.ts +42 -0
  44. package/src/framework.ts +4 -2
  45. package/src/generate.ts +41 -13
  46. package/src/processors/bpmnbuilder.ts +34 -38
  47. package/src/processors/jrxmlbuilder.ts +38 -0
  48. package/src/type.ts +7 -1
  49. package/templates/basic/nest/controller.ts.eta +34 -17
  50. package/templates/basic/nest/processor.ts.eta +2 -1
  51. package/templates/basic/nest/resolver.ts.eta +1 -1
  52. package/templates/basic/nest/service.ts.eta +22 -4
  53. package/templates/basic/nest/type.ts.eta +2 -2
  54. package/templates/basic/nuxt/component.select.vue.eta +5 -1
  55. package/templates/basic/nuxt/pages.form.vue.eta +1 -1
  56. package/templates/basic/nuxt/pages.mobile.landing.vue.eta +4 -61
  57. package/templates/basic/nuxt/simpleapp.generate.client.ts.eta +11 -13
  58. package/templates/nest/src/app.module.ts.eta +12 -4
  59. package/templates/nest/src/cloudapi/cloudapi.module.ts._eta +1 -1
  60. package/templates/nest/src/printapi/api/.gitignore.eta +4 -0
  61. package/templates/nest/src/printapi/api/.npmignore.eta +1 -0
  62. package/templates/nest/src/printapi/api/.openapi-generator/FILES.eta +8 -0
  63. package/templates/nest/src/printapi/api/.openapi-generator/VERSION.eta +1 -0
  64. package/templates/nest/src/printapi/api/.openapi-generator-ignore.eta +23 -0
  65. package/templates/nest/src/printapi/api/api.ts.eta +223 -0
  66. package/templates/nest/src/printapi/api/base.ts.eta +86 -0
  67. package/templates/nest/src/printapi/api/common.ts.eta +150 -0
  68. package/templates/nest/src/printapi/api/configuration.ts.eta +110 -0
  69. package/templates/nest/src/printapi/api/git_push.sh.eta +57 -0
  70. package/templates/nest/src/printapi/api/index.ts.eta +18 -0
  71. package/templates/nest/src/printapi/api/openapitools.json.eta +7 -0
  72. package/templates/nest/src/printapi/printapi.module.ts.eta +15 -0
  73. package/templates/nest/src/printapi/printapi.service.ts.eta +42 -0
  74. package/templates/nest/src/simpleapp/apischemas/index.ts._eta +11 -0
  75. package/templates/nest/src/simpleapp/generate/commons/robotuser.service.ts.eta +5 -4
  76. package/templates/nest/src/simpleapp/generate/commons/roles/roles.enum.ts.eta +7 -0
  77. package/templates/nest/src/simpleapp/generate/commons/user.context.ts.eta +10 -9
  78. package/templates/nest/src/simpleapp/generate/processors/autoinc.processor.ts.eta +73 -0
  79. package/templates/nest/src/simpleapp/generate/processors/branch.processor.ts.eta +104 -0
  80. package/templates/nest/src/simpleapp/generate/processors/docno.processor.ts.eta +77 -0
  81. package/templates/nest/src/simpleapp/generate/processors/org.processor.ts.eta +115 -0
  82. package/templates/nest/src/simpleapp/generate/processors/perm.processor.ts.eta +71 -0
  83. package/templates/nest/src/simpleapp/generate/processors/simpleapp.processor.ts.eta +77 -13
  84. package/templates/nest/src/simpleapp/generate/processors/sysmsg.processor.ts.eta +49 -0
  85. package/templates/nest/src/simpleapp/generate/processors/tenant.processor.ts.eta +52 -0
  86. package/templates/nest/src/simpleapp/generate/types/simpleapp.type.ts.eta +12 -5
  87. package/templates/nest/src/simpleapp/generate/workflow/workflow.controller.ts.eta +2 -2
  88. package/templates/nest/src/simpleapp/generate/workflow/workflow.delegate.ts.eta +33 -28
  89. package/templates/nest/src/simpleapp/generate/workflow/workflow.service.ts.eta +95 -26
  90. package/templates/nest/src/simpleapp/generate/workflow/workflow.type.ts.eta +4 -4
  91. package/templates/nest/src/simpleapp/profile/profile.apischema.ts.eta +15 -0
  92. package/templates/nest/src/simpleapp/profile/profile.controller.ts.eta +3 -1
  93. package/templates/nest/src/simpleapp/profile/profile.service.ts.eta +20 -3
  94. package/templates/nest/src/simpleapp/services/sysmsg.service.ts._etaxxx +43 -0
  95. package/templates/nest/src/simpleapp/services/userresolver.service.ts._eta +70 -0
  96. package/templates/nest/src/simpleapp/simpleapp.module.ts.eta +8 -4
  97. package/templates/nest/src/simpleapp/types/index.ts._eta +5 -0
  98. package/templates/nuxt/assets/css/listview.css._eta +2 -2
  99. package/templates/nuxt/components/button/ButtonAction.vue._eta +11 -5
  100. package/templates/nuxt/components/calendar/CalendarSmall.vue.eta +11 -2
  101. package/templates/nuxt/components/debug/DebugDocumentData.vue.eta +1 -1
  102. package/templates/nuxt/components/form/{FormBranch.vue.eta → FormBranch.vue._eta} +1 -1
  103. package/templates/nuxt/components/image/ImageAvatar.vue.eta.vue +38 -0
  104. package/templates/nuxt/components/image/ImageOrganization.vue.eta.vue +40 -0
  105. package/templates/nuxt/components/image/ImageToBase64Uploader.vue.eta.vue +147 -0
  106. package/templates/nuxt/components/list/ListItem.vue.eta +24 -0
  107. package/templates/nuxt/components/list/ListMessages.vue.eta +89 -0
  108. package/templates/nuxt/components/list/ListView.vue.eta +9 -12
  109. package/templates/nuxt/components/renderer/RendererMoney.vue.eta +11 -12
  110. package/templates/nuxt/components/select/SelectTemplate.vue.eta +49 -20
  111. package/templates/nuxt/components/simpleApp/SimpleAppAutocomplete.vue.eta +2 -2
  112. package/templates/nuxt/components/simpleApp/SimpleAppChildrenList.vue.eta +16 -15
  113. package/templates/nuxt/components/simpleApp/SimpleAppFormToolBar.vue._eta +92 -8
  114. package/templates/nuxt/components/simpleApp/SimpleAppInput.vue.eta +29 -6
  115. package/templates/nuxt/components/text/TextBold.vue._eta +13 -0
  116. package/templates/nuxt/components/user/UserButtonCreateTenant.vue._eta +18 -2
  117. package/templates/nuxt/composables/getUserStore.generate.ts.eta +12 -3
  118. package/templates/nuxt/composables/hotvalue.generate.ts.eta +30 -0
  119. package/templates/nuxt/composables/pusher.ts._eta +13 -0
  120. package/templates/nuxt/composables/stringHelper.generate.ts.eta +2 -3
  121. package/templates/nuxt/composables/sysmessage.generate.ts.eta +20 -0
  122. package/templates/nuxt/composables/workflow.generate.ts.eta +9 -4
  123. package/templates/nuxt/layouts/mobile.vue._eta +31 -42
  124. package/templates/nuxt/nuxt.config.ts._eta +2 -2
  125. package/templates/nuxt/othermodules.d.ts.eta +449 -0
  126. package/templates/nuxt/pages/[xorg]/mobile/organization/[id].vue._eta +40 -0
  127. package/templates/nuxt/pages/[xorg]/mobile/organization/{index.vue.eta → index.vue.aetaz} +16 -13
  128. package/templates/nuxt/pages/[xorg]/organization.vue.eta +21 -15
  129. package/templates/nuxt/plugins/40.pusher.ts.eta +18 -0
  130. package/templates/nuxt/simpleapp/generate/clients/SimpleAppClient.ts.eta +10 -1
  131. package/templates/nuxt/simpleapp/generate/commons/roles.ts.eta +4 -1
  132. package/templates/nuxt/types/schema.ts.eta +8 -1
  133. package/templates/nuxt/types/simpleappinput.ts.eta +3 -5
  134. package/templates/printformats/template.jrxml._eta +27 -0
  135. package/templates/project/groups/admin.json.eta +6 -1
  136. package/templates/project/jsonschemas/branch.json._eta +113 -0
  137. package/templates/project/jsonschemas/invoice.json._eta +5 -1
  138. package/templates/project/jsonschemas/organization.json._eta +111 -0
  139. package/templates/project/lang/default._json +71 -150
  140. package/templates/workflow/next/listener.ts.eta +6 -3
  141. package/tsconfig.tsbuildinfo +1 -1
  142. /package/templates/nest/src/simpleapp/services/{autoinc.service.ts.eta → autoinc.service.ts.etaxx} +0 -0
  143. /package/templates/nest/src/simpleapp/services/{branch.service.ts.eta → branch.service.ts.etaxxx} +0 -0
  144. /package/templates/nest/src/simpleapp/services/{docno.service.ts.eta → docno.service.ts.etaxxx} +0 -0
  145. /package/templates/nest/src/simpleapp/services/{org.service.ts.eta → org.service.ts.etaxxx} +0 -0
  146. /package/templates/nest/src/simpleapp/services/{perm.service.ts.eta → perm.service.ts.etaxxx} +0 -0
  147. /package/templates/nest/src/simpleapp/services/{tenant.service.ts.eta → tenant.service.ts.etaxxx} +0 -0
@@ -0,0 +1,42 @@
1
+ /**
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2024-04-02
5
+ * Author: Ks Tan
6
+ */
7
+
8
+ import { Injectable, InternalServerErrorException } from '@nestjs/common';
9
+ import * as api from './api';
10
+ import { UserContext } from 'src/simpleapp/generate/commons/user.context';
11
+
12
+ @Injectable()
13
+ export class PrintApiService {
14
+ constructor() {}
15
+
16
+ getConfig(appuser: UserContext) {
17
+ const config: api.Configuration = {
18
+ basePath: process.env.PRINTAPI_SERVER,
19
+ accessToken: appuser.getUserToken(),
20
+ isJsonMime(mime) {
21
+ return true;
22
+ },
23
+ };
24
+ return config;
25
+ }
26
+ async getBase64Pdf(appuser: UserContext, formatid: string, id: string) {
27
+ const printapi = new api.DefaultApi(this.getConfig(appuser), undefined);
28
+ try{
29
+ const result:any = await printapi.runPdfBase64(formatid, id, {
30
+ headers: {
31
+ 'x-org': appuser.getXorg(),
32
+ },
33
+ });
34
+
35
+ const pdfresult: string = result.data;
36
+ return pdfresult;
37
+ }catch(e){
38
+ throw new InternalServerErrorException('print-service servicer error')
39
+ }
40
+
41
+ }
42
+ }
@@ -4,6 +4,7 @@
4
4
  * last change 2024-02-22
5
5
  * author: Ks Tan
6
6
  */
7
+ import { Field, ObjectType } from '@nestjs/graphql';
7
8
  import { ApiProperty } from '@nestjs/swagger';
8
9
  export class ForeignKey {
9
10
  @ApiProperty({ type: 'string', required: false, format: 'uuid', default: '' })
@@ -29,6 +30,16 @@ export class CodeLabelValue {
29
30
  @Field()
30
31
  value: number
31
32
  }
33
+ @ObjectType()
34
+ export class KeyValue {
35
+ @ApiProperty({ type: 'string' })
36
+ @Field()
37
+ key: string;
38
+ @ApiProperty({ type: 'string' })
39
+ @Field()
40
+ value: string;
41
+ }
42
+
32
43
  export class UserAllPermissionsBranches {
33
44
  @ApiProperty({ type: 'string', required: true, default: '',})
34
45
  permId: string;
@@ -81,10 +81,11 @@ export class SimpleAppRobotUserService {
81
81
  const nextrefresh = tokens.expires_in * 0.8;
82
82
  const appuser = this.prepareAppUser(undefined);
83
83
 
84
-
85
- setTimeout(async () => {
86
- await this.refreshSystemToken();
87
- }, nextrefresh * 1000);
84
+ if(tokens.access_token){
85
+ setTimeout(async () => {
86
+ await this.refreshSystemToken();
87
+ }, nextrefresh * 1000);
88
+ }
88
89
  }
89
90
 
90
91
  prepareAppUser(data: any) {
@@ -13,6 +13,8 @@ export enum Role {
13
13
  User = 'user',
14
14
  <% for(let i=0;i<it.modules.length; i++){ %>
15
15
  <% const m = it.modules[i] %>
16
+ <%=m.docname%>_access='<%=m.docname%>:access',
17
+
16
18
  <%=m.docname%>_create='<%=m.docname%>:create',
17
19
 
18
20
  <%=m.docname%>_update='<%=m.docname%>:update',
@@ -21,6 +23,11 @@ export enum Role {
21
23
 
22
24
  <%=m.docname%>_search='<%=m.docname%>:search',
23
25
 
26
+ <%if(m.schema['x-simpleapp-config']['printFormats']){%>
27
+ <%=m.docname%>_print='<%=m.docname%>:print',
28
+ <%}%>
29
+
30
+
24
31
  <% if(m.api && m.api.length >0) {%>
25
32
 
26
33
  <% for(let j=0;j<m.api.length; j++){ %>
@@ -44,7 +44,7 @@ export class UserContext {
44
44
  protected uname: string = '';
45
45
  protected email: string = '';
46
46
  protected fullname: string = '';
47
- protected xOrg: string = '';
47
+ protected xOrg: string = '';
48
48
  protected tenantId: number = 0;
49
49
  protected orgId: number = 0;
50
50
  protected orgRecordId: string = '';
@@ -252,16 +252,16 @@ export class UserContext {
252
252
  return undefined;
253
253
  }
254
254
  };
255
- getUserToken = () => this.token
255
+ getUserToken = () => this.token;
256
256
  setUserToken = async (tokenstr: string) => {
257
257
  //define token info
258
258
  const tokeninfo = jwt.decode(tokenstr);
259
259
  this.token = tokenstr;
260
- this.uid = tokeninfo.sub;
261
- this.email = tokeninfo.email;
262
- this.uname = tokeninfo.preferred_username;
263
- this.fullname = tokeninfo.name;
264
- this.ssoACL = tokeninfo.resource_access;
260
+ this.uid = tokeninfo?.sub ?? '';
261
+ this.email = tokeninfo?.email ??'';
262
+ this.uname = tokeninfo?.preferred_username ?? '';
263
+ this.fullname = tokeninfo?.name ?? [];
264
+ this.ssoACL = tokeninfo?.resource_access ?? [];
265
265
  this.logger.verbose(`set token ${this.uid}`);
266
266
  //read current user from db
267
267
  // console.log("await this.obtainProfileFromDb()")
@@ -364,9 +364,9 @@ export class UserContext {
364
364
  this.orgId = orgId;
365
365
  this.branchId = branchId;
366
366
  }
367
- getXorg = () =>this.xOrg
367
+ getXorg = () => this.xOrg;
368
368
  setXorg = (xorg) => {
369
- this.xOrg = xorg
369
+ this.xOrg = xorg;
370
370
  try {
371
371
  const decodedText: string = Base64URL.decodeText(xorg);
372
372
  const x = decodedText.includes('/')
@@ -535,6 +535,7 @@ export class UserContext {
535
535
  };
536
536
 
537
537
  searchInsertedRecordId(collection: string, _id: string) {
538
+ if(!this.modifiedRecords.createds[collection]) return undefined
538
539
  return this.modifiedRecords.createds[collection].find(
539
540
  (item) => item === _id,
540
541
  );
@@ -0,0 +1,73 @@
1
+ /**
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2024-02-23
5
+ * Author: Ks Tan
6
+ */
7
+ import { UserContext } from '../commons/user.context';
8
+ import * as sharelibs from '../sharelibs';
9
+ import { Injectable,Inject } from '@nestjs/common';
10
+ import { InjectModel } from '@nestjs/mongoose';
11
+ import * as jsonpath from 'jsonpath';
12
+ import { Model } from 'mongoose';
13
+ import { AutoincreamentJsonSchema } from '../jsonschemas/autoinc.jsonschema';
14
+ import { SimpleAppService } from './simpleapp.processor';
15
+ import { IsolationType } from '../types';
16
+ import { DocNumberFormatGenerator } from '../commons/docnogenerator.service';
17
+ import { Autoincreament } from '../types/autoinc.type';
18
+ import { DefaultAutoincreament } from '../defaults/autoinc.default';
19
+
20
+ @Injectable()
21
+ export class AutoincreamentProcessor extends SimpleAppService<Autoincreament> {
22
+ protected documentIdentityCode = '';
23
+ protected documentIdentityLabel = '';
24
+
25
+ protected foreignkeys = {};
26
+ constructor(mydoc: Model<Autoincreament>) {
27
+ super('AUTOINC', 'autoincreament', mydoc, IsolationType.none);
28
+ this.setSchema(AutoincreamentJsonSchema);
29
+ this.setData(DefaultAutoincreament(crypto.randomUUID()));
30
+ }
31
+
32
+ reCalculateValue(data: Autoincreament) {
33
+ //console.log('trigger new recalculate')
34
+ const jsopbj = new jsonpath['JSONPath']();
35
+ }
36
+
37
+ async runGenerateNextNo(
38
+ appuser: UserContext,
39
+ collection: string,
40
+ field: string,
41
+ ) {
42
+ const res = await this.search(appuser, {
43
+ collectionName: collection,
44
+ fieldName: field,
45
+ });
46
+ // console.log(res)
47
+ let data;
48
+ if (res.length > 0) {
49
+ // console.log("FOUND RESULT------")
50
+ const tmp = res[0];
51
+ const nextno = tmp.nextNo;
52
+ data = { collectionName: collection, fieldName: field, nextno: nextno };
53
+ this.findIdThenUpdate(appuser, tmp._id, {
54
+ collectionName: collection,
55
+ fieldName: field,
56
+ nextNo: tmp.nextNo + 1,
57
+ });
58
+ } else {
59
+ // console.log("CREATE ROW------")
60
+ this.data = { collectionName: collection, fieldName: field, nextNo: 2 };
61
+ const createResult = await this.create(appuser, this.data);
62
+ data = {
63
+ _id: crypto.randomUUID(),
64
+ collectionName: collection,
65
+ fieldName: field,
66
+ nextno: 1,
67
+ };
68
+ }
69
+
70
+ return data;
71
+ }
72
+ /***************************** additional execute *****************************************/
73
+ }
@@ -0,0 +1,104 @@
1
+ /**
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2024-02-23
5
+ * Author: Ks Tan
6
+ */
7
+ import { UserContext } from '../commons/user.context';
8
+ import * as sharelibs from '../sharelibs';
9
+ import { Injectable, Inject,InternalServerErrorException } from '@nestjs/common';
10
+ import { InjectModel } from '@nestjs/mongoose';
11
+ import * as jsonpath from 'jsonpath';
12
+ import { Model } from 'mongoose';
13
+ import { BranchJsonSchema } from '../jsonschemas/branch.jsonschema';
14
+ import { SimpleAppService } from './simpleapp.processor';
15
+ import { IsolationType } from '../types';
16
+ import { DocNumberFormatGenerator } from '../commons/docnogenerator.service';
17
+ import { AutoincreamentService } from '../../services/autoinc.service';
18
+ import { alldocuments } from '../commons/dicts/documents';
19
+ import { Docnoformat, DocnoformatService } from '../../services/docno.service';
20
+ import { BranchOrganization, Branch,BranchHooks } from '../types/branch.type';
21
+ import {
22
+ DefaultBranchOrganization,
23
+ DefaultBranch,
24
+ } from '../defaults/branch.default';
25
+
26
+ @Injectable()
27
+ export class BranchProcessor extends SimpleAppService<Branch> {
28
+ @Inject(AutoincreamentService)
29
+ protected increament: AutoincreamentService;
30
+ @Inject(DocnoformatService)
31
+ private docnoservice: DocnoformatService;
32
+ protected strictIsolation = false;
33
+ protected documentIdentityCode = 'branchCode';
34
+ protected documentIdentityLabel = 'branchName';
35
+ protected hooks: BranchHooks = {
36
+ beforeCreate: async (appuser: UserContext, data: Branch) => await this.branchBeforeCreate(appuser,data),
37
+ afterCreate: async (appuser: UserContext, data: Branch) => await this.branchAfterCreate(appuser,data),
38
+ };
39
+ protected foreignkeys = { organization: ['$.organization._id'] };
40
+ constructor(mydoc: Model<Branch>) {
41
+ super('BRANCH', 'branch', mydoc, IsolationType.org);
42
+ this.setSchema(BranchJsonSchema);
43
+ this.setData(DefaultBranch(crypto.randomUUID()));
44
+ this.addAutoCompleteField({
45
+ branchId: 'branchId',
46
+ });
47
+ }
48
+
49
+ reCalculateValue(data: Branch) {
50
+ //console.log('trigger new recalculate')
51
+ const jsopbj = new jsonpath['JSONPath']();
52
+ }
53
+
54
+ /***************************** additional execute *****************************************/
55
+ async branchBeforeCreate(appuser: UserContext, data: Branch) {
56
+ const searchresult = await this.increament.runGenerateNextNo(
57
+ appuser,
58
+ 'branch',
59
+ 'branchId',
60
+ );
61
+ data.branchId = searchresult.nextno;
62
+ }
63
+ async branchAfterCreate(appuser: UserContext, data: Branch) {
64
+ await this.generateDefaultDocNumbers(appuser, data);
65
+ }
66
+
67
+ generateDefaultDocNumbers = async (appuser, data) => {
68
+ const branchName = data.branchName;
69
+ const branchCode = data.branchCode;
70
+ const recordId = data._id;
71
+ const branchId = data.branchId;
72
+ const orgId = data.orgId;
73
+ const tenantId = data.tenantId;
74
+ const docformats = alldocuments.filter((item) => item.docNumber);
75
+ for (let i = 0; i < docformats.length; i++) {
76
+ const doc = docformats[i];
77
+ const pattern = `${doc.docType}-${branchCode}-[00000]`;
78
+ const formatdata: Docnoformat = {
79
+ _id: crypto.randomUUID(),
80
+ docNoFormatNo: `${doc.docType}-${branchCode}`,
81
+ docNoFormatName: `Default ${doc.docType} - ${branchCode}`,
82
+ docNoType: doc.docType,
83
+ docNoPattern: pattern,
84
+ branch: { _id: recordId, branchId: branchId, label: branchName },
85
+ branchId: branchId,
86
+ orgId: orgId,
87
+ tenantId: tenantId,
88
+ nextNumber: 1,
89
+ } as Docnoformat;
90
+ try {
91
+ const result = await this.docnoservice.create(appuser, formatdata);
92
+ if (!result) {
93
+ throw new InternalServerErrorException(
94
+ `Generate default document number for "${branchCode}" failed. Pattern: ${pattern}`,
95
+ 'generateDefaultDocNumbers',
96
+ );
97
+ }
98
+ } catch (err) {
99
+ this.logger.error(err);
100
+ throw new InternalServerErrorException(err);
101
+ }
102
+ }
103
+ };
104
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2024-02-23
5
+ * Author: Ks Tan
6
+ */
7
+ import { UserContext } from '../commons/user.context';
8
+ import * as sharelibs from '../sharelibs';
9
+ import { Injectable,Inject } from '@nestjs/common';
10
+ import { InjectModel } from '@nestjs/mongoose';
11
+ import * as jsonpath from 'jsonpath';
12
+ import { Model } from 'mongoose';
13
+ import { DocnoformatJsonSchema } from '../jsonschemas/docno.jsonschema';
14
+ import { SimpleAppService } from './simpleapp.processor';
15
+ import { IsolationType } from '../types';
16
+ import { DocNumberFormatGenerator } from '../commons/docnogenerator.service';
17
+ import { DocnoformatBranch, Docnoformat } from '../types/docno.type';
18
+ import {
19
+ DefaultDocnoformatBranch,
20
+ DefaultDocnoformat,
21
+ } from '../defaults/docno.default';
22
+
23
+ @Injectable()
24
+ export class DocnoformatProcessor extends SimpleAppService<Docnoformat> {
25
+ protected strictIsolation = false;
26
+ protected documentIdentityCode = 'docNoFormatNo';
27
+ protected documentIdentityLabel = 'docNoFormatName';
28
+
29
+ protected foreignkeys = { branch: ['$.branch._id'] };
30
+ constructor(mydoc: Model<Docnoformat>) {
31
+ super('DOCNO', 'docnoformat', mydoc, IsolationType.org);
32
+ this.setSchema(DocnoformatJsonSchema);
33
+ this.setData(DefaultDocnoformat(crypto.randomUUID()));
34
+ this.addAutoCompleteField({
35
+ default: 'default',
36
+ });
37
+ }
38
+
39
+ reCalculateValue(data: Docnoformat) {
40
+ //console.log('trigger new recalculate')
41
+ const jsopbj = new jsonpath['JSONPath']();
42
+ }
43
+
44
+ /***************************** additional execute *****************************************/
45
+ /**
46
+ * list document number format and prepare sample of docformat
47
+ * @param appuser
48
+ * @param doctype
49
+ * @returns
50
+ */
51
+ async runListDocFormats(appuser: UserContext, doctype: string) {
52
+ doctype = doctype.toUpperCase();
53
+ const searchresult = await this.search(
54
+ appuser,
55
+ { docNoType: doctype,'branch.branchId':appuser.getBranchId() },
56
+ undefined,
57
+ {default:'desc'}
58
+ );
59
+ //console.log('searchresult',searchresult);
60
+ let data: any = [];
61
+ for (let i = 0; i < searchresult.length; i++) {
62
+ const s = searchresult[i];
63
+ if (s.active && s.docNoPattern) {
64
+ data.push({
65
+ _id: s._id,
66
+ docNoFormatNo: s.docNoFormatNo,
67
+ docNoFormatName: s.docNoFormatName,
68
+ docNoPattern: s.docNoPattern,
69
+ nextNumber: s.nextNumber,
70
+ default: s.default,
71
+ sample: DocNumberFormatGenerator.previewDocNo(s),
72
+ });
73
+ }
74
+ }
75
+ return data;
76
+ }
77
+ }
@@ -0,0 +1,115 @@
1
+ /**
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2024-02-23
5
+ * Author: Ks Tan
6
+ */
7
+ import { UserContext } from '../commons/user.context';
8
+ import * as sharelibs from '../sharelibs';
9
+ import { Injectable, Inject, BadRequestException } from '@nestjs/common';
10
+ import { InjectModel } from '@nestjs/mongoose';
11
+ import * as jsonpath from 'jsonpath';
12
+ import { Model } from 'mongoose';
13
+ import { OrganizationJsonSchema } from '../jsonschemas/org.jsonschema';
14
+ import { SimpleAppService } from './simpleapp.processor';
15
+ import { IsolationType, OrganizationHooks, KeyValue } from '../types';
16
+ import { DocNumberFormatGenerator } from '../commons/docnogenerator.service';
17
+ import { Organization } from '../types/org.type';
18
+ import { AutoincreamentService } from '../../services/autoinc.service';
19
+ import { DefaultOrganization } from '../defaults/org.default';
20
+ import {
21
+ KeyvaluepairService,
22
+ Keyvaluepair,
23
+ } from 'src/simpleapp/services/kvpair.service';
24
+ @Injectable()
25
+ export class OrganizationProcessor extends SimpleAppService<Organization> {
26
+ @Inject(AutoincreamentService)
27
+ protected increament: AutoincreamentService;
28
+ @Inject(KeyvaluepairService)
29
+ protected kvpairService: KeyvaluepairService;
30
+
31
+ protected documentIdentityCode = 'orgCode';
32
+ protected documentIdentityLabel = 'orgName';
33
+ protected strictIsolation = false;
34
+ protected foreignkeys = {};
35
+ protected defaultlogo =
36
+ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAApgAAAKYB3X3/OAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAANCSURBVEiJtZZPbBtFFMZ/M7ubXdtdb1xSFyeilBapySVU8h8OoFaooFSqiihIVIpQBKci6KEg9Q6H9kovIHoCIVQJJCKE1ENFjnAgcaSGC6rEnxBwA04Tx43t2FnvDAfjkNibxgHxnWb2e/u992bee7tCa00YFsffekFY+nUzFtjW0LrvjRXrCDIAaPLlW0nHL0SsZtVoaF98mLrx3pdhOqLtYPHChahZcYYO7KvPFxvRl5XPp1sN3adWiD1ZAqD6XYK1b/dvE5IWryTt2udLFedwc1+9kLp+vbbpoDh+6TklxBeAi9TL0taeWpdmZzQDry0AcO+jQ12RyohqqoYoo8RDwJrU+qXkjWtfi8Xxt58BdQuwQs9qC/afLwCw8tnQbqYAPsgxE1S6F3EAIXux2oQFKm0ihMsOF71dHYx+f3NND68ghCu1YIoePPQN1pGRABkJ6Bus96CutRZMydTl+TvuiRW1m3n0eDl0vRPcEysqdXn+jsQPsrHMquGeXEaY4Yk4wxWcY5V/9scqOMOVUFthatyTy8QyqwZ+kDURKoMWxNKr2EeqVKcTNOajqKoBgOE28U4tdQl5p5bwCw7BWquaZSzAPlwjlithJtp3pTImSqQRrb2Z8PHGigD4RZuNX6JYj6wj7O4TFLbCO/Mn/m8R+h6rYSUb3ekokRY6f/YukArN979jcW+V/S8g0eT/N3VN3kTqWbQ428m9/8k0P/1aIhF36PccEl6EhOcAUCrXKZXXWS3XKd2vc/TRBG9O5ELC17MmWubD2nKhUKZa26Ba2+D3P+4/MNCFwg59oWVeYhkzgN/JDR8deKBoD7Y+ljEjGZ0sosXVTvbc6RHirr2reNy1OXd6pJsQ+gqjk8VWFYmHrwBzW/n+uMPFiRwHB2I7ih8ciHFxIkd/3Omk5tCDV1t+2nNu5sxxpDFNx+huNhVT3/zMDz8usXC3ddaHBj1GHj/As08fwTS7Kt1HBTmyN29vdwAw+/wbwLVOJ3uAD1wi/dUH7Qei66PfyuRj4Ik9is+hglfbkbfR3cnZm7chlUWLdwmprtCohX4HUtlOcQjLYCu+fzGJH2QRKvP3UNz8bWk1qMxjGTOMThZ3kvgLI5AzFfo379UAAAAASUVORK5CYII=';
37
+ protected hooks: OrganizationHooks = {
38
+ beforeCreate: async (appuser: UserContext, data: Organization) =>
39
+ await this.orgBeforeCreate(appuser, data),
40
+ };
41
+
42
+ constructor(mydoc: Model<Organization>) {
43
+ super('ORG', 'organization', mydoc, IsolationType.tenant);
44
+ this.setSchema(OrganizationJsonSchema);
45
+ this.setData(DefaultOrganization(crypto.randomUUID()));
46
+ this.addAutoCompleteField({
47
+ orgId: 'orgId',
48
+ });
49
+ }
50
+
51
+ async orgBeforeCreate(appuser: UserContext, data: Organization) {
52
+ const searchresult = await this.increament.runGenerateNextNo(
53
+ appuser,
54
+ 'organization',
55
+ 'orgId',
56
+ );
57
+ data.orgId = searchresult.nextno;
58
+ }
59
+ reCalculateValue(data: Organization) {
60
+ //console.log('trigger new recalculate')
61
+ const jsopbj = new jsonpath['JSONPath']();
62
+ }
63
+
64
+ /***************************** additional execute *****************************************/
65
+ async runGetlogo(appuser: UserContext) {
66
+ const logo = await this.searchLogo(appuser);
67
+ if (logo) return logo.value;
68
+ else return this.defaultlogo;
69
+ }
70
+
71
+ async searchLogo(appuser: UserContext) {
72
+ const keyvaluepair = await this.kvpairService.search(appuser, {
73
+ key: 'orglogo',
74
+ });
75
+ if (keyvaluepair && keyvaluepair.length > 0) return keyvaluepair[0];
76
+ else return null;
77
+ }
78
+ async runUploadlogo(appuser: UserContext, data: KeyValue) {
79
+ // this.setDefaultLogo(data.value);
80
+ const key = data.key;
81
+
82
+ let kvdata: Keyvaluepair = await this.searchLogo(appuser);
83
+ if (kvdata) {
84
+ kvdata.value=data.value
85
+ const res = await this.kvpairService.findIdThenUpdate(
86
+ appuser,
87
+ kvdata._id,
88
+ kvdata,
89
+ );
90
+ if (res) {
91
+ return data.value;
92
+ } else {
93
+ throw new BadRequestException(`failed to update keyvalue pair ${key}`);
94
+ }
95
+ } else {
96
+ kvdata = {
97
+ _id: crypto.randomUUID(),
98
+ key: 'orglogo',
99
+ value: data.value,
100
+ };
101
+ const res = await this.kvpairService.create(appuser, kvdata);
102
+ if (res) {
103
+ return data.value;
104
+ } else {
105
+ throw new BadRequestException(`failed to create keyvalue pair ${key}`);
106
+ }
107
+ }
108
+
109
+ return this.defaultlogo;
110
+ }
111
+
112
+ async setDefaultLogo(data: string) {
113
+ this.defaultlogo = data;
114
+ }
115
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2024-02-23
5
+ * Author: Ks Tan
6
+ */
7
+ import { UserContext } from '../commons/user.context';
8
+ import * as sharelibs from '../sharelibs';
9
+
10
+ import { Injectable, Inject } from '@nestjs/common';
11
+ import { InjectModel } from '@nestjs/mongoose';
12
+ import * as jsonpath from 'jsonpath';
13
+ import { Model, PipelineStage } from 'mongoose';
14
+ import { PermissionJsonSchema } from '../jsonschemas/perm.jsonschema';
15
+ import { SimpleAppService } from './simpleapp.processor';
16
+ import { IsolationType } from '../types';
17
+ import { DocNumberFormatGenerator } from '../commons/docnogenerator.service';
18
+ import { Permission } from '../types/perm.type';
19
+ import { DefaultPermission } from '../defaults/perm.default';
20
+
21
+ @Injectable()
22
+ export class PermissionProcessor extends SimpleAppService<Permission> {
23
+ protected documentIdentityCode = '';
24
+ protected documentIdentityLabel = '';
25
+ protected strictIsolation = false;
26
+ protected foreignkeys = { user: ['$.userId'] };
27
+ constructor(mydoc: Model<Permission>) {
28
+ super('PERM', 'permission', mydoc, IsolationType.org);
29
+ this.setSchema(PermissionJsonSchema);
30
+ this.setData(DefaultPermission(crypto.randomUUID()));
31
+ }
32
+
33
+ reCalculateValue(data: Permission) {
34
+ //console.log('trigger new recalculate')
35
+ const jsopbj = new jsonpath['JSONPath']();
36
+ }
37
+
38
+ async runListUser(appuser: UserContext) {
39
+ const getallrecords: PipelineStage = { $match: {} };
40
+ const lookupuser: PipelineStage = {
41
+ $lookup: {
42
+ from: 'user',
43
+ localField: 'uid',
44
+ foreignField: 'uid',
45
+ as: 'user',
46
+ },
47
+ };
48
+ const pipeline: PipelineStage[] = [getallrecords, lookupuser];
49
+ const result = await this.aggregate(appuser, pipeline);
50
+ const finalresult: any[] = [];
51
+ for (let i = 0; i < result.length; i++) {
52
+ const r = result[i];
53
+
54
+ const u = r.user[0] ?? { email: 'unknownemail', fullName: 'unknown' };
55
+ finalresult.push({
56
+ _id: r._id,
57
+ tenantId: r.tenantId,
58
+ orgId: r.orgId,
59
+ branchId: r.branchId,
60
+ uid: r.uid,
61
+ group: r.group,
62
+ fullName: u.fullname,
63
+ email: u.email,
64
+ });
65
+ }
66
+ // result['user'] = result['users'][0]
67
+ // delete result['users'][0]
68
+ return finalresult;
69
+ }
70
+ /***************************** additional execute *****************************************/
71
+ }