@simitgroup/simpleapp-generator 1.6.7-o-alpha → 2.0.0-b-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 (305) hide show
  1. package/ReleaseNote.md +9 -0
  2. package/dist/buildinschemas/autoincreament.js +1 -1
  3. package/dist/buildinschemas/branch.d.ts.map +1 -1
  4. package/dist/buildinschemas/branch.js +2 -0
  5. package/dist/buildinschemas/branch.js.map +1 -1
  6. package/dist/buildinschemas/docnoformat.js +1 -1
  7. package/dist/buildinschemas/docnoformat.js.map +1 -1
  8. package/dist/buildinschemas/documentevent.js +1 -1
  9. package/dist/buildinschemas/documentnoformat.d.ts +3 -0
  10. package/dist/buildinschemas/documentnoformat.d.ts.map +1 -0
  11. package/dist/buildinschemas/documentnoformat.js +58 -0
  12. package/dist/buildinschemas/documentnoformat.js.map +1 -0
  13. package/dist/buildinschemas/index.d.ts +0 -5
  14. package/dist/buildinschemas/index.d.ts.map +1 -1
  15. package/dist/buildinschemas/index.js +5 -11
  16. package/dist/buildinschemas/index.js.map +1 -1
  17. package/dist/buildinschemas/organization.d.ts.map +1 -1
  18. package/dist/buildinschemas/organization.js +3 -19
  19. package/dist/buildinschemas/organization.js.map +1 -1
  20. package/dist/buildinschemas/user.d.ts.map +1 -1
  21. package/dist/buildinschemas/user.js +5 -2
  22. package/dist/buildinschemas/user.js.map +1 -1
  23. package/dist/generate.d.ts.map +1 -1
  24. package/dist/generate.js +118 -23
  25. package/dist/generate.js.map +1 -1
  26. package/dist/type.d.ts +6 -0
  27. package/dist/type.d.ts.map +1 -1
  28. package/dist/type.js.map +1 -1
  29. package/package.json +1 -1
  30. package/src/buildinschemas/{autoincreament.ts → autoincreament.ts.backup} +1 -1
  31. package/src/buildinschemas/branch.ts +2 -0
  32. package/src/buildinschemas/{documentevent.ts → documentevent.ts.backup} +1 -1
  33. package/src/buildinschemas/{docnoformat.ts → documentnoformat.ts.backup} +3 -3
  34. package/src/buildinschemas/index.ts +4 -5
  35. package/src/buildinschemas/organization.ts +3 -19
  36. package/src/buildinschemas/user.ts +5 -2
  37. package/src/generate.ts +128 -28
  38. package/src/type.ts +6 -1
  39. package/templates/basic/nest/api.controller.ts.eta +153 -0
  40. package/templates/basic/nest/api.module.ts.eta +32 -0
  41. package/templates/basic/nest/api.resolver.ts.eta +94 -0
  42. package/templates/basic/nest/api.schema.ts.eta +20 -0
  43. package/templates/basic/nest/api.service.ts.eta +85 -0
  44. package/templates/basic/nest/controller.ts.eta +31 -119
  45. package/templates/basic/nest/default.ts.eta +16 -10
  46. package/templates/basic/nest/enum.ts.eta +16 -0
  47. package/templates/basic/nest/model.ts.eta +6 -28
  48. package/templates/basic/nest/module.ts.eta +26 -0
  49. package/templates/basic/nest/resolver.ts.eta +12 -56
  50. package/templates/basic/nest/schema.ts.eta +133 -0
  51. package/templates/basic/nest/service.ts.eta +86 -73
  52. package/templates/basic/nest/service.ts.eta-backup +50 -0
  53. package/templates/basic/nuxt/default.ts.eta +10 -8
  54. package/templates/basic/nuxt/pages.[id].vue.eta +2 -2
  55. package/templates/basic/nuxt/pages.form.vue.eta +2 -2
  56. package/templates/basic/nuxt/pages.viewer.vue.eta +2 -2
  57. package/templates/basic/nuxt/simpleapp.doc.ts.eta +1 -1
  58. package/templates/basic/nuxt/simpleapp.generate.client.ts.eta +7 -5
  59. package/templates/nest/src/app.module.ts._eta +53 -69
  60. package/templates/nest/src/main.ts._eta +1 -1
  61. package/templates/nest/src/simple-app/.core/features/auth/api-key/api-key.service.ts.eta +29 -0
  62. package/templates/nest/src/simple-app/.core/features/auth/api-key/api-key.type.ts.eta +5 -0
  63. package/templates/nest/src/simple-app/.core/features/auth/api-key/validators/interface.ts.eta +7 -0
  64. package/templates/nest/src/simple-app/.core/features/auth/api-key/validators/mini-api-key.validator.ts.eta +30 -0
  65. package/templates/nest/src/simple-app/.core/features/auth/api-key/validators/static-api-key.validator.ts.eta +27 -0
  66. package/templates/nest/src/simple-app/.core/features/auth/auth.module.ts.eta +9 -0
  67. package/templates/nest/src/{simpleapp/generate/commons/roles → simple-app/.core/features/auth/role-guard}/roles.enum.ts.eta +7 -7
  68. package/templates/nest/src/{simpleapp/generate/commons/roles → simple-app/.core/features/auth/role-guard}/roles.guard.ts.eta +1 -1
  69. package/templates/nest/src/simple-app/.core/features/auto-increament/auto-increament.model.ts.eta +10 -0
  70. package/templates/nest/src/simple-app/.core/features/auto-increament/auto-increament.module.ts.eta +18 -0
  71. package/templates/nest/src/simple-app/.core/features/auto-increament/auto-increament.schema.ts.eta +119 -0
  72. package/templates/nest/src/simple-app/.core/features/auto-increament/auto-increament.service.ts.eta +65 -0
  73. package/templates/nest/src/simple-app/.core/features/cron/base/cron.base.ts.eta +13 -0
  74. package/templates/nest/src/simple-app/.core/features/cron/cron-system/cron-system.module.ts.eta +17 -0
  75. package/templates/nest/src/simple-app/.core/features/cron/cron-system/cron-system.service.ts.eta +37 -0
  76. package/templates/nest/src/simple-app/.core/features/cron/cron-system/schemas/index.ts.eta +2 -0
  77. package/templates/nest/src/simple-app/.core/features/cron/cron.module.ts.eta +10 -0
  78. package/templates/nest/src/simple-app/.core/features/document-no-format/document-no-format.controller.ts.eta +31 -0
  79. package/templates/nest/src/simple-app/.core/features/document-no-format/document-no-format.model.ts.eta +15 -0
  80. package/templates/nest/src/simple-app/.core/features/document-no-format/document-no-format.module.ts.eta +12 -0
  81. package/templates/nest/src/simple-app/.core/features/document-no-format/document-no-format.schema.ts.eta +162 -0
  82. package/templates/nest/src/simple-app/.core/features/document-no-format/document-no-format.service.ts.eta +189 -0
  83. package/templates/nest/src/simple-app/.core/features/event/event.module.ts.eta +9 -0
  84. package/templates/nest/src/simple-app/.core/features/event/event.type.ts.eta +23 -0
  85. package/templates/nest/src/simple-app/.core/features/event/interface/event-after-create.interface.ts.eta +5 -0
  86. package/templates/nest/src/simple-app/.core/features/event/interface/event-after-delete.interface.ts.eta +5 -0
  87. package/templates/nest/src/simple-app/.core/features/event/interface/event-after-set-status.interface.ts.eta +5 -0
  88. package/templates/nest/src/simple-app/.core/features/event/interface/event-after-update.interface.ts.eta +5 -0
  89. package/templates/nest/src/simple-app/.core/features/event/interface/event-before-create.interface.ts.eta +5 -0
  90. package/templates/nest/src/simple-app/.core/features/event/interface/event-before-delete.interface.ts.eta +5 -0
  91. package/templates/nest/src/simple-app/.core/features/event/interface/event-before-set-status.interface.ts.eta +5 -0
  92. package/templates/nest/src/simple-app/.core/features/event/interface/event-before-update.interface.ts.eta +5 -0
  93. package/templates/nest/src/simple-app/.core/features/event/interface/index.ts.eta +8 -0
  94. package/templates/nest/src/simple-app/.core/features/foreign-key/foreign-key.module.ts.eta +16 -0
  95. package/templates/nest/src/simple-app/.core/features/log/log.module.ts.eta +20 -0
  96. package/templates/nest/src/simple-app/.core/features/log/log.service.ts.eta +68 -0
  97. package/templates/nest/src/simple-app/.core/features/log/schemas/api-event.schema.ts.eta +57 -0
  98. package/templates/nest/src/simple-app/.core/features/log/schemas/document-event.schema.ts.eta +87 -0
  99. package/templates/nest/src/simple-app/.core/features/log/schemas/index.ts.eta +2 -0
  100. package/templates/nest/src/simple-app/.core/features/maintenance/maintenance.controller.ts.eta +84 -0
  101. package/templates/nest/src/simple-app/.core/features/maintenance/maintenance.module.ts.eta +19 -0
  102. package/templates/nest/src/simple-app/.core/features/maintenance/maintenance.service.ts.eta +86 -0
  103. package/templates/nest/src/simple-app/.core/features/maintenance/schemas/environment.ts.eta +23 -0
  104. package/templates/nest/src/{simpleapp/maintenance/apischemas → simple-app/.core/features/maintenance/schemas}/index.ts.eta +1 -1
  105. package/templates/nest/src/simple-app/.core/features/mini-app/developer-portal/developer-portal-bridge.service.ts.eta.eta +31 -0
  106. package/templates/nest/src/simple-app/.core/features/mini-app/developer-portal/developer-portal-env-development.service.ts.eta +124 -0
  107. package/templates/nest/src/simple-app/.core/features/mini-app/developer-portal/developer-portal-env-production.service.ts.eta +50 -0
  108. package/templates/nest/src/simple-app/.core/features/mini-app/developer-portal/developer-portal.controller.ts.eta +41 -0
  109. package/templates/nest/src/simple-app/.core/features/mini-app/developer-portal/developer-portal.schema.ts.eta +18 -0
  110. package/templates/nest/src/simple-app/.core/features/mini-app/developer-portal/developer-portal.service.ts.eta +94 -0
  111. package/templates/nest/src/simple-app/.core/features/mini-app/developer-portal/dto/developer-portal-create-app.dto.ts.eta +22 -0
  112. package/templates/nest/src/simple-app/.core/features/mini-app/developer-portal/dto/developer-portal-publish-app.dto.ts.eta +0 -0
  113. package/templates/nest/src/simple-app/.core/features/mini-app/dto/imports.ts.eta +2 -0
  114. package/templates/nest/src/simple-app/.core/features/mini-app/dto/index.ts.eta +2 -0
  115. package/templates/nest/src/simple-app/.core/features/mini-app/dto/mini-app.ts.eta +55 -0
  116. package/templates/nest/src/simple-app/.core/features/mini-app/mini-app-manager/mini-app-manager-bridge.service.ts.eta +162 -0
  117. package/templates/nest/src/simple-app/.core/features/mini-app/mini-app-manager/mini-app-manager-env-development.service.ts.eta +140 -0
  118. package/templates/nest/src/simple-app/.core/features/mini-app/mini-app-manager/mini-app-manager-env-production.service.ts.eta +125 -0
  119. package/templates/nest/src/simple-app/.core/features/mini-app/mini-app-manager/mini-app-manager-policy.service.ts.eta +43 -0
  120. package/templates/nest/src/simple-app/.core/features/mini-app/mini-app-manager/mini-app-manager.controller.ts.eta +81 -0
  121. package/templates/nest/src/simple-app/.core/features/mini-app/mini-app-manager/mini-app-manager.enum.ts.eta +5 -0
  122. package/templates/nest/src/simple-app/.core/features/mini-app/mini-app-manager/mini-app-manager.error.ts.eta +24 -0
  123. package/templates/nest/src/simple-app/.core/features/mini-app/mini-app-manager/mini-app-manager.processor.ts.eta +309 -0
  124. package/templates/nest/src/simple-app/.core/features/mini-app/mini-app-manager/mini-app-manager.service.ts.eta +346 -0
  125. package/templates/nest/src/simple-app/.core/features/mini-app/mini-app-scope/mini-app-scope.decorator.ts.eta +5 -0
  126. package/templates/nest/src/simple-app/.core/features/mini-app/mini-app-scope/mini-app-scope.guard.ts.eta +43 -0
  127. package/templates/nest/src/simple-app/.core/features/mini-app/mini-app-scope/mini-app-scope.service.ts.eta +101 -0
  128. package/templates/nest/src/simple-app/.core/features/mini-app/mini-app.module.ts.eta +24 -0
  129. package/templates/nest/src/simple-app/.core/features/mini-app/types/miniApp.ts.eta +23 -0
  130. package/templates/nest/src/simple-app/.core/features/mini-app/utils/mini-app.util.ts.eta +26 -0
  131. package/templates/nest/src/simple-app/.core/features/policy/policy.module.ts.eta +12 -0
  132. package/templates/nest/src/simple-app/.core/features/policy/policy.service.ts.eta +45 -0
  133. package/templates/nest/src/{simpleapp/profile/profile.controller.ts._eta → simple-app/.core/features/profile/profile.controller.ts.eta} +37 -83
  134. package/templates/nest/src/simple-app/.core/features/profile/profile.module.ts.eta +22 -0
  135. package/templates/nest/src/simple-app/.core/features/profile/profile.schema.ts.eta +165 -0
  136. package/templates/nest/src/{simpleapp/profile/profile.service.ts._eta → simple-app/.core/features/profile/profile.service.ts.eta} +36 -48
  137. package/templates/nest/src/simple-app/.core/features/queue/queue-base/queue-base.consumer.ts.eta +196 -0
  138. package/templates/nest/src/simple-app/.core/features/queue/queue-base/queue-base.producer.ts.eta +147 -0
  139. package/templates/nest/src/simple-app/.core/features/queue/queue-user-context/queue-user-context.service.ts.eta +35 -0
  140. package/templates/nest/src/simple-app/.core/features/queue/queue.module.ts.eta +24 -0
  141. package/templates/nest/src/simple-app/.core/features/queue/queue.type.ts.eta +75 -0
  142. package/templates/nest/src/simple-app/.core/features/simple-app-core-features.module.ts.eta +51 -0
  143. package/templates/nest/src/{simpleapp/generate/commons/robotuser.service.ts.eta → simple-app/.core/features/user-context/robot-user.service.ts.eta} +27 -16
  144. package/templates/nest/src/simple-app/.core/features/user-context/user-context.module.ts.eta +24 -0
  145. package/templates/nest/src/simple-app/.core/features/user-context/user-context.type.ts.eta +15 -0
  146. package/templates/nest/src/{simpleapp/generate/commons → simple-app/.core/features/user-context}/user.context.ts.eta +469 -449
  147. package/templates/nest/src/{simpleapp/generate/commons/runwebhook.service.ts.eta → simple-app/.core/features/webhook/run-webhook.service.ts.eta} +20 -17
  148. package/templates/nest/src/simple-app/.core/features/webhook/schemas/index.ts.eta +2 -0
  149. package/templates/nest/src/simple-app/.core/features/webhook/schemas/webhook-log.schema.ts.eta +116 -0
  150. package/templates/nest/src/simple-app/.core/features/webhook/schemas/webhook.schema.ts.eta +177 -0
  151. package/templates/nest/src/simple-app/.core/features/webhook/webhook.module.ts.eta +21 -0
  152. package/templates/nest/src/{simpleapp/generate/controllers/simpleapp.controller.ts.eta → simple-app/.core/framework/base/simple-app.controller.ts.eta} +20 -35
  153. package/templates/nest/src/{simpleapp/generate/processors/simpleapp.processor.ts.eta → simple-app/.core/framework/base/simple-app.service.ts.eta} +228 -140
  154. package/templates/nest/src/simple-app/.core/framework/custom-exception.ts.eta +26 -0
  155. package/templates/nest/src/simple-app/.core/framework/framework.module.ts.eta +12 -0
  156. package/templates/nest/src/simple-app/.core/framework/schemas/index.ts.eta +3 -0
  157. package/templates/nest/src/simple-app/.core/framework/schemas/others.schema.ts.eta +153 -0
  158. package/templates/nest/src/simple-app/.core/framework/schemas/simple-app.schema.ts.eta +172 -0
  159. package/templates/nest/src/{simpleapp/generate/commons/interceptors/response.interceptor.ts.eta → simple-app/.core/framework/simple-app.interceptor.ts.eta} +12 -22
  160. package/templates/nest/src/{simpleapp/generate/commons/middlewares/tenant.middleware.ts.eta → simple-app/.core/framework/simple-app.middleware.ts.eta} +28 -26
  161. package/templates/nest/src/simple-app/.core/readme.md.eta +3 -0
  162. package/templates/nest/src/simple-app/.core/resources/core-resources.module.ts.eta +38 -0
  163. package/templates/nest/src/simple-app/.core/simple-app-core.module.ts.eta +18 -0
  164. package/templates/nest/src/simple-app/.core/utils/dayjs.ts.eta +47 -0
  165. package/templates/nest/src/simple-app/.core/utils/locale-tool.ts.eta +11 -0
  166. package/templates/nest/src/simple-app/.core/utils/string-utils.ts.eta +1 -0
  167. package/templates/nest/src/simple-app/.resources/readme.md.eta +3 -0
  168. package/templates/nest/src/simple-app/.resources/resources.module.ts.eta +36 -0
  169. package/templates/nest/src/simple-app/apis/readme.md.eta +9 -0
  170. package/templates/nest/src/simple-app/apis/resource-api.module.ts.eta +37 -0
  171. package/templates/nest/src/simple-app/events/branch-event/branch-event.module.ts._eta +20 -0
  172. package/templates/nest/src/simple-app/events/branch-event/branch-event.service.ts._eta +43 -0
  173. package/templates/nest/src/simple-app/events/branch-event/branch-event.type.ts._eta +7 -0
  174. package/templates/nest/src/simple-app/events/events.module.ts._eta +17 -0
  175. package/templates/nest/src/simple-app/events/organization-event/organization-event.module.ts._eta +13 -0
  176. package/templates/nest/src/simple-app/events/organization-event/organization-event.service.ts._eta +52 -0
  177. package/templates/nest/src/simple-app/events/organization-event/organization-event.type.ts._eta +1 -0
  178. package/templates/nest/src/simple-app/events/permission-event/permission-event.module.ts.eta +11 -0
  179. package/templates/nest/src/simple-app/events/permission-event/permission-event.service.ts.eta +33 -0
  180. package/templates/nest/src/simple-app/events/permission-event/permission-event.type.ts.eta +1 -0
  181. package/templates/nest/src/simple-app/events/readme.md.eta +76 -0
  182. package/templates/nest/src/simple-app/events/tenant-event/tenant-event.module.ts_eta +12 -0
  183. package/templates/nest/src/simple-app/events/tenant-event/tenant-event.service.ts_eta +30 -0
  184. package/templates/nest/src/simple-app/events/tenant-event/tenant-event.type.ts_eta +1 -0
  185. package/templates/nest/src/{simpleapp/additional.module.ts._eta → simple-app/features/features.module.ts._eta} +8 -7
  186. package/templates/nest/src/{printapi/printapi.module.ts.eta → simple-app/features/print/print.module.ts.eta} +4 -4
  187. package/templates/nest/src/{printapi/printapi.service.ts.eta → simple-app/features/print/print.service.ts.eta} +7 -7
  188. package/templates/nest/src/simple-app/features/readme.md._eta +6 -0
  189. package/templates/nest/src/simple-app/simple-app.module.ts.eta +32 -0
  190. package/templates/nuxt/.env._eta +2 -0
  191. package/templates/nuxt/app.vue.eta +15 -7
  192. package/templates/nuxt/components/header/HeaderSelectBranch.vue.eta +2 -1
  193. package/templates/nuxt/components/image/ImageAvatar.vue._eta +63 -0
  194. package/templates/nuxt/components/image/ImageOrganization.vue._eta +77 -0
  195. package/templates/nuxt/components/simpleApp/SimpleAppForm.vue.eta +1 -1
  196. package/templates/nuxt/components/simpleApp/SimpleAppFormToolBar.vue._eta +95 -20
  197. package/templates/nuxt/components/user/UserButtonCreateTenant.vue._eta +20 -21
  198. package/templates/nuxt/components/user/UserTenantPicker.vue._eta +1 -1
  199. package/templates/nuxt/composables/docformat.generate.ts.eta +4 -2
  200. package/templates/nuxt/enums/enums.generate.ts.eta +1 -1
  201. package/templates/nuxt/middleware/30.acl.global.ts.eta +6 -6
  202. package/templates/nuxt/nuxt.config.ts._eta +1 -0
  203. package/templates/nuxt/pages/login.vue._eta +21 -15
  204. package/templates/nuxt/pages/profile.vue._eta +24 -32
  205. package/templates/nuxt/plugins/20.simpleapp-userstore.ts.eta +31 -24
  206. package/templates/nuxt/plugins/50.simpleapp-client.ts.eta +2 -2
  207. package/templates/nuxt/providers/my-provider.ts.eta +5 -6
  208. package/templates/nuxt/simpleapp/generate/clients/SimpleAppClient.ts.eta +1 -0
  209. package/templates/nuxt/simpleapp/generate/defaults/index.ts.eta +1 -1
  210. package/templates/nuxt/simpleapp/generate/types/index.ts.eta +1 -1
  211. package/templates/nuxt/types/schema.ts.eta +1 -0
  212. package/templates/nuxt/types/user.ts.eta +39 -38
  213. package/templates/project/build.sh.eta +2 -2
  214. package/templates/basic/nest/apischema.ts.eta +0 -96
  215. package/templates/basic/nest/processor.ts.eta +0 -86
  216. package/templates/nest/src/cloudapi/cloudapi.module.ts._eta +0 -15
  217. package/templates/nest/src/cloudapi/cloudapi.service.ts._eta +0 -15
  218. package/templates/nest/src/enums/enums.generate.ts.eta +0 -23
  219. package/templates/nest/src/simpleapp/apischemas/index.ts._eta +0 -85
  220. package/templates/nest/src/simpleapp/generate/apischemas/index.ts.eta +0 -15
  221. package/templates/nest/src/simpleapp/generate/apischemas/simpleapp.apischema.ts.eta +0 -62
  222. package/templates/nest/src/simpleapp/generate/commons/audittrail.service.ts.eta +0 -52
  223. package/templates/nest/src/simpleapp/generate/commons/customkeycloa.guard.ts.eta +0 -45
  224. package/templates/nest/src/simpleapp/generate/commons/docnogenerator.service.ts.eta +0 -129
  225. package/templates/nest/src/simpleapp/generate/commons/providers/workflow.provider.ts.etax +0 -87
  226. package/templates/nest/src/simpleapp/generate/jsonschemas/index.ts.eta +0 -11
  227. package/templates/nest/src/simpleapp/generate/models/apievent.model.ts.eta +0 -27
  228. package/templates/nest/src/simpleapp/generate/processors/autoinc.processor.ts.eta +0 -88
  229. package/templates/nest/src/simpleapp/generate/processors/branch.processor.ts.eta +0 -110
  230. package/templates/nest/src/simpleapp/generate/processors/docno.processor.ts.eta +0 -77
  231. package/templates/nest/src/simpleapp/generate/processors/org.processor.ts.eta +0 -110
  232. package/templates/nest/src/simpleapp/generate/processors/perm.processor.ts.eta +0 -71
  233. package/templates/nest/src/simpleapp/generate/processors/sysmsg.processor.ts.eta +0 -49
  234. package/templates/nest/src/simpleapp/generate/processors/tenant.processor.ts.eta +0 -52
  235. package/templates/nest/src/simpleapp/generate/processors/webhooklog.processor.ts.eta +0 -45
  236. package/templates/nest/src/simpleapp/generate/types/index.ts.eta +0 -7
  237. package/templates/nest/src/simpleapp/generate/types/schema.type.ts.eta +0 -193
  238. package/templates/nest/src/simpleapp/generate/types/simpleapp.type.ts.eta +0 -299
  239. package/templates/nest/src/simpleapp/generate/types/workflow.type.ts.eta +0 -15
  240. package/templates/nest/src/simpleapp/generate/workflow/formschema/SimpleApproveReject.ts.eta +0 -8
  241. package/templates/nest/src/simpleapp/generate/workflow/formschema/index.ts.eta +0 -7
  242. package/templates/nest/src/simpleapp/generate/workflow/workflow.apischema.ts.eta +0 -136
  243. package/templates/nest/src/simpleapp/generate/workflow/workflow.config.ts.eta +0 -79
  244. package/templates/nest/src/simpleapp/generate/workflow/workflow.controller.ts.eta +0 -414
  245. package/templates/nest/src/simpleapp/generate/workflow/workflow.delegate.ts.eta +0 -201
  246. package/templates/nest/src/simpleapp/generate/workflow/workflow.service.ts.eta +0 -641
  247. package/templates/nest/src/simpleapp/generate/workflow/workflow.type.ts.eta +0 -98
  248. package/templates/nest/src/simpleapp/generate/workflow/workflow.userservice.ts.eta +0 -83
  249. package/templates/nest/src/simpleapp/maintenance/apischemas/environment.ts.eta +0 -11
  250. package/templates/nest/src/simpleapp/maintenance/maintenance.controller.ts.eta +0 -72
  251. package/templates/nest/src/simpleapp/maintenance/maintenance.service.ts.eta +0 -88
  252. package/templates/nest/src/simpleapp/maintenance/models/environment.model.ts.eta +0 -16
  253. package/templates/nest/src/simpleapp/profile/profile.apischema.ts._eta +0 -95
  254. package/templates/nest/src/simpleapp/resolvers/readme.md.eta +0 -1
  255. package/templates/nest/src/simpleapp/services/autoinc.service.ts.etaxx +0 -59
  256. package/templates/nest/src/simpleapp/services/branch.service.ts.etaxxx +0 -83
  257. package/templates/nest/src/simpleapp/services/docno.service.ts.etaxxx +0 -59
  258. package/templates/nest/src/simpleapp/services/org.service.ts.etaxxx +0 -37
  259. package/templates/nest/src/simpleapp/services/perm.service.ts.etaxxx +0 -56
  260. package/templates/nest/src/simpleapp/services/sysmsg.service.ts._etaxxx +0 -43
  261. package/templates/nest/src/simpleapp/services/tenant.service.ts.etaxxx +0 -38
  262. package/templates/nest/src/simpleapp/services/user.service.ts.eta.old +0 -118
  263. package/templates/nest/src/simpleapp/services/userresolver.service.ts._eta +0 -67
  264. package/templates/nest/src/simpleapp/services/webhook.service.ts._eta +0 -37
  265. package/templates/nest/src/simpleapp/simpleapp.module.ts.eta +0 -85
  266. package/templates/nest/src/simpleapp/types/index.ts._eta +0 -45
  267. package/templates/nest/src/simpleapp/webhooks/branch.ts._eta +0 -44
  268. package/templates/nest/src/simpleapp/webhooks/index.ts._eta +0 -21
  269. package/templates/nest/src/simpleapp/workflows/bpmn/readme.md._eta +0 -1
  270. package/templates/nest/src/simpleapp/workflows/listeners/simpleapp.listener.ts.eta +0 -31
  271. package/templates/nest/src/simpleapp/workflows/readme.md._eta +0 -1
  272. package/templates/nuxt/components/image/ImageAvatar.vue.eta +0 -56
  273. package/templates/nuxt/components/image/ImageOrganization.vue.eta +0 -66
  274. /package/src/buildinschemas/{webhook.ts → webhook.ts.backup} +0 -0
  275. /package/src/buildinschemas/{webhooklog.ts → webhooklog.ts.backup} +0 -0
  276. /package/templates/basic/nest/{type.ts.eta → type.ts.eta-backup} +0 -0
  277. /package/templates/nest/src/{simpleapp/generate/commons/customkeycloak.guard.ts.eta → simple-app/.core/features/auth/keycloak/keycloak.guard.ts.eta} +0 -0
  278. /package/templates/nest/src/{simpleapp/generate/commons/roles → simple-app/.core/features/auth/role-guard}/roles.decorator.ts.eta +0 -0
  279. /package/templates/nest/src/{simpleapp/generate/commons/roles → simple-app/.core/features/auth/role-guard}/roles.group.ts.eta +0 -0
  280. /package/templates/nest/src/{simpleapp/generate/commons/dicts/documents.ts.eta → simple-app/.core/features/document-no-format/document.dict.ts.eta} +0 -0
  281. /package/templates/nest/src/{simpleapp/generate/commons/dicts/foreignkeys.ts.eta → simple-app/.core/features/foreign-key/foreignkeys.dict.ts.eta} +0 -0
  282. /package/templates/nest/src/{simpleapp/maintenance/dbupdate → simple-app/.core/features/maintenance/db-update}/1.00.00/index.ts._eta +0 -0
  283. /package/templates/nest/src/{simpleapp/maintenance/dbupdate → simple-app/.core/features/maintenance/db-update}/index.ts._eta +0 -0
  284. /package/templates/nest/src/{simpleapp/maintenance/apischemas/dbupdate.ts.eta → simple-app/.core/features/maintenance/schemas/db-update.ts.eta} +0 -0
  285. /package/templates/nest/src/{simpleapp/profile/profile.types.ts.eta → simple-app/.core/features/profile/profile.types.ts.eta-backup} +0 -0
  286. /package/templates/nest/src/{simpleapp/generate/commons/decorators → simple-app/.core/features/user-context}/appuser.decorator.ts.eta +0 -0
  287. /package/templates/nest/src/{simpleapp/generate/commons/exceptions/SimpleAppExceptionFilter.ts.eta → simple-app/.core/framework/exception-filter.ts.eta} +0 -0
  288. /package/templates/nest/src/{simpleapp/generate/commons → simple-app/.core/utils}/encryption.static.ts.eta +0 -0
  289. /package/templates/nest/src/{simpleapp → simple-app}/.gitignore.eta +0 -0
  290. /package/templates/nest/src/{printapi → simple-app/features/print}/api/.gitignore.eta +0 -0
  291. /package/templates/nest/src/{printapi → simple-app/features/print}/api/.npmignore.eta +0 -0
  292. /package/templates/nest/src/{printapi → simple-app/features/print}/api/.openapi-generator/FILES.eta +0 -0
  293. /package/templates/nest/src/{printapi → simple-app/features/print}/api/.openapi-generator/VERSION.eta +0 -0
  294. /package/templates/nest/src/{printapi → simple-app/features/print}/api/.openapi-generator-ignore.eta +0 -0
  295. /package/templates/nest/src/{printapi → simple-app/features/print}/api/api.ts.eta +0 -0
  296. /package/templates/nest/src/{printapi → simple-app/features/print}/api/base.ts.eta +0 -0
  297. /package/templates/nest/src/{printapi → simple-app/features/print}/api/common.ts.eta +0 -0
  298. /package/templates/nest/src/{printapi → simple-app/features/print}/api/configuration.ts.eta +0 -0
  299. /package/templates/nest/src/{printapi → simple-app/features/print}/api/git_push.sh.eta +0 -0
  300. /package/templates/nest/src/{printapi → simple-app/features/print}/api/index.ts.eta +0 -0
  301. /package/templates/nest/src/{printapi → simple-app/features/print}/api/openapitools.json.eta +0 -0
  302. /package/templates/project/{sharelibs → share-libs}/hello.ts._eta +0 -0
  303. /package/templates/project/{sharelibs → share-libs}/index.ts.eta +0 -0
  304. /package/templates/project/{sharelibs → share-libs}/money.ts.eta +0 -0
  305. /package/templates/project/{sharelibs → share-libs}/validate.ts.eta +0 -0
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * This file was automatically generated by simpleapp generator. Every
3
3
  * MODIFICATION OVERRIDE BY GENERATEOR
