@simitgroup/simpleapp-generator 1.6.7-o-alpha → 2.0.0-a-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 +4 -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 +18 -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 +25 -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 +82 -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} +7 -11
  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 +20 -0
  152. package/templates/nest/src/{simpleapp/generate/controllers/simpleapp.controller.ts.eta → simple-app/.core/framework/base/simple-app.controller.ts.eta} +13 -35
  153. package/templates/nest/src/{simpleapp/generate/processors/simpleapp.processor.ts.eta → simple-app/.core/framework/base/simple-app.service.ts.eta} +239 -139
  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,30 @@ 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
26
 
27
27
  @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)
28
+ export class SimpleAppService<T extends SchemaFields> {
29
+ // @Inject(EventEmitter2)
30
+ // ;
31
+ // @Inject(CloudApiService)
32
+ // protected cloudapi: CloudApiService;
33
+ // @Inject(PrintApiService)
34
+ // protected printapi: PrintApiService;
35
+ // @Inject(RunWebhookService)
36
36
  protected runWebHook: RunWebhookService;
37
- protected hooks: DefaultHooks<T> = {};
37
+ // @Inject(AuditTrail)
38
+ // protected audittrail: AuditTrail;
39
+ // @Inject(DocNumberFormatGenerator)
40
+ protected docnogenerator: DocumentNoFormatService;
38
41
  protected logger = new Logger();
39
42
  protected strictIsolation = true;
40
43
  protected jsonschema: any = {
@@ -43,6 +46,7 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
43
46
  properties: {},
44
47
  required: [],
45
48
  };
49
+
46
50
  protected documentIdentityCode = 'code';
47
51
  protected documentIdentityLabel = 'label';
48
52
  protected documentName = '-unknowndocname-';
@@ -56,32 +60,28 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
56
60
  protected errorlist = [];
57
61
  protected withDocNumberFormat = false;
58
62
  protected foreignkeys = {};
59
-
60
- @Inject(AuditTrail)
61
- protected audittrail: AuditTrail;
62
-
63
- @Inject(DocNumberFormatGenerator)
64
- protected docnogenerator: DocNumberFormatGenerator;
63
+ private eventEmitter: EventEmitter2;
65
64
 
66
65
  // protected userprovider = new UserContext() ;
67
66
 
68
- constructor(doctype: string, docname: string, newdoc: Model<T>, isolationtype: IsolationType = IsolationType.org) {
67
+ constructor(doctype: string, docname: string, newdoc: Model<T>, isolationtype: IsolationType = IsolationType.org, eventEmitter: EventEmitter2, docnogenerator: DocumentNoFormatService) {
69
68
  // console.log("-------init simpleapp service abstract class -------userprovider=",typeof this.userprovider)
69
+ this.eventEmitter = eventEmitter;
70
70
  this.documentType = doctype.toUpperCase();
71
71
  this.documentName = docname;
72
72
  this.doc = newdoc;
73
-
73
+ this.docnogenerator = docnogenerator;
74
74
  this.isolationtype = isolationtype;
75
- if (this.hooks.init) this.hooks.init();
75
+
76
76
  // this.tenantdoc = tenantdoc
77
77
  }
78
78
  getDocumentType = () => this.documentType;
79
79
  getDocumentName = (capFirst: boolean = false) => (capFirst ? _.upperFirst(this.documentName) : this.documentName);
80
- getRecordId = (): string => this.data._id;
80
+ getRecordId = (): string => this.data?._id ?? '';
81
81
  setSchema = (newschema) => (this.jsonschema = newschema);
82
82
  getSchema = () => this.doc.schema.obj;
83
83
  getJsonSchema = () => this.jsonschema;
84
- getHooks = () => this.hooks;
84
+
85
85
  getData = () => {
86
86
  //console.log('thisdata', this.data);
87
87
  return this.data;
@@ -141,8 +141,8 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
141
141
  };
142
142
  async getAutoComplete(appuser: UserContext, keyword: string, data?: T) {
143
143
  try {
144
- const filter1 = {};
145
- const filter2 = {};
144
+ const filter1: any = {};
145
+ const filter2: any = {};
146
146
  const filters: any[] = [];
147
147
  if (this.jsonschema.properties[this.documentIdentityCode]['type'] == 'string') {
148
148
  filter1[this.documentIdentityCode] = { $regex: keyword, $options: 'i' };
@@ -161,6 +161,7 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
161
161
  if (this.moreAutoCompleteField) {
162
162
  Object.assign(projections, this.moreAutoCompleteField);
163
163
  }
164
+
164
165
  const products = await this.doc.find(filterobj, projections, {
165
166
  // limit: this.LIMITPERPAGE,
166
167
  });
@@ -181,12 +182,12 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
181
182
  */
182
183
  async searchNoIsolation(appuser: UserContext, filters: FilterQuery<T>) {
183
184
  try {
184
- if (this.hooks.beforeSearch) await this.hooks.beforeSearch(appuser, filters);
185
+ //if (this.hooks.beforeSearch) await this.hooks.beforeSearch(appuser, filters);
185
186
  const products = await this.doc.find(filters);
186
187
  const productlist = products.map((p) => {
187
188
  return p;
188
189
  });
189
- if (this.hooks.afterSearch) await this.hooks.afterSearch(appuser, productlist);
190
+ //if (this.hooks.afterSearch) await this.hooks.afterSearch(appuser, productlist);
190
191
 
191
192
  // console.log(products);
192
193
  return productlist;
@@ -218,9 +219,18 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
218
219
 
219
220
  Object.assign(pipeline[0]['$match'], isolationFilter);
220
221
  this.logger.verbose(pipeline, `${this.documentName} aggregate:`);
221
- return await this.doc.aggregate(pipeline, {
222
+
223
+ // if(appuser.getId() == ''){
224
+ // console.log(JSON.stringify(pipeline))
225
+ // }
226
+ const res = await this.doc.aggregate(pipeline, {
222
227
  session: appuser.getDBSession(),
223
228
  });
229
+
230
+ // if(appuser.getId() == ''){
231
+ // console.log(res)
232
+ // }
233
+ return res;
224
234
  } catch (err) {
225
235
  throw new InternalServerErrorException(err);
226
236
  }
@@ -236,7 +246,7 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
236
246
  // console.log("initial search",filters)
237
247
  const newfilters: FilterQuery<T> = { ...filters, ...isolationFilter };
238
248
 
239
- if (this.hooks.beforeSearch) await this.hooks.beforeSearch(appuser, newfilters);
249
+ // if (this.hooks.beforeSearch) await this.hooks.beforeSearch(appuser, newfilters);
240
250
  // console.log("before _find",newfilters)
241
251
  // console.log("this.doc",this.doc)
242
252
  let searchResults: T[] = [];
@@ -253,7 +263,7 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
253
263
  return p;
254
264
  });
255
265
  // console.log("after map",productlist)
256
- if (this.hooks.afterSearch) await this.hooks.afterSearch(appuser, list);
266
+ // if (this.hooks.afterSearch) await this.hooks.afterSearch(appuser, list);
257
267
 
258
268
  // console.log(products);
259
269
  return list;
@@ -309,10 +319,10 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
309
319
  }
310
320
  }
311
321
  async findById(appuser: UserContext, id: string) {
312
- if (this.hooks.beforeFetchRecord) await this.hooks.beforeFetchRecord(appuser, id);
322
+ // if (this.hooks.beforeFetchRecord) await this.hooks.beforeFetchRecord(appuser, id);
313
323
 
314
324
  const data = await this.search(appuser, { _id: id as any });
315
- if (this.hooks.afterFetchRecord) await this.hooks.afterFetchRecord(appuser, data[0]);
325
+ // if (this.hooks.afterFetchRecord) await this.hooks.afterFetchRecord(appuser, data[0]);
316
326
 
317
327
  if (data.length == 1) {
318
328
  // console.log('data0', data[0]);
@@ -323,10 +333,10 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
323
333
  }
324
334
 
325
335
  async findByIdNoIsolation(appuser: UserContext, id: string) {
326
- if (this.hooks.beforeFetchRecord) await this.hooks.beforeFetchRecord(appuser, id);
336
+ // if (this.hooks.beforeFetchRecord) await this.hooks.beforeFetchRecord(appuser, id);
327
337
 
328
338
  const data = await this.searchNoIsolation(appuser, { _id: id as any });
329
- if (this.hooks.afterFetchRecord) await this.hooks.afterFetchRecord(appuser, data[0]);
339
+ // if (this.hooks.afterFetchRecord) await this.hooks.afterFetchRecord(appuser, data[0]);
330
340
 
331
341
  if (data.length == 1) {
332
342
  // console.log('data0', data[0]);
@@ -337,9 +347,7 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
337
347
  }
338
348
 
339
349
  async createManyWithId(appuser: UserContext, datas: T[]) {
340
-
341
- if (Array.isArray(datas)) {
342
-
350
+ if (Array.isArray(datas)) {
343
351
  for (let i = 0; i < datas.length; i++) {
344
352
  const data = datas[i];
345
353
  let isolationFilter: any = { ...appuser.getCreateFilterWithId() };
@@ -357,7 +365,7 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
357
365
  }
358
366
 
359
367
  const result = await this.doc.insertMany(datas, { session: dbsession });
360
- await this.audittrail.addManyEvents(appuser, this.documentName, 'createMany', datas);
368
+ await this.addManyAuditEvents(appuser, this.documentName, 'createMany', datas);
361
369
  for (let i = 0; i < datas.length; i++) {
362
370
  appuser.addInsertedRecordId(this.documentName, datas[i]._id);
363
371
  }
@@ -394,16 +402,19 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
394
402
  this.reCalculateValue(data);
395
403
  await this.validateData(appuser, data);
396
404
  this.applyNestedDateTime(appuser, data, 'create');
397
- if (this.hooks.beforeCreate) await this.hooks.beforeCreate(appuser, data);
405
+
406
+ //new way of hook
407
+ await this.runEvent(appuser, this.setHookName('beforeCreate'), { data: data }, false);
408
+
398
409
  const newdoc = new this.doc(data);
399
410
 
400
411
  try {
401
412
  result = await newdoc.save({ session: dbsession });
402
- await this.audittrail.addEvent(appuser, this.documentName, result._id, 'create', data);
413
+ await this.addAuditEvent(appuser, this.documentName, result._id, 'create', data);
403
414
  appuser.addInsertedRecordId(this.documentName, result._id);
404
415
  } catch (err) {
405
416
  this.logger.error(err);
406
- const processdata = await this.runWorker(appuser, 'processdata.processError', {
417
+ const processdata = await this.runEvent(appuser, 'processdata.processError', {
407
418
  err: err,
408
419
  });
409
420
 
@@ -415,7 +426,8 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
415
426
  }
416
427
 
417
428
  try {
418
- if (this.hooks.afterCreate) await this.hooks.afterCreate(appuser, result);
429
+ //new way of hook
430
+ await this.runEvent(appuser, this.setHookName('afterCreate'), { data: data }, false);
419
431
  await this.callWebhook(appuser, 'create', result);
420
432
 
421
433
  // return result as T;
@@ -450,8 +462,8 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
450
462
  if (dbsession && !dbsession.inTransaction()) {
451
463
  dbsession.startTransaction({ readPreference: 'primary' });
452
464
  }
453
- const result = await this.doc.insertMany(datas,{session:dbsession});
454
- await this.audittrail.addManyEvents(appuser, this.documentName, 'createMany', datas);
465
+ const result = await this.doc.insertMany(datas, { session: dbsession });
466
+ await this.addManyAuditEvents(appuser, this.documentName, 'createMany', datas);
455
467
  return result;
456
468
  } else {
457
469
  throw new BadRequestException(this.getDocumentType() + ': create many only support array');
@@ -486,17 +498,20 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
486
498
  this.logger.debug(data, `after create validation`);
487
499
  this.applyNestedDateTime(appuser, data, 'create');
488
500
 
489
- if (this.hooks.beforeCreate) await this.hooks.beforeCreate(appuser, data);
501
+ //new way of hook
502
+
503
+ await this.runEvent(appuser, this.setHookName('beforeCreate'), { data: data }, false);
504
+
490
505
  this.logger.debug(data, `Create Record ${this.documentName}`);
491
506
  const newdoc = new this.doc(data);
492
507
  await this.identifyForeignKeys(appuser, data);
493
508
  try {
494
509
  result = await newdoc.save({ session: dbsession });
495
- await this.audittrail.addEvent(appuser, this.documentName, result._id, 'create', data);
510
+ await this.addAuditEvent(appuser, this.documentName, result._id, 'create', data);
496
511
  appuser.addInsertedRecordId(this.documentName, result._id);
497
512
  } catch (err) {
498
513
  this.logger.error(err);
499
- const processdata = await this.runWorker(appuser, 'processdata.processError', {
514
+ const processdata = await this.runEvent(appuser, 'processdata.processError', {
500
515
  err: err,
501
516
  });
502
517
 
@@ -508,7 +523,9 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
508
523
  }
509
524
 
510
525
  try {
511
- if (this.hooks.afterCreate) await this.hooks.afterCreate(appuser, result);
526
+ //new way of hook
527
+ await this.runEvent(appuser, this.setHookName('afterCreate'), { data: result }, false);
528
+
512
529
  await this.callWebhook(appuser, 'create', result);
513
530
  return result as T;
514
531
  } catch (err) {
@@ -545,17 +562,19 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
545
562
  this.logger.debug(data, `after create validation`);
546
563
  this.applyNestedDateTime(appuser, data, 'create');
547
564
 
548
- if (this.hooks.beforeCreate) await this.hooks.beforeCreate(appuser, data);
565
+ //new way of hook
566
+ await this.runEvent(appuser, this.setHookName('beforeCreate'), { data: data }, false);
567
+
549
568
  this.logger.debug(data, `Create Record ${this.documentName}`);
550
569
  const newdoc = new this.doc(data);
551
570
  await this.identifyForeignKeys(appuser, data);
552
571
  try {
553
572
  result = await newdoc.save({ session: dbsession });
554
- await this.audittrail.addEvent(appuser, this.documentName, result._id, 'create', data);
573
+ await this.addAuditEvent(appuser, this.documentName, result._id, 'create', data);
555
574
  appuser.addInsertedRecordId(this.documentName, result._id);
556
575
  } catch (err) {
557
576
  this.logger.error(err);
558
- const processdata = await this.runWorker(appuser, 'processdata.processError', {
577
+ const processdata = await this.runEvent(appuser, 'processdata.processError', {
559
578
  err: err,
560
579
  });
561
580
 
@@ -567,7 +586,9 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
567
586
  }
568
587
 
569
588
  try {
570
- if (this.hooks.afterCreate) await this.hooks.afterCreate(appuser, result);
589
+ //new way of hook
590
+ await this.runEvent(appuser, this.setHookName('afterCreate'), { data: result }, false);
591
+
571
592
  await this.callWebhook(appuser, 'create', result);
572
593
  return result as T;
573
594
  } catch (err) {
@@ -612,9 +633,9 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
612
633
  ajv.addKeyword({ keyword: 'x-simpleapp-config', schemaType: 'object' });
613
634
  this.logger.debug('run hook during validation');
614
635
  let issuccess = true;
615
- if (this.hooks.beforeValidation) {
616
- issuccess = await this.hooks.beforeValidation(appuser, data, _id);
617
- }
636
+ // if (this.hooks.beforeValidation) {
637
+ // issuccess = await this.hooks.beforeValidation(appuser, data, _id);
638
+ // }
618
639
  // const issuccess = await this.hook(appuser, HookType.beforeValidation, data);
619
640
  if (!issuccess) {
620
641
  const errormsg: string[] = [];
@@ -638,8 +659,6 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
638
659
  this.logger.error(JSON.stringify(validate.errors), 'validate errors:');
639
660
  throw new BadRequestException('Data validation failed', validate.errors as HttpExceptionOptions);
640
661
  }
641
- //no check for duplicate those
642
- if (this.hooks.afterValidation) await this.hooks.afterValidation(appuser, data, _id);
643
662
  }
644
663
 
645
664
  polishIsolationFilter = (filterIsolation: any, data: any = {}) => {
@@ -681,7 +700,10 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
681
700
 
682
701
  let dependency;
683
702
  try {
684
- if (this.hooks.beforeDelete) await this.hooks.beforeDelete(appuser, id, deletedata);
703
+ //new way of hook
704
+ await this.runEvent(appuser, this.setHookName('beforeDelete'), { id: id, deleteData: deletedata }, false);
705
+
706
+ // if (this.hooks.beforeDelete) await this.hooks.beforeDelete(appuser, id, deletedata);
685
707
  this.logger.debug('delete record', this.documentName, id);
686
708
  dependency = await this.getRelatedRecords(appuser, id);
687
709
  //console.log('dependency', dependency);
@@ -692,7 +714,8 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
692
714
  filterIsolation['_id'] = id;
693
715
  this.logger.debug('delete filter', filterIsolation);
694
716
  const result = await this.doc.deleteOne(filterIsolation).session(dbsession);
695
- await this.audittrail.addEvent(appuser, this.documentName, id, 'delete', deletedata);
717
+
718
+ await this.addAuditEvent(appuser, this.documentName, id, 'delete', deletedata);
696
719
 
697
720
  appuser.addDeletedRecordId(this.documentName, id);
698
721
  const deleteresult: DeleteResultType<T> = {
@@ -702,13 +725,14 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
702
725
  this.logger.debug(deleteresult, ' delete result' + this.doc.collection.name);
703
726
  // this.doc.findByIdAndDelete(id)
704
727
 
705
- if (this.hooks.afterDelete) await this.hooks.afterDelete(appuser, deleteresult, id);
706
- //this.doc.findByIdAndDelete(id);
728
+ //new way of hook
729
+ await this.runEvent(appuser, this.setHookName('afterDelete'), { id: id, deleteData: deletedata }, false);
730
+
707
731
  await this.callWebhook(appuser, 'delete', deletedata);
708
732
  return deleteresult;
709
733
  } else {
710
734
  this.logger.debug('reject query', dependency);
711
-
735
+ console.log(this.documentName, ' dependency :id=', id, dependency);
712
736
  throw new ForbiddenException(`This system detected that the [${this.documentName}] data has been used in other record`, 'Foreignkey constraint');
713
737
  }
714
738
  } catch (err) {
@@ -743,7 +767,10 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
743
767
 
744
768
  await this.identifyForeignKeys(appuser, data);
745
769
 
746
- if (this.hooks.beforeUpdate) await this.hooks.beforeUpdate(appuser, id, existingdata, data);
770
+ //new way of hook
771
+ await this.runEvent(appuser, `${this.documentName}.beforeUpdate`, { id: id, prevData: existingdata, newData: data }, false);
772
+
773
+ // if (this.hooks.beforeUpdate) await this.hooks.beforeUpdate(appuser, id, existingdata, data);
747
774
 
748
775
  const dbsession = appuser.getDBSession();
749
776
  if (dbsession && !dbsession.inTransaction() && !noStartTransaction) {
@@ -768,10 +795,11 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
768
795
  session: dbsession,
769
796
  new: true,
770
797
  });
771
- await this.audittrail.addEvent(appuser, this.documentName, id, 'update', data);
798
+ await this.addAuditEvent(appuser, this.documentName, id, 'update', data);
772
799
 
773
800
  appuser.addUpdatedRecordId(this.documentName, data._id);
774
- if (this.hooks.afterUpdate) await this.hooks.afterUpdate(appuser, id, existingdata, result);
801
+ await this.runEvent(appuser, this.setHookName('afterUpdate'), { id: id, prevData: existingdata, newData: data }, false);
802
+
775
803
  await this.callWebhook(appuser, 'update', result);
776
804
  return result; // await this.findById(appuser, id);
777
805
  } catch (err) {
@@ -799,7 +827,9 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
799
827
 
800
828
  await this.identifyForeignKeys(appuser, data);
801
829
 
802
- if (this.hooks.beforeUpdate) await this.hooks.beforeUpdate(appuser, id, existingdata, data);
830
+ await this.runEvent(appuser, `${this.documentName}.beforeUpdate`, { data: data }, false);
831
+
832
+ // if (this.hooks.beforeUpdate) await this.hooks.beforeUpdate(appuser, id, existingdata, data);
803
833
 
804
834
  const dbsession = appuser.getDBSession();
805
835
  if (dbsession && !dbsession.inTransaction()) {
@@ -824,10 +854,11 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
824
854
  session: dbsession,
825
855
  new: true,
826
856
  });
827
- await this.audittrail.addEvent(appuser, this.documentName, id, 'update', data);
857
+ await this.addAuditEvent(appuser, this.documentName, id, 'update', data);
828
858
 
859
+ await this.runEvent(appuser, this.setHookName('afterUpdate'), { id: id, prevData: existingdata, newData: result }, false);
829
860
  appuser.addUpdatedRecordId(this.documentName, data._id);
830
- if (this.hooks.afterUpdate) await this.hooks.afterUpdate(appuser, id, existingdata, result);
861
+
831
862
  await this.callWebhook(appuser, 'update', result);
832
863
  return result; // await this.findById(appuser, id);
833
864
  } catch (err) {
@@ -837,64 +868,91 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
837
868
  };
838
869
 
839
870
  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
- }
871
+ try {
872
+ const existingdata = await this.findById(appuser, id);
873
+ if (!existingdata) {
874
+ throw new NotFoundException(`${id} not found`, 'not found');
875
+ }
876
+ if (typeof data.__v == 'number' && data.__v != existingdata.__v) {
877
+ throw new BadRequestException(`You submit older version data "v${data.__v}"" but latest version = "v${existingdata.__v}"`);
878
+ }
847
879
 
848
- data.__v = existingdata.__v + 1;
880
+ if (typeof existingdata.__v !== 'number') {
881
+ existingdata.__v = 0;
882
+ }
883
+ data.__v = existingdata.__v + 1;
849
884
 
850
- await this.identifyForeignKeys(appuser, data);
885
+ await this.identifyForeignKeys(appuser, data);
851
886
 
852
- //patch not suitable trigger afterupdate
853
- // if (this.hooks.beforeUpdate) await this.hooks.beforeUpdate(appuser, id, existingdata, data);
887
+ //patch not suitable trigger afterupdate
888
+ // if (this.hooks.beforeUpdate) await this.hooks.beforeUpdate(appuser, id, existingdata, data);
854
889
 
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'];
890
+ const dbsession = appuser.getDBSession();
891
+ if (dbsession && !dbsession.inTransaction()) {
892
+ dbsession.startTransaction({ readPreference: 'primary' });
893
+ }
894
+ // try {
895
+ Object.assign(data, appuser.getUpdateFilter());
896
+ delete data['_id'];
863
897
 
864
- //patch not suitable trigger afterupdate
865
- // this.reCalculateValue(data);
898
+ //patch not suitable trigger afterupdate
899
+ // this.reCalculateValue(data);
866
900
 
867
- // existingdata['_id']=''
868
- // console.log("newdata",data)
869
- //path record no validation
870
- // await this.validateData(appuser, data);
901
+ // existingdata['_id']=''
902
+ // console.log("newdata",data)
903
+ //path record no validation
904
+ // await this.validateData(appuser, data);
871
905
 
872
- const isolationFilter = { ...this.getIsolationFilter(appuser) };
873
- this.polishIsolationFilter(isolationFilter);
906
+ const isolationFilter = { ...this.getIsolationFilter(appuser) };
907
+ this.polishIsolationFilter(isolationFilter);
874
908
 
875
- isolationFilter['_id'] = id;
876
- this.applyNestedDateTime(appuser, data, 'update');
909
+ isolationFilter['_id'] = id;
910
+ this.applyNestedDateTime(appuser, data, 'update');
911
+ // console.log('findid patch ', data);
877
912
 
878
- try {
879
913
  const result = await this.doc.findOneAndUpdate(isolationFilter, data, {
880
914
  session: dbsession,
881
915
  new: true,
882
916
  });
883
917
  //skip audit trail, useful when want to patch x-foreignkey code,label
884
918
  if (!skipLog) {
885
- await this.audittrail.addEvent(appuser, this.documentName, id, 'patch', data);
919
+ await this.addAuditEvent(appuser, this.documentName, id, 'patch', data);
886
920
  }
887
921
  appuser.addUpdatedRecordId(this.documentName, data._id);
888
922
 
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
923
  return result; //await this.findById(appuser, id);
893
924
  } catch (err) {
925
+ this.logger.error(err.message, 'findIdThenPath error');
926
+ console.error(err);
894
927
  throw new InternalServerErrorException(err.message);
895
928
  }
896
929
  };
897
930
 
931
+ async patchMany<T>(appuser: UserContext, data: PatchManyRequest<T>) {
932
+ // filter = {
933
+ // _id: '7eb2661a-6ea6-406e-b868-2e8b19c4658b',
934
+ // 'tuitionClass._id': '5aa69cee-f651-45f4-bad8-0f52a3fb92b5',
935
+ // };
936
+
937
+ const filter = data.filter;
938
+ const patch = data.data as Object;
939
+
940
+ const isolationFilter = { ...this.getIsolationFilter(appuser), ...(filter || {}) };
941
+ this.polishIsolationFilter(isolationFilter);
942
+ this.applyNestedDateTime(appuser, patch, 'update');
943
+
944
+ // Get DB Session
945
+ const dbsession = appuser.getDBSession();
946
+ if (dbsession && !dbsession.inTransaction()) {
947
+ dbsession.startTransaction({ readPreference: 'primary' });
948
+ }
949
+
950
+ const result = await this.doc.updateMany(isolationFilter, { $set: patch }, { session: dbsession });
951
+ await this.addManyAuditEvents(appuser, this.documentName, 'patchMany', [patch]);
952
+
953
+ return result;
954
+ }
955
+
898
956
  //find what foreign key constraint
899
957
  async getRelatedRecords(appuser: UserContext, id: string) {
900
958
  this.logger.debug('get foreignkey for delete:', id);
@@ -965,19 +1023,22 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
965
1023
  }
966
1024
  data['documentStatus'] = docstatus;
967
1025
  // await this.hook(appuser, HookType.beforeSetStatus, data);
968
- if (this.hooks.beforeSetStatus) await this.hooks.beforeSetStatus(appuser, docstatus, data, existdata);
1026
+ await this.runEvent(appuser, this.setHookName('beforeSetStatus'), { docStatus: docstatus, prevData: existdata, newData: data }, false);
1027
+
1028
+ // if (this.hooks.beforeSetStatus) await this.hooks.beforeSetStatus(appuser, docstatus, data, existdata);
969
1029
 
970
1030
  if (data && !data['created']) {
971
1031
  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);
1032
+ await this.runEvent(appuser, this.setHookName('afterSetStatus'), { docStatus: docstatus, data: createresult }, false);
1033
+ // if (this.hooks.afterSetStatus) await this.hooks.afterSetStatus(appuser, docstatus, createresult);
1034
+ await this.addAuditEvent(appuser, this.documentName, id, docstatus, data);
974
1035
 
975
1036
  return createresult;
976
1037
  } else {
977
1038
  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);
1039
+ const finaldata = await this.findById(appuser, id);
1040
+ await this.runEvent(appuser, this.setHookName('afterSetStatus'), { docStatus: docstatus, data: finaldata }, false);
1041
+ await this.addAuditEvent(appuser, this.documentName, id, docstatus, data);
981
1042
 
982
1043
  await this.callWebhook(appuser, docstatus, finaldata);
983
1044
  return updateresult;
@@ -985,7 +1046,7 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
985
1046
  }
986
1047
 
987
1048
  /**
988
- * similar like runWorker, but it is syncronizely add event into queue and return.
1049
+ * similar like runEvent, but it is syncronizely add event into queue and return.
989
1050
  * No result will return from this method, it also lose appuser db's transaction
990
1051
  * due out of request flow
991
1052
  *
@@ -998,7 +1059,7 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
998
1059
  }
999
1060
 
1000
1061
  /**
1001
- * runWorker design with 2 purpose
1062
+ * runEvent design with 2 purpose
1002
1063
  * 1. we wish developer develop complex programming flow in worker class instead
1003
1064
  * of service class. We wish service class remain simple and easy to understand
1004
1065
  * it wish to do hook and api only
@@ -1013,28 +1074,40 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
1013
1074
  * @param {any} data The data
1014
1075
  * @return {Promise} { description_of_the_return_value }
1015
1076
  */
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
- }
1077
+ async runEvent(appuser: UserContext, eventName: string, payloads: any, enforce: boolean = true) {
1078
+ try {
1024
1079
 
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);
1080
+ if (enforce && !this.eventEmitter.hasListeners(eventName)) {
1081
+ throw new InternalServerErrorException(`${eventName} seems no listener`);
1082
+ } else if (this.eventEmitter.hasListeners(eventName)) {
1083
+ const res = await this.eventEmitter.emitAsync(eventName, appuser, payloads);
1084
+
1085
+ if (!res) {
1086
+ throw new InternalServerErrorException(`${eventName} is invalid worker`);
1087
+ }
1088
+
1089
+ const result = res[0];
1090
+ if (result?.name && result?.name.includes('Exception')) throw result;
1091
+ return result;
1092
+ }
1093
+ } catch (e) {
1094
+ console.error(e);
1095
+ throw e;
1096
+ }
1031
1097
  }
1098
+ // startWorkflow(appuser: UserContext, processName: WorkflowName, workflowData: any) {
1099
+ // return this.eventEmitter.emit('workflow.start', appuser, processName, workflowData);
1100
+ // }
1032
1101
 
1033
1102
  async genNewDocNo(appuser: UserContext, data: T) {
1034
1103
  this.logger.debug('genNewDocNo');
1104
+ // console.log('before genNewDocNo');
1035
1105
  const result = await this.docnogenerator.generateNextNumberFromDocument(appuser, this.documentType, data);
1106
+ // console.log('after genNewDocNo');
1036
1107
  this.logger.debug(result, 'genNewDocNo');
1037
- data[this.documentIdentityCode] = result;
1108
+
1109
+ // been for to convert become object
1110
+ (data as any)[this.documentIdentityCode] = result;
1038
1111
  }
1039
1112
  async runDefault(appuser: UserContext): Promise<unknown> {
1040
1113
  return 'Hello this is ' + this.getDocumentType() + ': ' + this.getDocumentName();
@@ -1125,13 +1198,15 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
1125
1198
  }
1126
1199
  }
1127
1200
 
1128
- async print(appuser: UserContext, id: string, formatid: string) {
1129
- const pdfresult = await this.printapi.getBase64Pdf(appuser, formatid, id);
1130
- return pdfresult;
1201
+ async print(appuser: UserContext, id: string, formatId: string) {
1202
+ // const pdfresult = await this.printapi.getBase64Pdf(appuser, formatid, id);
1203
+ const pdfresult = await this.runEvent(appuser, 'print.getbase64pdf', { id: id, formatId: formatId }, true);
1204
+ // return pdfresult;
1205
+ return Promise.resolve('ok');
1131
1206
  }
1132
1207
 
1133
- async checkMultipleUnionExist(appuser: UserContext, data: string[]): Promise<CheckMutipleUnionExistResponse> {
1134
- const response: CheckMutipleUnionExistResponse = [];
1208
+ async checkUniqueKeyExist(appuser: UserContext, data: string[]): Promise<UniqueKeyExistResponse[]> {
1209
+ const response: UniqueKeyExistResponse[] = [];
1135
1210
  const unionKey = this.getDocumentIdentityCode();
1136
1211
  const searchQuery: any = { [unionKey]: { $in: data } };
1137
1212
  // search for multiple union exist
@@ -1192,12 +1267,37 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
1192
1267
  return pipelines;
1193
1268
  }
1194
1269
 
1270
+ setHookName(hookName) {
1271
+ const resourceName = this.jsonschema['x-simpleapp-config']['resourceName'];
1272
+ return camelToKebab(resourceName) + '.' + camelToKebab(hookName);
1273
+ }
1195
1274
  //only realtime webhook supported at this moment
1196
1275
  async callWebhook(appuser: UserContext, actionName: string, data: any) {
1197
1276
  try {
1198
- await this.runWebHook.run(appuser, this.documentName, actionName, data);
1277
+ // await this.runWebHook.run(appuser, this.documentName, actionName, data);
1278
+ // await this.runEvent(appuser, 'webhook.run', {
1279
+ // documentName: this.documentName,
1280
+ // actionName: actionName,
1281
+ // data: data,
1282
+ // });
1199
1283
  } catch (e) {
1200
1284
  throw new InternalServerErrorException(e);
1201
1285
  }
1202
1286
  }
1287
+
1288
+ async addAuditEvent(appuser: UserContext, documentName: string, id: string, eventType: string, data: any) {
1289
+ // await this.runEvent(appuser, 'audittrail.add', {
1290
+ // documentName: documentName,
1291
+ // id: id,
1292
+ // eventType: eventType,
1293
+ // data: data,
1294
+ // });
1295
+ }
1296
+ async addManyAuditEvents(appuser: UserContext, documentName: string, eventType: string, datas: any) {
1297
+ // await this.runEvent(appuser, 'audittrail.add', {
1298
+ // documentName: documentName,
1299
+ // eventType: eventType,
1300
+ // datas: datas,
1301
+ // });
1302
+ }
1203
1303
  }