4
- * last change 2024-01-27
4
+ * last change 2025-09-01
5
5
  * Author: Ks Tan
6
6
  */
7
- import { Inject, Injectable, Logger } from '@nestjs/common';
7
+ import { Injectable, Logger } from '@nestjs/common';
8
8
  import jsonpath from 'jsonpath';
9
9
  import _ from 'lodash';
10
10
 
@@ -14,27 +14,31 @@ import Ajv from 'ajv';
14
14
  import addErrors from 'ajv-errors';
15
15
  import addFormats from 'ajv-formats';
16
16
  import { FilterQuery, Model, PipelineStage, mongo } from 'mongoose';
17
- import { CloudApiService } from 'src/cloudapi/cloudapi.service';
18
- import { CustomException } from 'src/customexception';
19
- import { PrintApiService } from 'src/printapi/printapi.service';
20
- import { AuditTrail } from '../commons/audittrail.service';
21
- import { foreignkeys } from '../commons/dicts/foreignkeys';
22
- import { DocNumberFormatGenerator } from '../commons/docnogenerator.service';
23
- import { RunWebhookService } from '../commons/runwebhook.service';
24
- import { UserContext } from '../commons/user.context';
25
- import { CheckMutipleUnionExistResponse, DefaultHooks, DeleteResultType, IsolationType, MoreProjectionType, TextSearchBody, WorkflowName } from '../types';
17
+ // import { CloudApiService } from 'src/cloudapi/cloudapi.service';
18
+ import { foreignkeys } from '../../features/foreign-key/foreignkeys.dict';
19
+ import { CustomException } from '../custom-exception';
20
+
21
+ import { camelToKebab } from 'src/simple-app/.core/utils/string-utils';
22
+ import { DocumentNoFormatService } from '../../features/document-no-format/document-no-format.service';
23
+ import { UserContext } from '../../features/user-context/user.context';
24
+ import { RunWebhookService } from '../../features/webhook/run-webhook.service';
25
+ import { UniqueKeyExistResponse, DeleteResultType, IsolationType, MoreProjectionType, SchemaFields, TextSearchBody, PatchManyRequest } from '../schemas';
26
+ import { SimpleAppLogService } from '../../features/log/log.service';
26
27
 
27
28
  @Injectable()
28
- export class SimpleAppService<T extends { _id?: string; __v?: number }> {
29
- @Inject(EventEmitter2)
30
- protected eventEmitter: EventEmitter2;
31
- @Inject(CloudApiService)
32
- protected cloudapi: CloudApiService;
33
- @Inject(PrintApiService)
34
- protected printapi: PrintApiService;
35
- @Inject(RunWebhookService)
29
+ export class SimpleAppService<T extends SchemaFields> {
30
+ // @Inject(EventEmitter2)
31
+ // ;
32
+ // @Inject(CloudApiService)
33
+ // protected cloudapi: CloudApiService;
34
+ // @Inject(PrintApiService)
35
+ // protected printapi: PrintApiService;
36
+ // @Inject(RunWebhookService)
36
37
  protected runWebHook: RunWebhookService;
37
- protected hooks: DefaultHooks<T> = {};
38
+ // @Inject(AuditTrail)
39
+ // protected audittrail: AuditTrail;
40
+ // @Inject(DocNumberFormatGenerator)
41
+ protected docnogenerator: DocumentNoFormatService;
38
42
  protected logger = new Logger();
39
43
  protected strictIsolation = true;
40
44
  protected jsonschema: any = {
@@ -43,6 +47,7 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
43
47
  properties: {},
44
48
  required: [],
45
49
  };
50
+
46
51
  protected documentIdentityCode = 'code';
47
52
  protected documentIdentityLabel = 'label';
48
53
  protected documentName = '-unknowndocname-';
@@ -56,32 +61,29 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
56
61
  protected errorlist = [];
57
62
  protected withDocNumberFormat = false;
58
63
  protected foreignkeys = {};
59
-
60
- @Inject(AuditTrail)
61
- protected audittrail: AuditTrail;
62
-
63
- @Inject(DocNumberFormatGenerator)
64
- protected docnogenerator: DocNumberFormatGenerator;
65
-
64
+ private eventEmitter: EventEmitter2;
65
+ private logSvc:SimpleAppLogService;
66
66
  // protected userprovider = new UserContext() ;
67
67
 
68
- constructor(doctype: string, docname: string, newdoc: Model<T>, isolationtype: IsolationType = IsolationType.org) {
68
+ constructor(doctype: string, docname: string, newdoc: Model<T>, isolationtype: IsolationType = IsolationType.org, eventEmitter: EventEmitter2, docnogenerator: DocumentNoFormatService,logSvc: SimpleAppLogService,runWebHook: RunWebhookService) {
69
69
  // console.log("-------init simpleapp service abstract class -------userprovider=",typeof this.userprovider)
70
+ this.eventEmitter = eventEmitter;
70
71
  this.documentType = doctype.toUpperCase();
71
72
  this.documentName = docname;
72
73
  this.doc = newdoc;
73
-
74
+ this.docnogenerator = docnogenerator;
74
75
  this.isolationtype = isolationtype;
75
- if (this.hooks.init) this.hooks.init();
76
+ this.logSvc = logSvc
77
+ this.runWebHook = runWebHook
76
78
  // this.tenantdoc = tenantdoc
77
79
  }
78
80
  getDocumentType = () => this.documentType;
79
81
  getDocumentName = (capFirst: boolean = false) => (capFirst ? _.upperFirst(this.documentName) : this.documentName);
80
- getRecordId = (): string => this.data._id;
82
+ getRecordId = (): string => this.data?._id ?? '';
81
83
  setSchema = (newschema) => (this.jsonschema = newschema);
82
84
  getSchema = () => this.doc.schema.obj;
83
85
  getJsonSchema = () => this.jsonschema;
84
- getHooks = () => this.hooks;
86
+
85
87
  getData = () => {
86
88
  //console.log('thisdata', this.data);
87
89
  return this.data;
@@ -141,8 +143,8 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
141
143
  };
142
144
  async getAutoComplete(appuser: UserContext, keyword: string, data?: T) {
143
145
  try {
144
- const filter1 = {};
145
- const filter2 = {};
146
+ const filter1: any = {};
147
+ const filter2: any = {};
146
148
  const filters: any[] = [];
147
149
  if (this.jsonschema.properties[this.documentIdentityCode]['type'] == 'string') {
148
150
  filter1[this.documentIdentityCode] = { $regex: keyword, $options: 'i' };
@@ -161,6 +163,7 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
161
163
  if (this.moreAutoCompleteField) {
162
164
  Object.assign(projections, this.moreAutoCompleteField);
163
165
  }
166
+
164
167
  const products = await this.doc.find(filterobj, projections, {
165
168
  // limit: this.LIMITPERPAGE,
166
169
  });
@@ -181,12 +184,12 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
181
184
  */
182
185
  async searchNoIsolation(appuser: UserContext, filters: FilterQuery<T>) {
183
186
  try {
184
- if (this.hooks.beforeSearch) await this.hooks.beforeSearch(appuser, filters);
187
+ //if (this.hooks.beforeSearch) await this.hooks.beforeSearch(appuser, filters);
185
188
  const products = await this.doc.find(filters);
186
189
  const productlist = products.map((p) => {
187
190
  return p;
188
191
  });
189
- if (this.hooks.afterSearch) await this.hooks.afterSearch(appuser, productlist);
192
+ //if (this.hooks.afterSearch) await this.hooks.afterSearch(appuser, productlist);
190
193
 
191
194
  // console.log(products);
192
195
  return productlist;
@@ -218,9 +221,18 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
218
221
 
219
222
  Object.assign(pipeline[0]['$match'], isolationFilter);
220
223
  this.logger.verbose(pipeline, `${this.documentName} aggregate:`);
221
- return await this.doc.aggregate(pipeline, {
224
+
225
+ // if(appuser.getId() == ''){
226
+ // console.log(JSON.stringify(pipeline))
227
+ // }
228
+ const res = await this.doc.aggregate(pipeline, {
222
229
  session: appuser.getDBSession(),
223
230
  });
231
+
232
+ // if(appuser.getId() == ''){
233
+ // console.log(res)
234
+ // }
235
+ return res;
224
236
  } catch (err) {
225
237
  throw new InternalServerErrorException(err);
226
238
  }
@@ -236,7 +248,7 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
236
248
  // console.log("initial search",filters)
237
249
  const newfilters: FilterQuery<T> = { ...filters, ...isolationFilter };
238
250
 
239
- if (this.hooks.beforeSearch) await this.hooks.beforeSearch(appuser, newfilters);
251
+ // if (this.hooks.beforeSearch) await this.hooks.beforeSearch(appuser, newfilters);
240
252
  // console.log("before _find",newfilters)
241
253
  // console.log("this.doc",this.doc)
242
254
  let searchResults: T[] = [];
@@ -253,7 +265,7 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
253
265
  return p;
254
266
  });
255
267
  // console.log("after map",productlist)
256
- if (this.hooks.afterSearch) await this.hooks.afterSearch(appuser, list);
268
+ // if (this.hooks.afterSearch) await this.hooks.afterSearch(appuser, list);
257
269
 
258
270
  // console.log(products);
259
271
  return list;
@@ -309,10 +321,10 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
309
321
  }
310
322
  }
311
323
  async findById(appuser: UserContext, id: string) {
312
- if (this.hooks.beforeFetchRecord) await this.hooks.beforeFetchRecord(appuser, id);
324
+ // if (this.hooks.beforeFetchRecord) await this.hooks.beforeFetchRecord(appuser, id);
313
325
 
314
326
  const data = await this.search(appuser, { _id: id as any });
315
- if (this.hooks.afterFetchRecord) await this.hooks.afterFetchRecord(appuser, data[0]);
327
+ // if (this.hooks.afterFetchRecord) await this.hooks.afterFetchRecord(appuser, data[0]);
316
328
 
317
329
  if (data.length == 1) {
318
330
  // console.log('data0', data[0]);
@@ -323,10 +335,10 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
323
335
  }
324
336
 
325
337
  async findByIdNoIsolation(appuser: UserContext, id: string) {
326
- if (this.hooks.beforeFetchRecord) await this.hooks.beforeFetchRecord(appuser, id);
338
+ // if (this.hooks.beforeFetchRecord) await this.hooks.beforeFetchRecord(appuser, id);
327
339
 
328
340
  const data = await this.searchNoIsolation(appuser, { _id: id as any });
329
- if (this.hooks.afterFetchRecord) await this.hooks.afterFetchRecord(appuser, data[0]);
341
+ // if (this.hooks.afterFetchRecord) await this.hooks.afterFetchRecord(appuser, data[0]);
330
342
 
331
343
  if (data.length == 1) {
332
344
  // console.log('data0', data[0]);
@@ -337,9 +349,7 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
337
349
  }
338
350
 
339
351
  async createManyWithId(appuser: UserContext, datas: T[]) {
340
-
341
- if (Array.isArray(datas)) {
342
-
352
+ if (Array.isArray(datas)) {
343
353
  for (let i = 0; i < datas.length; i++) {
344
354
  const data = datas[i];
345
355
  let isolationFilter: any = { ...appuser.getCreateFilterWithId() };
@@ -357,7 +367,7 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
357
367
  }
358
368
 
359
369
  const result = await this.doc.insertMany(datas, { session: dbsession });
360
- await this.audittrail.addManyEvents(appuser, this.documentName, 'createMany', datas);
370
+ await this.addManyAuditEvents(appuser, this.documentName, 'createMany', datas);
361
371
  for (let i = 0; i < datas.length; i++) {
362
372
  appuser.addInsertedRecordId(this.documentName, datas[i]._id);
363
373
  }
@@ -394,16 +404,19 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
394
404
  this.reCalculateValue(data);
395
405
  await this.validateData(appuser, data);
396
406
  this.applyNestedDateTime(appuser, data, 'create');
397
- if (this.hooks.beforeCreate) await this.hooks.beforeCreate(appuser, data);
407
+
408
+ //new way of hook
409
+ await this.runEvent(appuser, this.setHookName('beforeCreate'), { data: data }, false);
410
+
398
411
  const newdoc = new this.doc(data);
399
412
 
400
413
  try {
401
414
  result = await newdoc.save({ session: dbsession });
402
- await this.audittrail.addEvent(appuser, this.documentName, result._id, 'create', data);
415
+ await this.addAuditEvent(appuser, this.documentName, result._id, 'create', data);
403
416
  appuser.addInsertedRecordId(this.documentName, result._id);
404
417
  } catch (err) {
405
418
  this.logger.error(err);
406
- const processdata = await this.runWorker(appuser, 'processdata.processError', {
419
+ const processdata = await this.runEvent(appuser, 'processdata.processError', {
407
420
  err: err,
408
421
  });
409
422
 
@@ -415,7 +428,8 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
415
428
  }
416
429
 
417
430
  try {
418
- if (this.hooks.afterCreate) await this.hooks.afterCreate(appuser, result);
431
+ //new way of hook
432
+ await this.runEvent(appuser, this.setHookName('afterCreate'), { data: data }, false);
419
433
  await this.callWebhook(appuser, 'create', result);
420
434
 
421
435
  // return result as T;
@@ -450,8 +464,8 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
450
464
  if (dbsession && !dbsession.inTransaction()) {
451
465
  dbsession.startTransaction({ readPreference: 'primary' });
452
466
  }
453
- const result = await this.doc.insertMany(datas,{session:dbsession});
454
- await this.audittrail.addManyEvents(appuser, this.documentName, 'createMany', datas);
467
+ const result = await this.doc.insertMany(datas, { session: dbsession });
468
+ await this.addManyAuditEvents(appuser, this.documentName, 'createMany', datas);
455
469
  return result;
456
470
  } else {
457
471
  throw new BadRequestException(this.getDocumentType() + ': create many only support array');
@@ -486,17 +500,20 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
486
500
  this.logger.debug(data, `after create validation`);
487
501
  this.applyNestedDateTime(appuser, data, 'create');
488
502
 
489
- if (this.hooks.beforeCreate) await this.hooks.beforeCreate(appuser, data);
503
+ //new way of hook
504
+
505
+ await this.runEvent(appuser, this.setHookName('beforeCreate'), { data: data }, false);
506
+
490
507
  this.logger.debug(data, `Create Record ${this.documentName}`);
491
508
  const newdoc = new this.doc(data);
492
509
  await this.identifyForeignKeys(appuser, data);
493
510
  try {
494
511
  result = await newdoc.save({ session: dbsession });
495
- await this.audittrail.addEvent(appuser, this.documentName, result._id, 'create', data);
512
+ await this.addAuditEvent(appuser, this.documentName, result._id, 'create', data);
496
513
  appuser.addInsertedRecordId(this.documentName, result._id);
497
514
  } catch (err) {
498
515
  this.logger.error(err);
499
- const processdata = await this.runWorker(appuser, 'processdata.processError', {
516
+ const processdata = await this.runEvent(appuser, 'processdata.processError', {
500
517
  err: err,
501
518
  });
502
519
 
@@ -508,7 +525,9 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
508
525
  }
509
526
 
510
527
  try {
511
- if (this.hooks.afterCreate) await this.hooks.afterCreate(appuser, result);
528
+ //new way of hook
529
+ await this.runEvent(appuser, this.setHookName('afterCreate'), { data: result }, false);
530
+
512
531
  await this.callWebhook(appuser, 'create', result);
513
532
  return result as T;
514
533
  } catch (err) {
@@ -545,17 +564,19 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
545
564
  this.logger.debug(data, `after create validation`);
546
565
  this.applyNestedDateTime(appuser, data, 'create');
547
566
 
548
- if (this.hooks.beforeCreate) await this.hooks.beforeCreate(appuser, data);
567
+ //new way of hook
568
+ await this.runEvent(appuser, this.setHookName('beforeCreate'), { data: data }, false);
569
+
549
570
  this.logger.debug(data, `Create Record ${this.documentName}`);
550
571
  const newdoc = new this.doc(data);
551
572
  await this.identifyForeignKeys(appuser, data);
552
573
  try {
553
574
  result = await newdoc.save({ session: dbsession });
554
- await this.audittrail.addEvent(appuser, this.documentName, result._id, 'create', data);
575
+ await this.addAuditEvent(appuser, this.documentName, result._id, 'create', data);
555
576
  appuser.addInsertedRecordId(this.documentName, result._id);
556
577
  } catch (err) {
557
578
  this.logger.error(err);
558
- const processdata = await this.runWorker(appuser, 'processdata.processError', {
579
+ const processdata = await this.runEvent(appuser, 'processdata.processError', {
559
580
  err: err,
560
581
  });
561
582
 
@@ -567,7 +588,9 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
567
588
  }
568
589
 
569
590
  try {
570
- if (this.hooks.afterCreate) await this.hooks.afterCreate(appuser, result);
591
+ //new way of hook
592
+ await this.runEvent(appuser, this.setHookName('afterCreate'), { data: result }, false);
593
+
571
594
  await this.callWebhook(appuser, 'create', result);
572
595
  return result as T;
573
596
  } catch (err) {
@@ -612,9 +635,9 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
612
635
  ajv.addKeyword({ keyword: 'x-simpleapp-config', schemaType: 'object' });
613
636
  this.logger.debug('run hook during validation');
614
637
  let issuccess = true;
615
- if (this.hooks.beforeValidation) {
616
- issuccess = await this.hooks.beforeValidation(appuser, data, _id);
617
- }
638
+ // if (this.hooks.beforeValidation) {
639
+ // issuccess = await this.hooks.beforeValidation(appuser, data, _id);
640
+ // }
618
641
  // const issuccess = await this.hook(appuser, HookType.beforeValidation, data);
619
642
  if (!issuccess) {
620
643
  const errormsg: string[] = [];
@@ -638,8 +661,6 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
638
661
  this.logger.error(JSON.stringify(validate.errors), 'validate errors:');
639
662
  throw new BadRequestException('Data validation failed', validate.errors as HttpExceptionOptions);
640
663
  }
641
- //no check for duplicate those
642
- if (this.hooks.afterValidation) await this.hooks.afterValidation(appuser, data, _id);
643
664
  }
644
665
 
645
666
  polishIsolationFilter = (filterIsolation: any, data: any = {}) => {
@@ -681,7 +702,10 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
681
702
 
682
703
  let dependency;
683
704
  try {
684
- if (this.hooks.beforeDelete) await this.hooks.beforeDelete(appuser, id, deletedata);
705
+ //new way of hook
706
+ await this.runEvent(appuser, this.setHookName('beforeDelete'), { id: id, deleteData: deletedata }, false);
707
+
708
+ // if (this.hooks.beforeDelete) await this.hooks.beforeDelete(appuser, id, deletedata);
685
709
  this.logger.debug('delete record', this.documentName, id);
686
710
  dependency = await this.getRelatedRecords(appuser, id);
687
711
  //console.log('dependency', dependency);
@@ -692,7 +716,8 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
692
716
  filterIsolation['_id'] = id;
693
717
  this.logger.debug('delete filter', filterIsolation);
694
718
  const result = await this.doc.deleteOne(filterIsolation).session(dbsession);
695
- await this.audittrail.addEvent(appuser, this.documentName, id, 'delete', deletedata);
719
+
720
+ await this.addAuditEvent(appuser, this.documentName, id, 'delete', deletedata);
696
721
 
697
722
  appuser.addDeletedRecordId(this.documentName, id);
698
723
  const deleteresult: DeleteResultType<T> = {
@@ -702,13 +727,14 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
702
727
  this.logger.debug(deleteresult, ' delete result' + this.doc.collection.name);
703
728
  // this.doc.findByIdAndDelete(id)
704
729
 
705
- if (this.hooks.afterDelete) await this.hooks.afterDelete(appuser, deleteresult, id);
706
- //this.doc.findByIdAndDelete(id);
730
+ //new way of hook
731
+ await this.runEvent(appuser, this.setHookName('afterDelete'), { id: id, deleteData: deletedata }, false);
732
+
707
733
  await this.callWebhook(appuser, 'delete', deletedata);
708
734
  return deleteresult;
709
735
  } else {
710
736
  this.logger.debug('reject query', dependency);
711
-
737
+ console.log(this.documentName, ' dependency :id=', id, dependency);
712
738
  throw new ForbiddenException(`This system detected that the [${this.documentName}] data has been used in other record`, 'Foreignkey constraint');
713
739
  }
714
740
  } catch (err) {
@@ -743,7 +769,10 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
743
769
 
744
770
  await this.identifyForeignKeys(appuser, data);
745
771
 
746
- if (this.hooks.beforeUpdate) await this.hooks.beforeUpdate(appuser, id, existingdata, data);
772
+ //new way of hook
773
+ await this.runEvent(appuser, `${this.documentName}.beforeUpdate`, { id: id, prevData: existingdata, newData: data }, false);
774
+
775
+ // if (this.hooks.beforeUpdate) await this.hooks.beforeUpdate(appuser, id, existingdata, data);
747
776
 
748
777
  const dbsession = appuser.getDBSession();
749
778
  if (dbsession && !dbsession.inTransaction() && !noStartTransaction) {
@@ -768,10 +797,11 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
768
797
  session: dbsession,
769
798
  new: true,
770
799
  });
771
- await this.audittrail.addEvent(appuser, this.documentName, id, 'update', data);
800
+ await this.addAuditEvent(appuser, this.documentName, id, 'update', data);
772
801
 
773
802
  appuser.addUpdatedRecordId(this.documentName, data._id);
774
- if (this.hooks.afterUpdate) await this.hooks.afterUpdate(appuser, id, existingdata, result);
803
+ await this.runEvent(appuser, this.setHookName('afterUpdate'), { id: id, prevData: existingdata, newData: data }, false);
804
+
775
805
  await this.callWebhook(appuser, 'update', result);
776
806
  return result; // await this.findById(appuser, id);
777
807
  } catch (err) {
@@ -799,7 +829,9 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
799
829
 
800
830
  await this.identifyForeignKeys(appuser, data);
801
831
 
802
- if (this.hooks.beforeUpdate) await this.hooks.beforeUpdate(appuser, id, existingdata, data);
832
+ await this.runEvent(appuser, `${this.documentName}.beforeUpdate`, { data: data }, false);
833
+
834
+ // if (this.hooks.beforeUpdate) await this.hooks.beforeUpdate(appuser, id, existingdata, data);
803
835
 
804
836
  const dbsession = appuser.getDBSession();
805
837
  if (dbsession && !dbsession.inTransaction()) {
@@ -824,10 +856,11 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
824
856
  session: dbsession,
825
857
  new: true,
826
858
  });
827
- await this.audittrail.addEvent(appuser, this.documentName, id, 'update', data);
859
+ await this.addAuditEvent(appuser, this.documentName, id, 'update', data);
828
860
 
861
+ await this.runEvent(appuser, this.setHookName('afterUpdate'), { id: id, prevData: existingdata, newData: result }, false);
829
862
  appuser.addUpdatedRecordId(this.documentName, data._id);
830
- if (this.hooks.afterUpdate) await this.hooks.afterUpdate(appuser, id, existingdata, result);
863
+
831
864
  await this.callWebhook(appuser, 'update', result);
832
865
  return result; // await this.findById(appuser, id);
833
866
  } catch (err) {
@@ -837,64 +870,91 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
837
870
  };
838
871
 
839
872
  findIdThenPatch = async (appuser: UserContext, id: string, data: Partial<T>, session: mongo.ClientSession = undefined, skipLog: boolean = false) => {
840
- const existingdata = await this.findById(appuser, id);
841
- if (!existingdata) {
842
- throw new NotFoundException(`${id} not found`, 'not found');
843
- }
844
- if (typeof data.__v == 'number' && data.__v != existingdata.__v) {
845
- throw new BadRequestException(`You submit older version data "v${data.__v}"" but latest version = "v${existingdata.__v}"`);
846
- }
873
+ try {
874
+ const existingdata = await this.findById(appuser, id);
875
+ if (!existingdata) {
876
+ throw new NotFoundException(`${id} not found`, 'not found');
877
+ }
878
+ if (typeof data.__v == 'number' && data.__v != existingdata.__v) {
879
+ throw new BadRequestException(`You submit older version data "v${data.__v}"" but latest version = "v${existingdata.__v}"`);
880
+ }
847
881
 
848
- data.__v = existingdata.__v + 1;
882
+ if (typeof existingdata.__v !== 'number') {
883
+ existingdata.__v = 0;
884
+ }
885
+ data.__v = existingdata.__v + 1;
849
886
 
850
- await this.identifyForeignKeys(appuser, data);
887
+ await this.identifyForeignKeys(appuser, data);
851
888
 
852
- //patch not suitable trigger afterupdate
853
- // if (this.hooks.beforeUpdate) await this.hooks.beforeUpdate(appuser, id, existingdata, data);
889
+ //patch not suitable trigger afterupdate
890
+ // if (this.hooks.beforeUpdate) await this.hooks.beforeUpdate(appuser, id, existingdata, data);
854
891
 
855
- const dbsession = appuser.getDBSession();
856
- if (dbsession && !dbsession.inTransaction()) {
857
- dbsession.startTransaction({ readPreference: 'primary' });
858
- }
859
- // try {
860
- Object.assign(data, appuser.getUpdateFilter());
861
- // Object.assign(existingdata, data);
862
- delete data['_id'];
892
+ const dbsession = appuser.getDBSession();
893
+ if (dbsession && !dbsession.inTransaction()) {
894
+ dbsession.startTransaction({ readPreference: 'primary' });
895
+ }
896
+ // try {
897
+ Object.assign(data, appuser.getUpdateFilter());
898
+ delete data['_id'];
863
899
 
864
- //patch not suitable trigger afterupdate
865
- // this.reCalculateValue(data);
900
+ //patch not suitable trigger afterupdate
901
+ // this.reCalculateValue(data);
866
902
 
867
- // existingdata['_id']=''
868
- // console.log("newdata",data)
869
- //path record no validation
870
- // await this.validateData(appuser, data);
903
+ // existingdata['_id']=''
904
+ // console.log("newdata",data)
905
+ //path record no validation
906
+ // await this.validateData(appuser, data);
871
907
 
872
- const isolationFilter = { ...this.getIsolationFilter(appuser) };
873
- this.polishIsolationFilter(isolationFilter);
908
+ const isolationFilter = { ...this.getIsolationFilter(appuser) };
909
+ this.polishIsolationFilter(isolationFilter);
874
910
 
875
- isolationFilter['_id'] = id;
876
- this.applyNestedDateTime(appuser, data, 'update');
911
+ isolationFilter['_id'] = id;
912
+ this.applyNestedDateTime(appuser, data, 'update');
913
+ // console.log('findid patch ', data);
877
914
 
878
- try {
879
915
  const result = await this.doc.findOneAndUpdate(isolationFilter, data, {
880
916
  session: dbsession,
881
917
  new: true,
882
918
  });
883
919
  //skip audit trail, useful when want to patch x-foreignkey code,label
884
920
  if (!skipLog) {
885
- await this.audittrail.addEvent(appuser, this.documentName, id, 'patch', data);
921
+ await this.addAuditEvent(appuser, this.documentName, id, 'patch', data);
886
922
  }
887
923
  appuser.addUpdatedRecordId(this.documentName, data._id);
888
924
 
889
- //patch not suitable trigger afterupdate
890
- // if (this.hooks.afterUpdate) await this.hooks.afterUpdate(appuser, id, existingdata, result);
891
- // await this.callWebhook(appuser, 'update', result);
892
925
  return result; //await this.findById(appuser, id);
893
926
  } catch (err) {
927
+ this.logger.error(err.message, 'findIdThenPath error');
928
+ console.error(err);
894
929
  throw new InternalServerErrorException(err.message);
895
930
  }
896
931
  };
897
932
 
933
+ async patchMany<T>(appuser: UserContext, data: PatchManyRequest<T>) {
934
+ // filter = {
935
+ // _id: '7eb2661a-6ea6-406e-b868-2e8b19c4658b',
936
+ // 'tuitionClass._id': '5aa69cee-f651-45f4-bad8-0f52a3fb92b5',
937
+ // };
938
+
939
+ const filter = data.filter;
940
+ const patch = data.data as Object;
941
+
942
+ const isolationFilter = { ...this.getIsolationFilter(appuser), ...(filter || {}) };
943
+ this.polishIsolationFilter(isolationFilter);
944
+ this.applyNestedDateTime(appuser, patch, 'update');
945
+
946
+ // Get DB Session
947
+ const dbsession = appuser.getDBSession();
948
+ if (dbsession && !dbsession.inTransaction()) {
949
+ dbsession.startTransaction({ readPreference: 'primary' });
950
+ }
951
+
952
+ const result = await this.doc.updateMany(isolationFilter, { $set: patch }, { session: dbsession });
953
+ await this.addManyAuditEvents(appuser, this.documentName, 'patchMany', [patch]);
954
+
955
+ return result;
956
+ }
957
+
898
958
  //find what foreign key constraint
899
959
  async getRelatedRecords(appuser: UserContext, id: string) {
900
960
  this.logger.debug('get foreignkey for delete:', id);
@@ -965,19 +1025,22 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
965
1025
  }
966
1026
  data['documentStatus'] = docstatus;
967
1027
  // await this.hook(appuser, HookType.beforeSetStatus, data);
968
- if (this.hooks.beforeSetStatus) await this.hooks.beforeSetStatus(appuser, docstatus, data, existdata);
1028
+ await this.runEvent(appuser, this.setHookName('beforeSetStatus'), { docStatus: docstatus, prevData: existdata, newData: data }, false);
1029
+
1030
+ // if (this.hooks.beforeSetStatus) await this.hooks.beforeSetStatus(appuser, docstatus, data, existdata);
969
1031
 
970
1032
  if (data && !data['created']) {
971
1033
  const createresult = await this.create(appuser, data);
972
- if (this.hooks.afterSetStatus) await this.hooks.afterSetStatus(appuser, docstatus, createresult);
973
- await this.audittrail.addEvent(appuser, this.documentName, id, docstatus, data);
1034
+ await this.runEvent(appuser, this.setHookName('afterSetStatus'), { docStatus: docstatus, data: createresult }, false);
1035
+ // if (this.hooks.afterSetStatus) await this.hooks.afterSetStatus(appuser, docstatus, createresult);
1036
+ await this.addAuditEvent(appuser, this.documentName, id, docstatus, data);
974
1037
 
975
1038
  return createresult;
976
1039
  } else {
977
1040
  const updateresult = await this.findIdThenPatch(appuser, id, data);
978
- const finaldata = await this.findById(appuser, id);
979
- if (this.hooks.afterSetStatus) await this.hooks.afterSetStatus(appuser, docstatus, finaldata);
980
- await this.audittrail.addEvent(appuser, this.documentName, id, docstatus, data);
1041
+ const finaldata = await this.findById(appuser, id);
1042
+ await this.runEvent(appuser, this.setHookName('afterSetStatus'), { docStatus: docstatus, data: finaldata }, false);
1043
+ await this.addAuditEvent(appuser, this.documentName, id, docstatus, data);
981
1044
 
982
1045
  await this.callWebhook(appuser, docstatus, finaldata);
983
1046
  return updateresult;
@@ -985,7 +1048,7 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
985
1048
  }
986
1049
 
987
1050
  /**
988
- * similar like runWorker, but it is syncronizely add event into queue and return.
1051
+ * similar like runEvent, but it is syncronizely add event into queue and return.
989
1052
  * No result will return from this method, it also lose appuser db's transaction
990
1053
  * due out of request flow
991
1054
  *
@@ -998,7 +1061,7 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
998
1061
  }
999
1062
 
1000
1063
  /**
1001
- * runWorker design with 2 purpose
1064
+ * runEvent design with 2 purpose
1002
1065
  * 1. we wish developer develop complex programming flow in worker class instead
1003
1066
  * of service class. We wish service class remain simple and easy to understand
1004
1067
  * it wish to do hook and api only
@@ -1013,28 +1076,40 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
1013
1076
  * @param {any} data The data
1014
1077
  * @return {Promise} { description_of_the_return_value }
1015
1078
  */
1016
- async runWorker(appuser: UserContext, eventName: string, payloads: any) {
1017
- const res = await this.eventEmitter.emitAsync(eventName, appuser, payloads);
1018
- if (!this.eventEmitter.hasListeners(eventName)) {
1019
- throw new InternalServerErrorException(`${eventName} seems no listener`);
1020
- }
1021
- if (!res) {
1022
- throw new InternalServerErrorException(`${eventName} is invalid worker`);
1023
- }
1079
+ async runEvent(appuser: UserContext, eventName: string, payloads: any, enforce: boolean = true) {
1080
+ try {
1024
1081
 
1025
- const result = res[0];
1026
- if (result?.name && result?.name.includes('Exception')) throw result;
1027
- return result;
1028
- }
1029
- startWorkflow(appuser: UserContext, processName: WorkflowName, workflowData: any) {
1030
- return this.eventEmitter.emit('workflow.start', appuser, processName, workflowData);
1082
+ if (enforce && !this.eventEmitter.hasListeners(eventName)) {
1083
+ throw new InternalServerErrorException(`${eventName} seems no listener`);
1084
+ } else if (this.eventEmitter.hasListeners(eventName)) {
1085
+ const res = await this.eventEmitter.emitAsync(eventName, appuser, payloads);
1086
+
1087
+ if (!res) {
1088
+ throw new InternalServerErrorException(`${eventName} is invalid worker`);
1089
+ }
1090
+
1091
+ const result = res[0];
1092
+ if (result?.name && result?.name.includes('Exception')) throw result;
1093
+ return result;
1094
+ }
1095
+ } catch (e) {
1096
+ console.error(e);
1097
+ throw e;
1098
+ }
1031
1099
  }
1100
+ // startWorkflow(appuser: UserContext, processName: WorkflowName, workflowData: any) {
1101
+ // return this.eventEmitter.emit('workflow.start', appuser, processName, workflowData);
1102
+ // }
1032
1103
 
1033
1104
  async genNewDocNo(appuser: UserContext, data: T) {
1034
1105
  this.logger.debug('genNewDocNo');
1106
+ // console.log('before genNewDocNo');
1035
1107
  const result = await this.docnogenerator.generateNextNumberFromDocument(appuser, this.documentType, data);
1108
+ // console.log('after genNewDocNo');
1036
1109
  this.logger.debug(result, 'genNewDocNo');
1037
- data[this.documentIdentityCode] = result;
1110
+
1111
+ // been for to convert become object
1112
+ (data as any)[this.documentIdentityCode] = result;
1038
1113
  }
1039
1114
  async runDefault(appuser: UserContext): Promise<unknown> {
1040
1115
  return 'Hello this is ' + this.getDocumentType() + ': ' + this.getDocumentName();
@@ -1125,13 +1200,15 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
1125
1200
  }
1126
1201
  }
1127
1202
 
1128
- async print(appuser: UserContext, id: string, formatid: string) {
1129
- const pdfresult = await this.printapi.getBase64Pdf(appuser, formatid, id);
1130
- return pdfresult;
1203
+ async print(appuser: UserContext, id: string, formatId: string) {
1204
+ // const pdfresult = await this.printapi.getBase64Pdf(appuser, formatid, id);
1205
+ const pdfresult = await this.runEvent(appuser, 'print.getbase64pdf', { id: id, formatId: formatId }, true);
1206
+ // return pdfresult;
1207
+ return Promise.resolve('ok');
1131
1208
  }
1132
1209
 
1133
- async checkMultipleUnionExist(appuser: UserContext, data: string[]): Promise<CheckMutipleUnionExistResponse> {
1134
- const response: CheckMutipleUnionExistResponse = [];
1210
+ async checkUniqueKeyExist(appuser: UserContext, data: string[]): Promise<UniqueKeyExistResponse[]> {
1211
+ const response: UniqueKeyExistResponse[] = [];
1135
1212
  const unionKey = this.getDocumentIdentityCode();
1136
1213
  const searchQuery: any = { [unionKey]: { $in: data } };
1137
1214
  // search for multiple union exist
@@ -1192,12 +1269,23 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
1192
1269
  return pipelines;
1193
1270
  }
1194
1271
 
1272
+ setHookName(hookName) {
1273
+ const resourceName = this.jsonschema['x-simpleapp-config']['resourceName'];
1274
+ return camelToKebab(resourceName) + '.' + camelToKebab(hookName);
1275
+ }
1195
1276
  //only realtime webhook supported at this moment
1196
1277
  async callWebhook(appuser: UserContext, actionName: string, data: any) {
1197
1278
  try {
1198
- await this.runWebHook.run(appuser, this.documentName, actionName, data);
1279
+ await this.runWebHook.run(appuser, this.documentName, actionName, data);
1199
1280
  } catch (e) {
1200
1281
  throw new InternalServerErrorException(e);
1201
1282
  }
1202
1283
  }
1284
+
1285
+ async addAuditEvent(appUser: UserContext, documentName: string, id: string, eventType: string, data: any) {
1286
+ await this.logSvc.addEvent(appUser,documentName,id,eventType,data)
1287
+ }
1288
+ async addManyAuditEvents(appUser: UserContext, documentName: string, eventType: string, datas: any) {
1289
+ await this.logSvc.addManyEvents(appUser,documentName,eventType,datas)
1290
+ }
1203
1291
  }