@rytass/bpm-core-nestjs-module 0.1.3 → 0.1.5

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 (612) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/LICENSE +21 -0
  3. package/README.md +143 -0
  4. package/package.json +3 -3
  5. package/src/index.js +18 -0
  6. package/src/index.js.map +1 -0
  7. package/src/lib/attachment/attachment-options.d.ts +44 -0
  8. package/src/lib/attachment/attachment-options.js +62 -0
  9. package/src/lib/attachment/attachment-options.js.map +1 -0
  10. package/src/lib/attachment/attachment-storage.provider.d.ts +4 -0
  11. package/src/lib/attachment/attachment-storage.provider.js +35 -0
  12. package/src/lib/attachment/attachment-storage.provider.js.map +1 -0
  13. package/src/lib/attachment/{attachment-storage.token.ts → attachment-storage.token.d.ts} +1 -3
  14. package/src/lib/attachment/attachment-storage.token.js +5 -0
  15. package/src/lib/attachment/attachment-storage.token.js.map +1 -0
  16. package/src/lib/attachment/attachment.controller.d.ts +8 -0
  17. package/src/lib/attachment/attachment.controller.js +38 -0
  18. package/src/lib/attachment/attachment.controller.js.map +1 -0
  19. package/src/lib/attachment/attachment.entity.d.ts +14 -0
  20. package/src/lib/attachment/attachment.entity.js +74 -0
  21. package/src/lib/attachment/attachment.entity.js.map +1 -0
  22. package/src/lib/attachment/attachment.module.d.ts +27 -0
  23. package/src/lib/attachment/attachment.module.js +103 -0
  24. package/src/lib/attachment/attachment.module.js.map +1 -0
  25. package/src/lib/attachment/attachment.mutations.d.ts +8 -0
  26. package/src/lib/attachment/attachment.mutations.js +35 -0
  27. package/src/lib/attachment/attachment.mutations.js.map +1 -0
  28. package/src/lib/attachment/attachment.queries.d.ts +9 -0
  29. package/src/lib/attachment/attachment.queries.js +78 -0
  30. package/src/lib/attachment/attachment.queries.js.map +1 -0
  31. package/src/lib/attachment/attachment.service.d.ts +49 -0
  32. package/src/lib/attachment/attachment.service.js +276 -0
  33. package/src/lib/attachment/attachment.service.js.map +1 -0
  34. package/src/lib/attachment/dto/upload-attachment.input.d.ts +11 -0
  35. package/src/lib/attachment/dto/upload-attachment.input.js +68 -0
  36. package/src/lib/attachment/dto/upload-attachment.input.js.map +1 -0
  37. package/src/lib/attachment/index.js +9 -0
  38. package/src/lib/attachment/index.js.map +1 -0
  39. package/src/lib/bpm/bpm-root.module.d.ts +155 -0
  40. package/src/lib/bpm/bpm-root.module.js +170 -0
  41. package/src/lib/bpm/bpm-root.module.js.map +1 -0
  42. package/src/lib/bpm/index.js +5 -0
  43. package/src/lib/bpm/index.js.map +1 -0
  44. package/src/lib/bpm-auth/bpm-auth-context.d.ts +24 -0
  45. package/src/lib/bpm-auth/bpm-auth-context.extractor.d.ts +4 -0
  46. package/src/lib/bpm-auth/bpm-auth-context.extractor.js +69 -0
  47. package/src/lib/bpm-auth/bpm-auth-context.extractor.js.map +1 -0
  48. package/src/lib/bpm-auth/bpm-auth-context.js +15 -0
  49. package/src/lib/bpm-auth/bpm-auth-context.js.map +1 -0
  50. package/src/lib/bpm-auth/bpm-auth.authorization.d.ts +12 -0
  51. package/src/lib/bpm-auth/bpm-auth.authorization.js +67 -0
  52. package/src/lib/bpm-auth/bpm-auth.authorization.js.map +1 -0
  53. package/src/lib/bpm-auth/bpm-auth.decorators.d.ts +3 -0
  54. package/src/lib/bpm-auth/bpm-auth.decorators.js +11 -0
  55. package/src/lib/bpm-auth/bpm-auth.decorators.js.map +1 -0
  56. package/src/lib/bpm-auth/bpm-auth.guard.d.ts +7 -0
  57. package/src/lib/bpm-auth/bpm-auth.guard.js +24 -0
  58. package/src/lib/bpm-auth/bpm-auth.guard.js.map +1 -0
  59. package/src/lib/bpm-auth/bpm-auth.module.d.ts +6 -0
  60. package/src/lib/bpm-auth/bpm-auth.module.js +69 -0
  61. package/src/lib/bpm-auth/bpm-auth.module.js.map +1 -0
  62. package/src/lib/bpm-auth/bpm-auth.options.d.ts +11 -0
  63. package/src/lib/bpm-auth/bpm-auth.options.js +3 -0
  64. package/src/lib/bpm-auth/bpm-auth.options.js.map +1 -0
  65. package/src/lib/bpm-auth/configurable-bpm-auth-context.accessor.d.ts +10 -0
  66. package/src/lib/bpm-auth/configurable-bpm-auth-context.accessor.js +40 -0
  67. package/src/lib/bpm-auth/configurable-bpm-auth-context.accessor.js.map +1 -0
  68. package/src/lib/bpm-auth/index.js +10 -0
  69. package/src/lib/bpm-auth/index.js.map +1 -0
  70. package/src/lib/common/filters/all-exceptions.filter.d.ts +25 -0
  71. package/src/lib/common/filters/all-exceptions.filter.js +93 -0
  72. package/src/lib/common/filters/all-exceptions.filter.js.map +1 -0
  73. package/src/lib/common/index.js +5 -0
  74. package/src/lib/common/index.js.map +1 -0
  75. package/src/lib/common/iso-duration.d.ts +1 -0
  76. package/src/lib/common/iso-duration.js +27 -0
  77. package/src/lib/common/iso-duration.js.map +1 -0
  78. package/src/lib/condition/condition.module.d.ts +2 -0
  79. package/src/lib/condition/condition.module.js +16 -0
  80. package/src/lib/condition/condition.module.js.map +1 -0
  81. package/src/lib/condition/condition.service.d.ts +16 -0
  82. package/src/lib/condition/condition.service.js +82 -0
  83. package/src/lib/condition/condition.service.js.map +1 -0
  84. package/src/lib/condition/index.js +6 -0
  85. package/src/lib/condition/index.js.map +1 -0
  86. package/src/lib/database/data-source.d.ts +4 -0
  87. package/src/lib/database/data-source.js +7 -0
  88. package/src/lib/database/data-source.js.map +1 -0
  89. package/src/lib/database/index.js +6 -0
  90. package/src/lib/database/index.js.map +1 -0
  91. package/src/lib/database/migration-runner.d.ts +1 -0
  92. package/src/lib/database/migration-runner.js +23 -0
  93. package/src/lib/database/migration-runner.js.map +1 -0
  94. package/src/lib/database/typeorm.config.d.ts +14 -0
  95. package/src/lib/database/typeorm.config.js +135 -0
  96. package/src/lib/database/typeorm.config.js.map +1 -0
  97. package/src/lib/delegation/delegation-rule.entity.d.ts +19 -0
  98. package/src/lib/delegation/delegation-rule.entity.js +99 -0
  99. package/src/lib/delegation/delegation-rule.entity.js.map +1 -0
  100. package/src/lib/delegation/delegation.enums.d.ts +10 -0
  101. package/src/lib/delegation/delegation.enums.js +23 -0
  102. package/src/lib/delegation/delegation.enums.js.map +1 -0
  103. package/src/lib/delegation/delegation.module.d.ts +2 -0
  104. package/src/lib/delegation/delegation.module.js +22 -0
  105. package/src/lib/delegation/delegation.module.js.map +1 -0
  106. package/src/lib/delegation/delegation.mutations.d.ts +11 -0
  107. package/src/lib/delegation/delegation.mutations.js +87 -0
  108. package/src/lib/delegation/delegation.mutations.js.map +1 -0
  109. package/src/lib/delegation/delegation.queries.d.ts +10 -0
  110. package/src/lib/delegation/delegation.queries.js +91 -0
  111. package/src/lib/delegation/delegation.queries.js.map +1 -0
  112. package/src/lib/delegation/delegation.service.d.ts +56 -0
  113. package/src/lib/delegation/delegation.service.js +268 -0
  114. package/src/lib/delegation/delegation.service.js.map +1 -0
  115. package/src/lib/delegation/dto/delegation-rule.input.d.ts +24 -0
  116. package/src/lib/delegation/dto/delegation-rule.input.js +143 -0
  117. package/src/lib/delegation/dto/delegation-rule.input.js.map +1 -0
  118. package/src/lib/delegation/index.js +9 -0
  119. package/src/lib/delegation/index.js.map +1 -0
  120. package/src/lib/form/dto/form-definition.input.d.ts +21 -0
  121. package/src/lib/form/dto/form-definition.input.js +103 -0
  122. package/src/lib/form/dto/form-definition.input.js.map +1 -0
  123. package/src/lib/form/form-definition-version.entity.d.ts +17 -0
  124. package/src/lib/form/form-definition-version.entity.js +84 -0
  125. package/src/lib/form/form-definition-version.entity.js.map +1 -0
  126. package/src/lib/form/form-definition.entity.d.ts +13 -0
  127. package/src/lib/form/form-definition.entity.js +66 -0
  128. package/src/lib/form/form-definition.entity.js.map +1 -0
  129. package/src/lib/form/form-schema-lint.object.d.ts +4 -0
  130. package/src/lib/form/form-schema-lint.object.js +20 -0
  131. package/src/lib/form/form-schema-lint.object.js.map +1 -0
  132. package/src/lib/form/form-schema.validator.d.ts +13 -0
  133. package/src/lib/form/form-schema.validator.js +354 -0
  134. package/src/lib/form/form-schema.validator.js.map +1 -0
  135. package/src/lib/form/form.enums.d.ts +9 -0
  136. package/src/lib/form/form.enums.js +22 -0
  137. package/src/lib/form/form.enums.js.map +1 -0
  138. package/src/lib/form/form.module.d.ts +2 -0
  139. package/src/lib/form/form.module.js +27 -0
  140. package/src/lib/form/form.module.js.map +1 -0
  141. package/src/lib/form/form.mutations.d.ts +14 -0
  142. package/src/lib/form/form.mutations.js +88 -0
  143. package/src/lib/form/form.mutations.js.map +1 -0
  144. package/src/lib/form/form.queries.d.ts +16 -0
  145. package/src/lib/form/form.queries.js +96 -0
  146. package/src/lib/form/form.queries.js.map +1 -0
  147. package/src/lib/form/form.service.d.ts +35 -0
  148. package/src/lib/form/form.service.js +297 -0
  149. package/src/lib/form/form.service.js.map +1 -0
  150. package/src/lib/form/index.js +12 -0
  151. package/src/lib/form/index.js.map +1 -0
  152. package/src/lib/identity/identity-options.d.ts +13 -0
  153. package/src/lib/identity/identity-options.js +20 -0
  154. package/src/lib/identity/identity-options.js.map +1 -0
  155. package/src/lib/identity/identity.module.d.ts +17 -0
  156. package/src/lib/identity/identity.module.js +65 -0
  157. package/src/lib/identity/identity.module.js.map +1 -0
  158. package/src/lib/identity/identity.queries.d.ts +12 -0
  159. package/src/lib/identity/identity.queries.js +79 -0
  160. package/src/lib/identity/identity.queries.js.map +1 -0
  161. package/src/lib/identity/identity.service.d.ts +22 -0
  162. package/src/lib/identity/identity.service.js +141 -0
  163. package/src/lib/identity/identity.service.js.map +1 -0
  164. package/src/lib/identity/index.js +7 -0
  165. package/src/lib/identity/index.js.map +1 -0
  166. package/src/lib/identity/member-base.adapter.d.ts +95 -0
  167. package/src/lib/identity/member-base.adapter.js +137 -0
  168. package/src/lib/identity/member-base.adapter.js.map +1 -0
  169. package/src/lib/identity/member-metadata-cache.entity.d.ts +8 -0
  170. package/src/lib/identity/member-metadata-cache.entity.js +39 -0
  171. package/src/lib/identity/member-metadata-cache.entity.js.map +1 -0
  172. package/src/lib/identity/member-profile.object.d.ts +8 -0
  173. package/src/lib/identity/member-profile.object.js +37 -0
  174. package/src/lib/identity/member-profile.object.js.map +1 -0
  175. package/src/lib/identity/member-resolver.interface.d.ts +79 -0
  176. package/src/lib/identity/member-resolver.interface.js +19 -0
  177. package/src/lib/identity/member-resolver.interface.js.map +1 -0
  178. package/src/lib/migrations/0000000000001-enable-postgres-extensions.d.ts +6 -0
  179. package/src/lib/migrations/0000000000001-enable-postgres-extensions.js +17 -0
  180. package/src/lib/migrations/0000000000001-enable-postgres-extensions.js.map +1 -0
  181. package/src/lib/migrations/0000000001000-identity-organization-foundation.d.ts +6 -0
  182. package/src/lib/migrations/{0000000001000-identity-organization-foundation.ts → 0000000001000-identity-organization-foundation.js} +29 -38
  183. package/src/lib/migrations/0000000001000-identity-organization-foundation.js.map +1 -0
  184. package/src/lib/migrations/0000000002000-form-builder-foundation.d.ts +6 -0
  185. package/src/lib/migrations/{0000000002000-form-builder-foundation.ts → 0000000002000-form-builder-foundation.js} +21 -22
  186. package/src/lib/migrations/0000000002000-form-builder-foundation.js.map +1 -0
  187. package/src/lib/migrations/0000000003000-approval-template-foundation.d.ts +6 -0
  188. package/src/lib/migrations/{0000000003000-approval-template-foundation.ts → 0000000003000-approval-template-foundation.js} +21 -24
  189. package/src/lib/migrations/0000000003000-approval-template-foundation.js.map +1 -0
  190. package/src/lib/migrations/0000000004000-workflow-engine-foundation.d.ts +6 -0
  191. package/src/lib/migrations/{0000000004000-workflow-engine-foundation.ts → 0000000004000-workflow-engine-foundation.js} +34 -46
  192. package/src/lib/migrations/0000000004000-workflow-engine-foundation.js.map +1 -0
  193. package/src/lib/migrations/0000000005000-delegation-rules.d.ts +6 -0
  194. package/src/lib/migrations/{0000000005000-delegation-rules.ts → 0000000005000-delegation-rules.js} +19 -20
  195. package/src/lib/migrations/0000000005000-delegation-rules.js.map +1 -0
  196. package/src/lib/migrations/0000000006000-notifications-sla.d.ts +6 -0
  197. package/src/lib/migrations/{0000000006000-notifications-sla.ts → 0000000006000-notifications-sla.js} +23 -26
  198. package/src/lib/migrations/0000000006000-notifications-sla.js.map +1 -0
  199. package/src/lib/migrations/0000000007000-signatures-attachments.d.ts +6 -0
  200. package/src/lib/migrations/{0000000007000-signatures-attachments.ts → 0000000007000-signatures-attachments.js} +27 -28
  201. package/src/lib/migrations/0000000007000-signatures-attachments.js.map +1 -0
  202. package/src/lib/migrations/0000000008000-approval-template-categories.d.ts +6 -0
  203. package/src/lib/migrations/{0000000008000-approval-template-categories.ts → 0000000008000-approval-template-categories.js} +25 -28
  204. package/src/lib/migrations/0000000008000-approval-template-categories.js.map +1 -0
  205. package/src/lib/migrations/0000000009000-task-candidates.d.ts +6 -0
  206. package/src/lib/migrations/{0000000009000-task-candidates.ts → 0000000009000-task-candidates.js} +23 -26
  207. package/src/lib/migrations/0000000009000-task-candidates.js.map +1 -0
  208. package/src/lib/migrations/0000000010000-notification-delivery-state.d.ts +6 -0
  209. package/src/lib/migrations/{0000000010000-notification-delivery-state.ts → 0000000010000-notification-delivery-state.js} +17 -16
  210. package/src/lib/migrations/0000000010000-notification-delivery-state.js.map +1 -0
  211. package/src/lib/migrations/0000000011000-remove-attachment-encryption-key.d.ts +6 -0
  212. package/src/lib/migrations/0000000011000-remove-attachment-encryption-key.js +22 -0
  213. package/src/lib/migrations/0000000011000-remove-attachment-encryption-key.js.map +1 -0
  214. package/src/lib/migrations/0000000012000-notification-sla-idempotency.d.ts +6 -0
  215. package/src/lib/migrations/0000000012000-notification-sla-idempotency.js +21 -0
  216. package/src/lib/migrations/0000000012000-notification-sla-idempotency.js.map +1 -0
  217. package/src/lib/migrations/0000000013000-workflow-query-indexes.d.ts +6 -0
  218. package/src/lib/migrations/0000000013000-workflow-query-indexes.js +80 -0
  219. package/src/lib/migrations/0000000013000-workflow-query-indexes.js.map +1 -0
  220. package/src/lib/migrations/index.d.ts +16 -0
  221. package/src/lib/migrations/index.js +49 -0
  222. package/src/lib/migrations/index.js.map +1 -0
  223. package/src/lib/notification/dto/notification-preference.input.d.ts +9 -0
  224. package/src/lib/notification/dto/notification-preference.input.js +53 -0
  225. package/src/lib/notification/dto/notification-preference.input.js.map +1 -0
  226. package/src/lib/notification/index.js +11 -0
  227. package/src/lib/notification/index.js.map +1 -0
  228. package/src/lib/notification/notification-delivery-scheduler.service.d.ts +13 -0
  229. package/src/lib/notification/notification-delivery-scheduler.service.js +53 -0
  230. package/src/lib/notification/notification-delivery-scheduler.service.js.map +1 -0
  231. package/src/lib/notification/notification-delivery.service.d.ts +23 -0
  232. package/src/lib/notification/notification-delivery.service.js +245 -0
  233. package/src/lib/notification/notification-delivery.service.js.map +1 -0
  234. package/src/lib/notification/notification-dispatcher.token.d.ts +7 -0
  235. package/src/lib/notification/notification-dispatcher.token.js +5 -0
  236. package/src/lib/notification/notification-dispatcher.token.js.map +1 -0
  237. package/src/lib/notification/notification-options.d.ts +215 -0
  238. package/src/lib/notification/notification-options.js +128 -0
  239. package/src/lib/notification/notification-options.js.map +1 -0
  240. package/src/lib/notification/notification-options.module.d.ts +23 -0
  241. package/src/lib/notification/notification-options.module.js +41 -0
  242. package/src/lib/notification/notification-options.module.js.map +1 -0
  243. package/src/lib/notification/notification-preference.entity.d.ts +10 -0
  244. package/src/lib/notification/notification-preference.entity.js +50 -0
  245. package/src/lib/notification/notification-preference.entity.js.map +1 -0
  246. package/src/lib/notification/notification-sla-scheduler.service.d.ts +13 -0
  247. package/src/lib/notification/notification-sla-scheduler.service.js +51 -0
  248. package/src/lib/notification/notification-sla-scheduler.service.js.map +1 -0
  249. package/src/lib/notification/notification-template.d.ts +13 -0
  250. package/src/lib/notification/notification-template.js +61 -0
  251. package/src/lib/notification/notification-template.js.map +1 -0
  252. package/src/lib/notification/notification.entity.d.ts +23 -0
  253. package/src/lib/notification/notification.entity.js +122 -0
  254. package/src/lib/notification/notification.entity.js.map +1 -0
  255. package/src/lib/notification/notification.enums.d.ts +24 -0
  256. package/src/lib/notification/notification.enums.js +45 -0
  257. package/src/lib/notification/notification.enums.js.map +1 -0
  258. package/src/lib/notification/notification.module.d.ts +2 -0
  259. package/src/lib/notification/notification.module.js +45 -0
  260. package/src/lib/notification/notification.module.js.map +1 -0
  261. package/src/lib/notification/notification.mutations.d.ts +11 -0
  262. package/src/lib/notification/notification.mutations.js +64 -0
  263. package/src/lib/notification/notification.mutations.js.map +1 -0
  264. package/src/lib/notification/notification.queries.d.ts +11 -0
  265. package/src/lib/notification/notification.queries.js +77 -0
  266. package/src/lib/notification/notification.queries.js.map +1 -0
  267. package/src/lib/notification/notification.service.d.ts +81 -0
  268. package/src/lib/notification/notification.service.js +621 -0
  269. package/src/lib/notification/notification.service.js.map +1 -0
  270. package/src/lib/organization/dto/manager-resolution.input.d.ts +18 -0
  271. package/src/lib/organization/dto/manager-resolution.input.js +107 -0
  272. package/src/lib/organization/dto/manager-resolution.input.js.map +1 -0
  273. package/src/lib/organization/dto/membership.input.d.ts +16 -0
  274. package/src/lib/organization/dto/membership.input.js +99 -0
  275. package/src/lib/organization/dto/membership.input.js.map +1 -0
  276. package/src/lib/organization/dto/org-unit.input.d.ts +24 -0
  277. package/src/lib/organization/dto/org-unit.input.js +119 -0
  278. package/src/lib/organization/dto/org-unit.input.js.map +1 -0
  279. package/src/lib/organization/dto/position.input.d.ts +13 -0
  280. package/src/lib/organization/dto/position.input.js +70 -0
  281. package/src/lib/organization/dto/position.input.js.map +1 -0
  282. package/src/lib/organization/index.js +16 -0
  283. package/src/lib/organization/index.js.map +1 -0
  284. package/src/lib/organization/json-metadata.d.ts +1 -0
  285. package/src/lib/organization/json-metadata.js +14 -0
  286. package/src/lib/organization/json-metadata.js.map +1 -0
  287. package/src/lib/organization/manager-resolution.entity.d.ts +11 -0
  288. package/src/lib/organization/manager-resolution.entity.js +55 -0
  289. package/src/lib/organization/manager-resolution.entity.js.map +1 -0
  290. package/src/lib/organization/membership.entity.d.ts +11 -0
  291. package/src/lib/organization/membership.entity.js +60 -0
  292. package/src/lib/organization/membership.entity.js.map +1 -0
  293. package/src/lib/organization/org-unit-tree-commit-result.object.d.ts +4 -0
  294. package/src/lib/organization/org-unit-tree-commit-result.object.js +17 -0
  295. package/src/lib/organization/org-unit-tree-commit-result.object.js.map +1 -0
  296. package/src/lib/organization/org-unit.entity.d.ts +13 -0
  297. package/src/lib/organization/org-unit.entity.js +64 -0
  298. package/src/lib/organization/org-unit.entity.js.map +1 -0
  299. package/src/lib/organization/organization-summary.object.d.ts +6 -0
  300. package/src/lib/organization/organization-summary.object.js +28 -0
  301. package/src/lib/organization/organization-summary.object.js.map +1 -0
  302. package/src/lib/organization/organization.enums.d.ts +11 -0
  303. package/src/lib/organization/organization.enums.js +22 -0
  304. package/src/lib/organization/organization.enums.js.map +1 -0
  305. package/src/lib/organization/organization.module.d.ts +2 -0
  306. package/src/lib/organization/organization.module.js +35 -0
  307. package/src/lib/organization/organization.module.js.map +1 -0
  308. package/src/lib/organization/organization.mutations.d.ts +26 -0
  309. package/src/lib/organization/organization.mutations.js +148 -0
  310. package/src/lib/organization/organization.mutations.js.map +1 -0
  311. package/src/lib/organization/organization.queries.d.ts +23 -0
  312. package/src/lib/organization/organization.queries.js +202 -0
  313. package/src/lib/organization/organization.queries.js.map +1 -0
  314. package/src/lib/organization/organization.service.d.ts +102 -0
  315. package/src/lib/organization/organization.service.js +751 -0
  316. package/src/lib/organization/organization.service.js.map +1 -0
  317. package/src/lib/organization/position.entity.d.ts +9 -0
  318. package/src/lib/organization/position.entity.js +48 -0
  319. package/src/lib/organization/position.entity.js.map +1 -0
  320. package/src/lib/organization/resolved-manager.object.d.ts +4 -0
  321. package/src/lib/organization/resolved-manager.object.js +20 -0
  322. package/src/lib/organization/resolved-manager.object.js.map +1 -0
  323. package/src/lib/signature/index.js +8 -0
  324. package/src/lib/signature/index.js.map +1 -0
  325. package/src/lib/signature/signature-options.d.ts +33 -0
  326. package/src/lib/signature/signature-options.js +51 -0
  327. package/src/lib/signature/signature-options.js.map +1 -0
  328. package/src/lib/signature/signature-verification.object.d.ts +6 -0
  329. package/src/lib/signature/signature-verification.object.js +28 -0
  330. package/src/lib/signature/signature-verification.object.js.map +1 -0
  331. package/src/lib/signature/signature.entity.d.ts +16 -0
  332. package/src/lib/signature/signature.entity.js +88 -0
  333. package/src/lib/signature/signature.entity.js.map +1 -0
  334. package/src/lib/signature/signature.module.d.ts +11 -0
  335. package/src/lib/signature/signature.module.js +60 -0
  336. package/src/lib/signature/signature.module.js.map +1 -0
  337. package/src/lib/signature/signature.queries.d.ts +11 -0
  338. package/src/lib/signature/signature.queries.js +46 -0
  339. package/src/lib/signature/signature.queries.js.map +1 -0
  340. package/src/lib/signature/signature.service.d.ts +25 -0
  341. package/src/lib/signature/signature.service.js +124 -0
  342. package/src/lib/signature/signature.service.js.map +1 -0
  343. package/src/lib/template/approval-template-category.entity.d.ts +9 -0
  344. package/src/lib/template/approval-template-category.entity.js +49 -0
  345. package/src/lib/template/approval-template-category.entity.js.map +1 -0
  346. package/src/lib/template/approval-template-version.entity.d.ts +21 -0
  347. package/src/lib/template/approval-template-version.entity.js +106 -0
  348. package/src/lib/template/approval-template-version.entity.js.map +1 -0
  349. package/src/lib/template/approval-template.entity.d.ts +14 -0
  350. package/src/lib/template/approval-template.entity.js +74 -0
  351. package/src/lib/template/approval-template.entity.js.map +1 -0
  352. package/src/lib/template/dto/approval-template.input.d.ts +36 -0
  353. package/src/lib/template/dto/approval-template.input.js +187 -0
  354. package/src/lib/template/dto/approval-template.input.js.map +1 -0
  355. package/src/lib/template/index.js +12 -0
  356. package/src/lib/template/index.js.map +1 -0
  357. package/src/lib/template/template.enums.d.ts +14 -0
  358. package/src/lib/template/template.enums.js +31 -0
  359. package/src/lib/template/template.enums.js.map +1 -0
  360. package/src/lib/template/template.module.d.ts +2 -0
  361. package/src/lib/template/template.module.js +33 -0
  362. package/src/lib/template/template.module.js.map +1 -0
  363. package/src/lib/template/template.mutations.d.ts +20 -0
  364. package/src/lib/template/template.mutations.js +139 -0
  365. package/src/lib/template/template.mutations.js.map +1 -0
  366. package/src/lib/template/template.queries.d.ts +16 -0
  367. package/src/lib/template/template.queries.js +133 -0
  368. package/src/lib/template/template.queries.js.map +1 -0
  369. package/src/lib/template/template.service.d.ts +64 -0
  370. package/src/lib/template/template.service.js +521 -0
  371. package/src/lib/template/template.service.js.map +1 -0
  372. package/src/lib/template/workflow-definition.validator.d.ts +9 -0
  373. package/src/lib/template/workflow-definition.validator.js +362 -0
  374. package/src/lib/template/workflow-definition.validator.js.map +1 -0
  375. package/src/lib/testing/cel-js.jest.d.ts +15 -0
  376. package/src/lib/testing/cel-js.jest.js +27 -0
  377. package/src/lib/testing/cel-js.jest.js.map +1 -0
  378. package/src/lib/workflow-engine/activity-log.entity.d.ts +12 -0
  379. package/src/lib/workflow-engine/activity-log.entity.js +62 -0
  380. package/src/lib/workflow-engine/activity-log.entity.js.map +1 -0
  381. package/src/lib/workflow-engine/approval-instance-page-info.object.d.ts +8 -0
  382. package/src/lib/workflow-engine/approval-instance-page-info.object.js +36 -0
  383. package/src/lib/workflow-engine/approval-instance-page-info.object.js.map +1 -0
  384. package/src/lib/workflow-engine/approval-instance.entity.d.ts +22 -0
  385. package/src/lib/workflow-engine/approval-instance.entity.js +113 -0
  386. package/src/lib/workflow-engine/approval-instance.entity.js.map +1 -0
  387. package/src/lib/workflow-engine/dto/cancel-approval-instance.input.d.ts +5 -0
  388. package/src/lib/workflow-engine/dto/cancel-approval-instance.input.js +29 -0
  389. package/src/lib/workflow-engine/dto/cancel-approval-instance.input.js.map +1 -0
  390. package/src/lib/workflow-engine/dto/decide-task.input.d.ts +9 -0
  391. package/src/lib/workflow-engine/dto/decide-task.input.js +47 -0
  392. package/src/lib/workflow-engine/dto/decide-task.input.js.map +1 -0
  393. package/src/lib/workflow-engine/dto/dry-run-approval-workflow.input.d.ts +6 -0
  394. package/src/lib/workflow-engine/dto/dry-run-approval-workflow.input.js +34 -0
  395. package/src/lib/workflow-engine/dto/dry-run-approval-workflow.input.js.map +1 -0
  396. package/src/lib/workflow-engine/dto/resubmit-approval-instance.input.d.ts +6 -0
  397. package/src/lib/workflow-engine/dto/resubmit-approval-instance.input.js +34 -0
  398. package/src/lib/workflow-engine/dto/resubmit-approval-instance.input.js.map +1 -0
  399. package/src/lib/workflow-engine/dto/submit-approval-instance.input.d.ts +7 -0
  400. package/src/lib/workflow-engine/dto/submit-approval-instance.input.js +40 -0
  401. package/src/lib/workflow-engine/dto/submit-approval-instance.input.js.map +1 -0
  402. package/src/lib/workflow-engine/index.js +24 -0
  403. package/src/lib/workflow-engine/index.js.map +1 -0
  404. package/src/lib/workflow-engine/task-candidate.entity.d.ts +14 -0
  405. package/src/lib/workflow-engine/task-candidate.entity.js +72 -0
  406. package/src/lib/workflow-engine/task-candidate.entity.js.map +1 -0
  407. package/src/lib/workflow-engine/task-decision.entity.d.ts +12 -0
  408. package/src/lib/workflow-engine/task-decision.entity.js +60 -0
  409. package/src/lib/workflow-engine/task-decision.entity.js.map +1 -0
  410. package/src/lib/workflow-engine/task.entity.d.ts +20 -0
  411. package/src/lib/workflow-engine/task.entity.js +109 -0
  412. package/src/lib/workflow-engine/task.entity.js.map +1 -0
  413. package/src/lib/workflow-engine/workflow-condition-evaluator.d.ts +5 -0
  414. package/src/lib/workflow-engine/workflow-condition-evaluator.js +107 -0
  415. package/src/lib/workflow-engine/workflow-condition-evaluator.js.map +1 -0
  416. package/src/lib/workflow-engine/workflow-dashboard-summary.object.d.ts +8 -0
  417. package/src/lib/workflow-engine/workflow-dashboard-summary.object.js +36 -0
  418. package/src/lib/workflow-engine/workflow-dashboard-summary.object.js.map +1 -0
  419. package/src/lib/workflow-engine/workflow-dry-run.object.d.ts +21 -0
  420. package/src/lib/workflow-engine/workflow-dry-run.object.js +86 -0
  421. package/src/lib/workflow-engine/workflow-dry-run.object.js.map +1 -0
  422. package/src/lib/workflow-engine/workflow-engine.enums.d.ts +58 -0
  423. package/src/lib/workflow-engine/workflow-engine.enums.js +95 -0
  424. package/src/lib/workflow-engine/workflow-engine.enums.js.map +1 -0
  425. package/src/lib/workflow-engine/workflow-engine.module.d.ts +9 -0
  426. package/src/lib/workflow-engine/workflow-engine.module.js +76 -0
  427. package/src/lib/workflow-engine/workflow-engine.module.js.map +1 -0
  428. package/src/lib/workflow-engine/workflow-engine.mutations.d.ts +19 -0
  429. package/src/lib/workflow-engine/workflow-engine.mutations.js +106 -0
  430. package/src/lib/workflow-engine/workflow-engine.mutations.js.map +1 -0
  431. package/src/lib/workflow-engine/workflow-engine.queries.d.ts +29 -0
  432. package/src/lib/workflow-engine/workflow-engine.queries.js +225 -0
  433. package/src/lib/workflow-engine/workflow-engine.queries.js.map +1 -0
  434. package/src/lib/workflow-engine/workflow-engine.service.d.ts +145 -0
  435. package/src/lib/workflow-engine/workflow-engine.service.js +2785 -0
  436. package/src/lib/workflow-engine/workflow-engine.service.js.map +1 -0
  437. package/src/lib/workflow-engine/{workflow-engine.tokens.ts → workflow-engine.tokens.d.ts} +3 -9
  438. package/src/lib/workflow-engine/workflow-engine.tokens.js +5 -0
  439. package/src/lib/workflow-engine/workflow-engine.tokens.js.map +1 -0
  440. package/src/lib/workflow-engine/workflow-service-task-dispatcher.token.d.ts +18 -0
  441. package/src/lib/workflow-engine/workflow-service-task-dispatcher.token.js +39 -0
  442. package/src/lib/workflow-engine/workflow-service-task-dispatcher.token.js.map +1 -0
  443. package/src/lib/workflow-engine/workflow-token.entity.d.ts +10 -0
  444. package/src/lib/workflow-engine/workflow-token.entity.js +50 -0
  445. package/src/lib/workflow-engine/workflow-token.entity.js.map +1 -0
  446. package/eslint.config.mjs +0 -20
  447. package/jest.config.cts +0 -15
  448. package/project.json +0 -58
  449. package/src/lib/attachment/attachment-options.spec.ts +0 -45
  450. package/src/lib/attachment/attachment-options.ts +0 -130
  451. package/src/lib/attachment/attachment-storage.provider.spec.ts +0 -79
  452. package/src/lib/attachment/attachment-storage.provider.ts +0 -60
  453. package/src/lib/attachment/attachment.controller.ts +0 -39
  454. package/src/lib/attachment/attachment.entity.ts +0 -59
  455. package/src/lib/attachment/attachment.module.ts +0 -149
  456. package/src/lib/attachment/attachment.mutations.ts +0 -22
  457. package/src/lib/attachment/attachment.queries.ts +0 -65
  458. package/src/lib/attachment/attachment.service.spec.ts +0 -319
  459. package/src/lib/attachment/attachment.service.ts +0 -477
  460. package/src/lib/attachment/dto/upload-attachment.input.ts +0 -60
  461. package/src/lib/bpm/bpm-root.module.spec.ts +0 -138
  462. package/src/lib/bpm/bpm-root.module.ts +0 -320
  463. package/src/lib/bpm-auth/bpm-auth-context.extractor.ts +0 -106
  464. package/src/lib/bpm-auth/bpm-auth-context.ts +0 -40
  465. package/src/lib/bpm-auth/bpm-auth.authorization.ts +0 -80
  466. package/src/lib/bpm-auth/bpm-auth.decorators.ts +0 -19
  467. package/src/lib/bpm-auth/bpm-auth.guard.ts +0 -31
  468. package/src/lib/bpm-auth/bpm-auth.module.spec.ts +0 -106
  469. package/src/lib/bpm-auth/bpm-auth.module.ts +0 -69
  470. package/src/lib/bpm-auth/bpm-auth.options.ts +0 -21
  471. package/src/lib/bpm-auth/configurable-bpm-auth-context.accessor.ts +0 -55
  472. package/src/lib/common/filters/all-exceptions.filter.ts +0 -138
  473. package/src/lib/common/iso-duration.ts +0 -31
  474. package/src/lib/condition/condition.module.ts +0 -8
  475. package/src/lib/condition/condition.service.spec.ts +0 -50
  476. package/src/lib/condition/condition.service.ts +0 -141
  477. package/src/lib/database/data-source.ts +0 -7
  478. package/src/lib/database/migration-runner.ts +0 -24
  479. package/src/lib/database/typeorm.config.ts +0 -217
  480. package/src/lib/delegation/delegation-rule.entity.ts +0 -84
  481. package/src/lib/delegation/delegation.enums.ts +0 -21
  482. package/src/lib/delegation/delegation.module.ts +0 -14
  483. package/src/lib/delegation/delegation.mutations.ts +0 -92
  484. package/src/lib/delegation/delegation.queries.ts +0 -111
  485. package/src/lib/delegation/delegation.service.spec.ts +0 -295
  486. package/src/lib/delegation/delegation.service.ts +0 -482
  487. package/src/lib/delegation/dto/delegation-rule.input.ts +0 -125
  488. package/src/lib/form/dto/form-definition.input.ts +0 -73
  489. package/src/lib/form/form-definition-version.entity.ts +0 -66
  490. package/src/lib/form/form-definition.entity.ts +0 -54
  491. package/src/lib/form/form-schema-lint.object.ts +0 -10
  492. package/src/lib/form/form-schema.validator.spec.ts +0 -180
  493. package/src/lib/form/form-schema.validator.ts +0 -538
  494. package/src/lib/form/form.enums.ts +0 -20
  495. package/src/lib/form/form.module.ts +0 -19
  496. package/src/lib/form/form.mutations.ts +0 -68
  497. package/src/lib/form/form.queries.ts +0 -72
  498. package/src/lib/form/form.service.spec.ts +0 -144
  499. package/src/lib/form/form.service.ts +0 -490
  500. package/src/lib/identity/identity-options.ts +0 -41
  501. package/src/lib/identity/identity.module.ts +0 -96
  502. package/src/lib/identity/identity.queries.ts +0 -61
  503. package/src/lib/identity/identity.service.spec.ts +0 -105
  504. package/src/lib/identity/identity.service.ts +0 -200
  505. package/src/lib/identity/member-base.adapter.spec.ts +0 -77
  506. package/src/lib/identity/member-base.adapter.ts +0 -244
  507. package/src/lib/identity/member-metadata-cache.entity.ts +0 -27
  508. package/src/lib/identity/member-profile.object.ts +0 -28
  509. package/src/lib/identity/member-resolver.interface.ts +0 -47
  510. package/src/lib/migrations/0000000000001-enable-postgres-extensions.ts +0 -14
  511. package/src/lib/migrations/0000000011000-remove-attachment-encryption-key.ts +0 -19
  512. package/src/lib/migrations/0000000012000-notification-sla-idempotency.ts +0 -22
  513. package/src/lib/migrations/0000000013000-workflow-query-indexes.ts +0 -113
  514. package/src/lib/migrations/index.ts +0 -47
  515. package/src/lib/notification/dto/notification-preference.input.ts +0 -46
  516. package/src/lib/notification/notification-delivery-scheduler.service.ts +0 -69
  517. package/src/lib/notification/notification-delivery.service.spec.ts +0 -315
  518. package/src/lib/notification/notification-delivery.service.ts +0 -339
  519. package/src/lib/notification/notification-dispatcher.token.ts +0 -13
  520. package/src/lib/notification/notification-options.module.ts +0 -67
  521. package/src/lib/notification/notification-options.spec.ts +0 -93
  522. package/src/lib/notification/notification-options.ts +0 -452
  523. package/src/lib/notification/notification-preference.entity.ts +0 -35
  524. package/src/lib/notification/notification-sla-scheduler.service.ts +0 -66
  525. package/src/lib/notification/notification-template.spec.ts +0 -33
  526. package/src/lib/notification/notification-template.ts +0 -97
  527. package/src/lib/notification/notification.entity.ts +0 -102
  528. package/src/lib/notification/notification.enums.ts +0 -45
  529. package/src/lib/notification/notification.module.ts +0 -37
  530. package/src/lib/notification/notification.mutations.ts +0 -47
  531. package/src/lib/notification/notification.queries.ts +0 -64
  532. package/src/lib/notification/notification.service.spec.ts +0 -412
  533. package/src/lib/notification/notification.service.ts +0 -974
  534. package/src/lib/organization/dto/manager-resolution.input.ts +0 -91
  535. package/src/lib/organization/dto/membership.input.ts +0 -77
  536. package/src/lib/organization/dto/org-unit.input.ts +0 -96
  537. package/src/lib/organization/dto/position.input.ts +0 -50
  538. package/src/lib/organization/json-metadata.ts +0 -15
  539. package/src/lib/organization/manager-resolution.entity.ts +0 -44
  540. package/src/lib/organization/membership.entity.ts +0 -50
  541. package/src/lib/organization/org-unit-tree-commit-result.object.ts +0 -8
  542. package/src/lib/organization/org-unit.entity.ts +0 -53
  543. package/src/lib/organization/organization-summary.object.ts +0 -16
  544. package/src/lib/organization/organization.enums.ts +0 -19
  545. package/src/lib/organization/organization.module.ts +0 -27
  546. package/src/lib/organization/organization.mutations.ts +0 -115
  547. package/src/lib/organization/organization.queries.ts +0 -188
  548. package/src/lib/organization/organization.service.spec.ts +0 -760
  549. package/src/lib/organization/organization.service.ts +0 -1216
  550. package/src/lib/organization/position.entity.ts +0 -39
  551. package/src/lib/organization/resolved-manager.object.ts +0 -10
  552. package/src/lib/signature/signature-options.spec.ts +0 -60
  553. package/src/lib/signature/signature-options.ts +0 -120
  554. package/src/lib/signature/signature-verification.object.ts +0 -16
  555. package/src/lib/signature/signature.entity.ts +0 -62
  556. package/src/lib/signature/signature.module.ts +0 -80
  557. package/src/lib/signature/signature.queries.ts +0 -37
  558. package/src/lib/signature/signature.service.spec.ts +0 -134
  559. package/src/lib/signature/signature.service.ts +0 -205
  560. package/src/lib/template/approval-template-category.entity.ts +0 -40
  561. package/src/lib/template/approval-template-version.entity.ts +0 -82
  562. package/src/lib/template/approval-template.entity.ts +0 -64
  563. package/src/lib/template/dto/approval-template.input.ts +0 -147
  564. package/src/lib/template/template.enums.ts +0 -30
  565. package/src/lib/template/template.module.ts +0 -25
  566. package/src/lib/template/template.mutations.ts +0 -106
  567. package/src/lib/template/template.queries.ts +0 -119
  568. package/src/lib/template/template.service.spec.ts +0 -476
  569. package/src/lib/template/template.service.ts +0 -820
  570. package/src/lib/template/workflow-definition.validator.spec.ts +0 -595
  571. package/src/lib/template/workflow-definition.validator.ts +0 -539
  572. package/src/lib/testing/cel-js.jest.ts +0 -46
  573. package/src/lib/workflow-engine/activity-log.entity.ts +0 -48
  574. package/src/lib/workflow-engine/approval-instance-page-info.object.ts +0 -22
  575. package/src/lib/workflow-engine/approval-instance.entity.ts +0 -86
  576. package/src/lib/workflow-engine/dto/cancel-approval-instance.input.ts +0 -18
  577. package/src/lib/workflow-engine/dto/decide-task.input.ts +0 -33
  578. package/src/lib/workflow-engine/dto/dry-run-approval-workflow.input.ts +0 -22
  579. package/src/lib/workflow-engine/dto/resubmit-approval-instance.input.ts +0 -22
  580. package/src/lib/workflow-engine/dto/submit-approval-instance.input.ts +0 -27
  581. package/src/lib/workflow-engine/task-candidate.entity.ts +0 -56
  582. package/src/lib/workflow-engine/task-decision.entity.ts +0 -43
  583. package/src/lib/workflow-engine/task.entity.ts +0 -85
  584. package/src/lib/workflow-engine/workflow-condition-evaluator.ts +0 -168
  585. package/src/lib/workflow-engine/workflow-dashboard-summary.object.ts +0 -22
  586. package/src/lib/workflow-engine/workflow-dry-run.object.ts +0 -58
  587. package/src/lib/workflow-engine/workflow-engine.enums.ts +0 -99
  588. package/src/lib/workflow-engine/workflow-engine.module.ts +0 -75
  589. package/src/lib/workflow-engine/workflow-engine.mutations.ts +0 -85
  590. package/src/lib/workflow-engine/workflow-engine.queries.ts +0 -229
  591. package/src/lib/workflow-engine/workflow-engine.service.spec.ts +0 -2689
  592. package/src/lib/workflow-engine/workflow-engine.service.ts +0 -4707
  593. package/src/lib/workflow-engine/workflow-service-task-dispatcher.token.ts +0 -69
  594. package/src/lib/workflow-engine/workflow-token.entity.ts +0 -40
  595. package/tsconfig.json +0 -24
  596. package/tsconfig.lib.json +0 -16
  597. package/tsconfig.spec.json +0 -16
  598. /package/src/{index.ts → index.d.ts} +0 -0
  599. /package/src/lib/attachment/{index.ts → index.d.ts} +0 -0
  600. /package/src/lib/bpm/{index.ts → index.d.ts} +0 -0
  601. /package/src/lib/bpm-auth/{index.ts → index.d.ts} +0 -0
  602. /package/src/lib/common/{index.ts → index.d.ts} +0 -0
  603. /package/src/lib/condition/{index.ts → index.d.ts} +0 -0
  604. /package/src/lib/database/{index.ts → index.d.ts} +0 -0
  605. /package/src/lib/delegation/{index.ts → index.d.ts} +0 -0
  606. /package/src/lib/form/{index.ts → index.d.ts} +0 -0
  607. /package/src/lib/identity/{index.ts → index.d.ts} +0 -0
  608. /package/src/lib/notification/{index.ts → index.d.ts} +0 -0
  609. /package/src/lib/organization/{index.ts → index.d.ts} +0 -0
  610. /package/src/lib/signature/{index.ts → index.d.ts} +0 -0
  611. /package/src/lib/template/{index.ts → index.d.ts} +0 -0
  612. /package/src/lib/workflow-engine/{index.ts → index.d.ts} +0 -0
@@ -0,0 +1,751 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OrganizationService = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const node_crypto_1 = require("node:crypto");
6
+ const common_1 = require("@nestjs/common");
7
+ const typeorm_1 = require("@nestjs/typeorm");
8
+ const typeorm_2 = require("typeorm");
9
+ const manager_resolution_entity_1 = require("./manager-resolution.entity");
10
+ const membership_entity_1 = require("./membership.entity");
11
+ const org_unit_entity_1 = require("./org-unit.entity");
12
+ const organization_enums_1 = require("./organization.enums");
13
+ const position_entity_1 = require("./position.entity");
14
+ const json_metadata_1 = require("./json-metadata");
15
+ const ROOT_PATH_PREFIX = 'org';
16
+ const BUSINESS_TIME_ZONE = 'Asia/Taipei';
17
+ let OrganizationService = class OrganizationService {
18
+ constructor(dataSource, orgUnitRepository, positionRepository, membershipRepository, managerResolutionRepository) {
19
+ this.dataSource = dataSource;
20
+ this.orgUnitRepository = orgUnitRepository;
21
+ this.positionRepository = positionRepository;
22
+ this.membershipRepository = membershipRepository;
23
+ this.managerResolutionRepository = managerResolutionRepository;
24
+ }
25
+ async createOrgUnit(input) {
26
+ await this.assertOrgUnitCodeAvailable(input.code);
27
+ const id = (0, node_crypto_1.randomUUID)();
28
+ const parent = input.parentId
29
+ ? await this.getOrgUnitOrThrow(input.parentId)
30
+ : null;
31
+ const pathSegment = this.buildPathSegment(id);
32
+ const path = parent
33
+ ? `${parent.path}.${pathSegment}`
34
+ : `${ROOT_PATH_PREFIX}.${pathSegment}`;
35
+ const entity = this.orgUnitRepository.create({
36
+ code: input.code,
37
+ id,
38
+ metadata: (0, json_metadata_1.parseMetadataJson)(input.metadataJson),
39
+ name: input.name,
40
+ parentId: input.parentId,
41
+ path,
42
+ type: input.type,
43
+ });
44
+ return this.orgUnitRepository.save(entity);
45
+ }
46
+ async updateOrgUnit(input) {
47
+ const existing = await this.getOrgUnitOrThrow(input.id);
48
+ const nextParentId = input.parentId === undefined ? existing.parentId : input.parentId;
49
+ const parent = nextParentId
50
+ ? await this.getOrgUnitOrThrow(nextParentId)
51
+ : null;
52
+ const nextCode = input.code ?? existing.code;
53
+ if (nextParentId === existing.id) {
54
+ throw new common_1.BadRequestException('Org unit cannot be its own parent');
55
+ }
56
+ if (parent && parent.path.startsWith(`${existing.path}.`)) {
57
+ throw new common_1.BadRequestException('Org unit cannot be moved under its descendant');
58
+ }
59
+ await this.assertOrgUnitCodeAvailable(nextCode, existing.id);
60
+ const pathSegment = this.buildPathSegment(existing.id);
61
+ const path = parent
62
+ ? `${parent.path}.${pathSegment}`
63
+ : `${ROOT_PATH_PREFIX}.${pathSegment}`;
64
+ const previousPath = existing.path;
65
+ const next = this.orgUnitRepository.merge(existing, {
66
+ code: nextCode,
67
+ metadata: input.metadataJson
68
+ ? (0, json_metadata_1.parseMetadataJson)(input.metadataJson)
69
+ : existing.metadata,
70
+ name: input.name ?? existing.name,
71
+ parentId: nextParentId,
72
+ path,
73
+ type: input.type ?? existing.type,
74
+ });
75
+ return this.dataSource.transaction(async (manager) => {
76
+ const saved = await manager.getRepository(org_unit_entity_1.OrgUnitEntity).save(next);
77
+ if (saved.path !== previousPath) {
78
+ const descendants = await manager
79
+ .getRepository(org_unit_entity_1.OrgUnitEntity)
80
+ .createQueryBuilder('orgUnit')
81
+ .where('orgUnit.deleted_at IS NULL')
82
+ .andWhere('orgUnit.path <@ :previousPath', { previousPath })
83
+ .andWhere('orgUnit.id != :id', { id: saved.id })
84
+ .getMany();
85
+ await Promise.all(descendants.map((descendant) => {
86
+ const updatedDescendant = manager
87
+ .getRepository(org_unit_entity_1.OrgUnitEntity)
88
+ .merge(descendant, {
89
+ path: descendant.path.replace(previousPath, saved.path),
90
+ });
91
+ return manager
92
+ .getRepository(org_unit_entity_1.OrgUnitEntity)
93
+ .save(updatedDescendant);
94
+ }));
95
+ }
96
+ return saved;
97
+ });
98
+ }
99
+ async commitOrgUnitTreeDraft(input) {
100
+ if (!input.moves.length) {
101
+ return { orgUnits: [] };
102
+ }
103
+ this.assertUniqueOrgUnitTreeMoves(input.moves);
104
+ return this.dataSource.transaction(async (manager) => {
105
+ const repository = manager.getRepository(org_unit_entity_1.OrgUnitEntity);
106
+ const orgUnitIds = collectOrgUnitTreeDraftIds(input.moves);
107
+ const orgUnits = await repository.find({
108
+ where: { deletedAt: (0, typeorm_2.IsNull)(), id: (0, typeorm_2.In)(orgUnitIds) },
109
+ });
110
+ const orgUnitById = new Map(orgUnits.map((orgUnit) => [
111
+ orgUnit.id,
112
+ orgUnit,
113
+ ]));
114
+ this.assertOrgUnitTreeDraftReferences(input.moves, orgUnitById);
115
+ this.assertOrgUnitTreeDraftVersions(input.moves, orgUnitById);
116
+ this.assertOrgUnitTreeDraftHierarchy(input.moves, orgUnitById);
117
+ const affectedOrgUnits = new Map();
118
+ const sortedMoves = sortOrgUnitTreeDraftMoves(input.moves);
119
+ for (const move of sortedMoves) {
120
+ const existing = orgUnitById.get(move.id);
121
+ if (!existing) {
122
+ throw new common_1.NotFoundException(`Org unit ${move.id} was not found`);
123
+ }
124
+ const parent = move.parentId
125
+ ? orgUnitById.get(move.parentId) ?? null
126
+ : null;
127
+ const previousPath = existing.path;
128
+ const nextPath = parent
129
+ ? `${parent.path}.${this.buildPathSegment(existing.id)}`
130
+ : `${ROOT_PATH_PREFIX}.${this.buildPathSegment(existing.id)}`;
131
+ if (existing.parentId === move.parentId &&
132
+ existing.path === nextPath) {
133
+ affectedOrgUnits.set(existing.id, existing);
134
+ continue;
135
+ }
136
+ const saved = await repository.save(repository.merge(existing, {
137
+ parentId: move.parentId,
138
+ path: nextPath,
139
+ }));
140
+ orgUnitById.set(saved.id, saved);
141
+ affectedOrgUnits.set(saved.id, saved);
142
+ const descendants = await repository
143
+ .createQueryBuilder('orgUnit')
144
+ .where('orgUnit.deleted_at IS NULL')
145
+ .andWhere('orgUnit.path <@ :previousPath', { previousPath })
146
+ .andWhere('orgUnit.id != :id', { id: saved.id })
147
+ .getMany();
148
+ for (const descendant of descendants) {
149
+ const updatedDescendant = await repository.save(repository.merge(descendant, {
150
+ path: descendant.path.replace(previousPath, saved.path),
151
+ }));
152
+ orgUnitById.set(updatedDescendant.id, updatedDescendant);
153
+ affectedOrgUnits.set(updatedDescendant.id, updatedDescendant);
154
+ }
155
+ }
156
+ return {
157
+ orgUnits: [...affectedOrgUnits.values()].sort(compareOrgUnitPath),
158
+ };
159
+ });
160
+ }
161
+ async deleteOrgUnit(id) {
162
+ await this.getOrgUnitOrThrow(id);
163
+ const childCount = await this.orgUnitRepository.count({
164
+ where: { deletedAt: (0, typeorm_2.IsNull)(), parentId: id },
165
+ });
166
+ if (childCount > 0) {
167
+ throw new common_1.BadRequestException('Org unit with child units cannot be deleted');
168
+ }
169
+ const membershipCount = await this.membershipRepository.count({
170
+ where: { orgUnitId: id },
171
+ });
172
+ if (membershipCount > 0) {
173
+ throw new common_1.BadRequestException('Org unit with memberships cannot be deleted');
174
+ }
175
+ await this.orgUnitRepository.softDelete(id);
176
+ return true;
177
+ }
178
+ async getOrgUnit(id) {
179
+ return this.getOrgUnitOrThrow(id);
180
+ }
181
+ async listOrgUnits({ page, pageSize, parentId, searchText, type, } = {}) {
182
+ return this.orgUnitRepository.find({
183
+ ...createPaginationFindOptions({ page, pageSize }),
184
+ order: { path: 'ASC' },
185
+ where: createOrgUnitWhere({ parentId, searchText, type }),
186
+ });
187
+ }
188
+ async countOrgUnits({ parentId, searchText, type, } = {}) {
189
+ return this.orgUnitRepository.count({
190
+ where: createOrgUnitWhere({ parentId, searchText, type }),
191
+ });
192
+ }
193
+ async createPosition(input) {
194
+ await this.assertPositionCodeAvailable(input.code);
195
+ return this.positionRepository.save(this.positionRepository.create({
196
+ code: input.code,
197
+ level: input.level,
198
+ metadata: (0, json_metadata_1.parseMetadataJson)(input.metadataJson),
199
+ name: input.name,
200
+ }));
201
+ }
202
+ async updatePosition(input) {
203
+ const existing = await this.getPositionOrThrow(input.id);
204
+ const nextCode = input.code ?? existing.code;
205
+ await this.assertPositionCodeAvailable(nextCode, existing.id);
206
+ const next = this.positionRepository.merge(existing, {
207
+ code: nextCode,
208
+ level: input.level ?? existing.level,
209
+ metadata: input.metadataJson
210
+ ? (0, json_metadata_1.parseMetadataJson)(input.metadataJson)
211
+ : existing.metadata,
212
+ name: input.name ?? existing.name,
213
+ });
214
+ return this.positionRepository.save(next);
215
+ }
216
+ async listPositions({ page, pageSize, searchText, } = {}) {
217
+ return this.positionRepository.find({
218
+ ...createPaginationFindOptions({ page, pageSize }),
219
+ order: { level: 'DESC', code: 'ASC' },
220
+ where: createPositionWhere({ searchText }),
221
+ });
222
+ }
223
+ async countPositions({ searchText, } = {}) {
224
+ return this.positionRepository.count({
225
+ where: createPositionWhere({ searchText }),
226
+ });
227
+ }
228
+ async createMembership(input) {
229
+ await this.assertMembershipReferences(input);
230
+ await this.assertMembershipDateRange(input.effectiveFrom, input.effectiveTo);
231
+ if (input.isPrimary) {
232
+ await this.clearPrimaryMemberships(input.memberId);
233
+ }
234
+ return this.membershipRepository.save(this.membershipRepository.create(input));
235
+ }
236
+ async updateMembership(input) {
237
+ const existing = await this.getMembershipOrThrow(input.id);
238
+ const nextMemberId = existing.memberId;
239
+ const nextOrgUnitId = input.orgUnitId ?? existing.orgUnitId;
240
+ const nextPositionId = input.positionId === undefined ? existing.positionId : input.positionId;
241
+ const nextEffectiveFrom = input.effectiveFrom ?? existing.effectiveFrom;
242
+ const nextEffectiveTo = input.effectiveTo === undefined
243
+ ? existing.effectiveTo
244
+ : input.effectiveTo;
245
+ const nextIsPrimary = input.isPrimary ?? existing.isPrimary;
246
+ await this.assertMembershipReferences({
247
+ effectiveFrom: nextEffectiveFrom,
248
+ effectiveTo: nextEffectiveTo,
249
+ isPrimary: nextIsPrimary,
250
+ memberId: nextMemberId,
251
+ orgUnitId: nextOrgUnitId,
252
+ positionId: nextPositionId,
253
+ });
254
+ await this.assertMembershipDateRange(nextEffectiveFrom, nextEffectiveTo);
255
+ if (nextIsPrimary) {
256
+ await this.clearPrimaryMemberships(nextMemberId, existing.id);
257
+ }
258
+ const next = this.membershipRepository.merge(existing, {
259
+ effectiveFrom: nextEffectiveFrom,
260
+ effectiveTo: nextEffectiveTo,
261
+ isPrimary: nextIsPrimary,
262
+ orgUnitId: nextOrgUnitId,
263
+ positionId: nextPositionId,
264
+ });
265
+ return this.membershipRepository.save(next);
266
+ }
267
+ async deleteMembership(id) {
268
+ await this.getMembershipOrThrow(id);
269
+ await this.membershipRepository.delete(id);
270
+ return true;
271
+ }
272
+ async listMemberships({ activeOnly = false, memberId, orgUnitId, page, pageSize, positionId, } = {}) {
273
+ const date = this.toDateOnly(new Date());
274
+ return this.membershipRepository.find({
275
+ ...createPaginationFindOptions({ page, pageSize }),
276
+ order: { memberId: 'ASC', isPrimary: 'DESC', effectiveFrom: 'DESC' },
277
+ where: createMembershipWhere({
278
+ activeOnly,
279
+ date,
280
+ memberId,
281
+ orgUnitId,
282
+ positionId,
283
+ }),
284
+ });
285
+ }
286
+ async countMemberships({ activeOnly = false, memberId, orgUnitId, positionId, } = {}) {
287
+ const date = this.toDateOnly(new Date());
288
+ return this.membershipRepository.count({
289
+ where: createMembershipWhere({
290
+ activeOnly,
291
+ date,
292
+ memberId,
293
+ orgUnitId,
294
+ positionId,
295
+ }),
296
+ });
297
+ }
298
+ async createManagerResolution(input) {
299
+ await this.assertManagerResolutionReferences(input);
300
+ await this.assertMembershipDateRange(input.effectiveFrom, input.effectiveTo);
301
+ return this.managerResolutionRepository.save(this.managerResolutionRepository.create(input));
302
+ }
303
+ async updateManagerResolution(input) {
304
+ const existing = await this.getManagerResolutionOrThrow(input.id);
305
+ const nextScopeType = input.scopeType ?? existing.scopeType;
306
+ const nextScopeId = input.scopeId ?? existing.scopeId;
307
+ const nextManagerMemberId = input.managerMemberId ?? existing.managerMemberId;
308
+ const nextEffectiveFrom = input.effectiveFrom ?? existing.effectiveFrom;
309
+ const nextEffectiveTo = input.effectiveTo === undefined
310
+ ? existing.effectiveTo
311
+ : input.effectiveTo;
312
+ await this.assertManagerResolutionReferences({
313
+ effectiveFrom: nextEffectiveFrom,
314
+ effectiveTo: nextEffectiveTo,
315
+ managerMemberId: nextManagerMemberId,
316
+ priority: input.priority ?? existing.priority,
317
+ scopeId: nextScopeId,
318
+ scopeType: nextScopeType,
319
+ });
320
+ await this.assertMembershipDateRange(nextEffectiveFrom, nextEffectiveTo);
321
+ const next = this.managerResolutionRepository.merge(existing, {
322
+ effectiveFrom: nextEffectiveFrom,
323
+ effectiveTo: nextEffectiveTo,
324
+ managerMemberId: nextManagerMemberId,
325
+ priority: input.priority ?? existing.priority,
326
+ scopeId: nextScopeId,
327
+ scopeType: nextScopeType,
328
+ });
329
+ return this.managerResolutionRepository.save(next);
330
+ }
331
+ async deleteManagerResolution(id) {
332
+ await this.getManagerResolutionOrThrow(id);
333
+ await this.managerResolutionRepository.delete(id);
334
+ return true;
335
+ }
336
+ async listManagerResolutions({ activeOnly = false, page, pageSize, scopeId, scopeType, } = {}) {
337
+ const date = this.toDateOnly(new Date());
338
+ return this.managerResolutionRepository.find({
339
+ ...createPaginationFindOptions({ page, pageSize }),
340
+ order: { priority: 'DESC', createdAt: 'DESC' },
341
+ where: createManagerResolutionWhere({
342
+ activeOnly,
343
+ date,
344
+ scopeId,
345
+ scopeType,
346
+ }),
347
+ });
348
+ }
349
+ async countManagerResolutions({ activeOnly = false, scopeId, scopeType, } = {}) {
350
+ const date = this.toDateOnly(new Date());
351
+ return this.managerResolutionRepository.count({
352
+ where: createManagerResolutionWhere({
353
+ activeOnly,
354
+ date,
355
+ scopeId,
356
+ scopeType,
357
+ }),
358
+ });
359
+ }
360
+ async readOrganizationSummary() {
361
+ const [orgUnitCount, positionCount, membershipCount, managerResolutionCount,] = await Promise.all([
362
+ this.orgUnitRepository.count({ where: { deletedAt: (0, typeorm_2.IsNull)() } }),
363
+ this.positionRepository.count(),
364
+ this.membershipRepository.count(),
365
+ this.managerResolutionRepository.count(),
366
+ ]);
367
+ return {
368
+ managerResolutionCount,
369
+ membershipCount,
370
+ orgUnitCount,
371
+ positionCount,
372
+ };
373
+ }
374
+ async resolveManagerMemberId(memberId, effectiveAt = new Date()) {
375
+ const date = this.toDateOnly(effectiveAt);
376
+ const memberships = await this.findActiveMemberships(memberId, date);
377
+ const orgUnits = await this.findMembershipOrgUnits(memberships);
378
+ const positionIds = memberships
379
+ .map((membership) => membership.positionId)
380
+ .filter((positionId) => Boolean(positionId));
381
+ const candidatePairs = [
382
+ { scopeId: memberId, scopeType: organization_enums_1.ManagerResolutionScopeTypeEnum.MEMBER },
383
+ ...orgUnits.map((orgUnit) => ({
384
+ scopeId: orgUnit.id,
385
+ scopeType: organization_enums_1.ManagerResolutionScopeTypeEnum.ORG_UNIT,
386
+ })),
387
+ ...positionIds.map((positionId) => ({
388
+ scopeId: positionId,
389
+ scopeType: organization_enums_1.ManagerResolutionScopeTypeEnum.POSITION,
390
+ })),
391
+ ];
392
+ const scopeIds = candidatePairs.map((pair) => pair.scopeId);
393
+ const resolutions = scopeIds.length
394
+ ? await this.managerResolutionRepository.find({
395
+ where: {
396
+ scopeId: (0, typeorm_2.In)(scopeIds),
397
+ scopeType: (0, typeorm_2.In)([
398
+ organization_enums_1.ManagerResolutionScopeTypeEnum.MEMBER,
399
+ organization_enums_1.ManagerResolutionScopeTypeEnum.ORG_UNIT,
400
+ organization_enums_1.ManagerResolutionScopeTypeEnum.POSITION,
401
+ ]),
402
+ },
403
+ })
404
+ : [];
405
+ const active = resolutions
406
+ .filter((resolution) => candidatePairs.some((pair) => pair.scopeId === resolution.scopeId &&
407
+ pair.scopeType === resolution.scopeType))
408
+ .filter((resolution) => this.isDateActive(resolution, date))
409
+ .sort((left, right) => this.compareManagerResolution(left, right));
410
+ return active[0]?.managerMemberId ?? null;
411
+ }
412
+ assertUniqueOrgUnitTreeMoves(moves) {
413
+ const moveIds = moves.map((move) => move.id);
414
+ const uniqueMoveIds = new Set(moveIds);
415
+ if (uniqueMoveIds.size !== moveIds.length) {
416
+ throw new common_1.BadRequestException('Org unit tree draft includes duplicate moves');
417
+ }
418
+ }
419
+ assertOrgUnitTreeDraftReferences(moves, orgUnitById) {
420
+ const missingId = collectOrgUnitTreeDraftIds(moves).find((id) => !orgUnitById.has(id));
421
+ if (missingId) {
422
+ throw new common_1.NotFoundException(`Org unit ${missingId} was not found`);
423
+ }
424
+ }
425
+ assertOrgUnitTreeDraftVersions(moves, orgUnitById) {
426
+ const staleMove = moves.find((move) => {
427
+ const orgUnit = orgUnitById.get(move.id);
428
+ return orgUnit
429
+ ? orgUnit.updatedAt.getTime() !== parseBaseUpdatedAt(move).getTime()
430
+ : false;
431
+ });
432
+ if (staleMove) {
433
+ throw new common_1.ConflictException(`Org unit ${staleMove.id} has changed since this draft was based`);
434
+ }
435
+ }
436
+ assertOrgUnitTreeDraftHierarchy(moves, orgUnitById) {
437
+ for (const move of moves) {
438
+ if (move.id === move.parentId) {
439
+ throw new common_1.BadRequestException('Org unit cannot be its own parent');
440
+ }
441
+ const existing = orgUnitById.get(move.id);
442
+ const parent = move.parentId ? orgUnitById.get(move.parentId) : null;
443
+ if (existing && parent?.path.startsWith(`${existing.path}.`)) {
444
+ throw new common_1.BadRequestException('Org unit cannot be moved under its descendant');
445
+ }
446
+ }
447
+ assertOrgUnitTreeDraftHasNoCycles(moves);
448
+ }
449
+ async getOrgUnitOrThrow(id) {
450
+ const entity = await this.orgUnitRepository.findOne({
451
+ where: { deletedAt: (0, typeorm_2.IsNull)(), id },
452
+ });
453
+ if (!entity) {
454
+ throw new common_1.NotFoundException(`Org unit ${id} was not found`);
455
+ }
456
+ return entity;
457
+ }
458
+ async getPositionOrThrow(id) {
459
+ const entity = await this.positionRepository.findOne({ where: { id } });
460
+ if (!entity) {
461
+ throw new common_1.NotFoundException(`Position ${id} was not found`);
462
+ }
463
+ return entity;
464
+ }
465
+ async assertOrgUnitCodeAvailable(code, exceptId) {
466
+ const existing = await this.orgUnitRepository.findOne({
467
+ where: {
468
+ code,
469
+ deletedAt: (0, typeorm_2.IsNull)(),
470
+ ...(exceptId ? { id: (0, typeorm_2.Not)(exceptId) } : {}),
471
+ },
472
+ });
473
+ if (existing) {
474
+ throw new common_1.BadRequestException(`Org unit code ${code} is already used`);
475
+ }
476
+ }
477
+ async assertPositionCodeAvailable(code, exceptId) {
478
+ const existing = await this.positionRepository.findOne({
479
+ where: {
480
+ code,
481
+ ...(exceptId ? { id: (0, typeorm_2.Not)(exceptId) } : {}),
482
+ },
483
+ });
484
+ if (existing) {
485
+ throw new common_1.BadRequestException(`Position code ${code} is already used`);
486
+ }
487
+ }
488
+ async assertMembershipReferences(input) {
489
+ await this.getOrgUnitOrThrow(input.orgUnitId);
490
+ if (input.positionId) {
491
+ await this.getPositionOrThrow(input.positionId);
492
+ }
493
+ }
494
+ async assertManagerResolutionReferences(input) {
495
+ if (input.scopeType === organization_enums_1.ManagerResolutionScopeTypeEnum.MEMBER &&
496
+ input.scopeId === input.managerMemberId) {
497
+ throw new common_1.BadRequestException('Manager cannot be the scoped member');
498
+ }
499
+ if (input.scopeType === organization_enums_1.ManagerResolutionScopeTypeEnum.ORG_UNIT) {
500
+ await this.getOrgUnitOrThrow(input.scopeId);
501
+ }
502
+ if (input.scopeType === organization_enums_1.ManagerResolutionScopeTypeEnum.POSITION) {
503
+ await this.getPositionOrThrow(input.scopeId);
504
+ }
505
+ }
506
+ async assertMembershipDateRange(effectiveFrom, effectiveTo) {
507
+ if (effectiveTo && effectiveFrom > effectiveTo) {
508
+ throw new common_1.BadRequestException('Effective from cannot be after effective to');
509
+ }
510
+ }
511
+ async clearPrimaryMemberships(memberId, exceptId) {
512
+ await this.membershipRepository.update({
513
+ isPrimary: true,
514
+ memberId,
515
+ ...(exceptId ? { id: (0, typeorm_2.Not)(exceptId) } : {}),
516
+ }, { isPrimary: false });
517
+ }
518
+ async getMembershipOrThrow(id) {
519
+ const entity = await this.membershipRepository.findOne({ where: { id } });
520
+ if (!entity) {
521
+ throw new common_1.NotFoundException(`Membership ${id} was not found`);
522
+ }
523
+ return entity;
524
+ }
525
+ async getManagerResolutionOrThrow(id) {
526
+ const entity = await this.managerResolutionRepository.findOne({
527
+ where: { id },
528
+ });
529
+ if (!entity) {
530
+ throw new common_1.NotFoundException(`Manager resolution ${id} was not found`);
531
+ }
532
+ return entity;
533
+ }
534
+ async findActiveMemberships(memberId, date) {
535
+ const memberships = await this.membershipRepository.find({
536
+ where: { memberId },
537
+ });
538
+ return memberships.filter((membership) => this.isDateActive(membership, date));
539
+ }
540
+ async findMembershipOrgUnits(memberships) {
541
+ const orgUnitIds = memberships.map((membership) => membership.orgUnitId);
542
+ if (!orgUnitIds.length) {
543
+ return [];
544
+ }
545
+ const directOrgUnits = await this.orgUnitRepository.find({
546
+ where: { deletedAt: (0, typeorm_2.IsNull)(), id: (0, typeorm_2.In)(orgUnitIds) },
547
+ });
548
+ const ancestorGroups = await Promise.all(directOrgUnits.map((orgUnit) => this.orgUnitRepository
549
+ .createQueryBuilder('orgUnit')
550
+ .where('orgUnit.deleted_at IS NULL')
551
+ .andWhere('orgUnit.path @> :path', { path: orgUnit.path })
552
+ .getMany()));
553
+ const flattened = ancestorGroups.flat();
554
+ const byId = new Map(flattened.map((orgUnit) => [
555
+ orgUnit.id,
556
+ orgUnit,
557
+ ]));
558
+ return [...byId.values()];
559
+ }
560
+ buildPathSegment(id) {
561
+ return `n${id.replace(/-/g, '_')}`;
562
+ }
563
+ toDateOnly(date) {
564
+ const parts = new Intl.DateTimeFormat('en-US', {
565
+ day: '2-digit',
566
+ month: '2-digit',
567
+ timeZone: BUSINESS_TIME_ZONE,
568
+ year: 'numeric',
569
+ }).formatToParts(date);
570
+ const byType = new Map(parts.map((part) => [part.type, part.value]));
571
+ return `${byType.get('year') ?? '1970'}-${byType.get('month') ?? '01'}-${byType.get('day') ?? '01'}`;
572
+ }
573
+ isDateActive(value, date) {
574
+ return (value.effectiveFrom <= date &&
575
+ (!value.effectiveTo || value.effectiveTo >= date));
576
+ }
577
+ compareManagerResolution(left, right) {
578
+ const priorityDiff = right.priority - left.priority;
579
+ if (priorityDiff !== 0) {
580
+ return priorityDiff;
581
+ }
582
+ return (this.scopeRank(right.scopeType) - this.scopeRank(left.scopeType) ||
583
+ right.effectiveFrom.localeCompare(left.effectiveFrom));
584
+ }
585
+ scopeRank(scopeType) {
586
+ const ranks = {
587
+ [organization_enums_1.ManagerResolutionScopeTypeEnum.MEMBER]: 3,
588
+ [organization_enums_1.ManagerResolutionScopeTypeEnum.ORG_UNIT]: 2,
589
+ [organization_enums_1.ManagerResolutionScopeTypeEnum.POSITION]: 1,
590
+ };
591
+ return ranks[scopeType];
592
+ }
593
+ };
594
+ exports.OrganizationService = OrganizationService;
595
+ exports.OrganizationService = OrganizationService = tslib_1.__decorate([
596
+ (0, common_1.Injectable)(),
597
+ tslib_1.__param(1, (0, typeorm_1.InjectRepository)(org_unit_entity_1.OrgUnitEntity)),
598
+ tslib_1.__param(2, (0, typeorm_1.InjectRepository)(position_entity_1.PositionEntity)),
599
+ tslib_1.__param(3, (0, typeorm_1.InjectRepository)(membership_entity_1.MembershipEntity)),
600
+ tslib_1.__param(4, (0, typeorm_1.InjectRepository)(manager_resolution_entity_1.ManagerResolutionEntity)),
601
+ tslib_1.__metadata("design:paramtypes", [typeorm_2.DataSource,
602
+ typeorm_2.Repository,
603
+ typeorm_2.Repository,
604
+ typeorm_2.Repository,
605
+ typeorm_2.Repository])
606
+ ], OrganizationService);
607
+ function createOrgUnitWhere({ parentId, searchText, type, }) {
608
+ const parentWhere = parentId === undefined
609
+ ? {}
610
+ : { parentId: parentId === null ? (0, typeorm_2.IsNull)() : parentId };
611
+ const baseWhere = {
612
+ deletedAt: (0, typeorm_2.IsNull)(),
613
+ ...parentWhere,
614
+ ...(type ? { type } : {}),
615
+ };
616
+ const trimmedSearchText = searchText?.trim();
617
+ if (!trimmedSearchText) {
618
+ return baseWhere;
619
+ }
620
+ const searchPattern = `%${trimmedSearchText}%`;
621
+ return [
622
+ { ...baseWhere, code: (0, typeorm_2.ILike)(searchPattern) },
623
+ { ...baseWhere, name: (0, typeorm_2.ILike)(searchPattern) },
624
+ ];
625
+ }
626
+ function createPositionWhere({ searchText, }) {
627
+ const trimmedSearchText = searchText?.trim();
628
+ if (!trimmedSearchText) {
629
+ return {};
630
+ }
631
+ const searchPattern = `%${trimmedSearchText}%`;
632
+ return [{ code: (0, typeorm_2.ILike)(searchPattern) }, { name: (0, typeorm_2.ILike)(searchPattern) }];
633
+ }
634
+ function createMembershipWhere({ activeOnly, date, memberId, orgUnitId, positionId, }) {
635
+ const baseWhere = {
636
+ ...(memberId ? { memberId } : {}),
637
+ ...(orgUnitId ? { orgUnitId } : {}),
638
+ ...(positionId ? { positionId } : {}),
639
+ };
640
+ if (!activeOnly) {
641
+ return baseWhere;
642
+ }
643
+ return [
644
+ {
645
+ ...baseWhere,
646
+ effectiveFrom: (0, typeorm_2.LessThanOrEqual)(date),
647
+ effectiveTo: (0, typeorm_2.IsNull)(),
648
+ },
649
+ {
650
+ ...baseWhere,
651
+ effectiveFrom: (0, typeorm_2.LessThanOrEqual)(date),
652
+ effectiveTo: (0, typeorm_2.MoreThanOrEqual)(date),
653
+ },
654
+ ];
655
+ }
656
+ function createManagerResolutionWhere({ activeOnly, date, scopeId, scopeType, }) {
657
+ const baseWhere = {
658
+ ...(scopeId ? { scopeId } : {}),
659
+ ...(scopeType ? { scopeType } : {}),
660
+ };
661
+ if (!activeOnly) {
662
+ return baseWhere;
663
+ }
664
+ return [
665
+ {
666
+ ...baseWhere,
667
+ effectiveFrom: (0, typeorm_2.LessThanOrEqual)(date),
668
+ effectiveTo: (0, typeorm_2.IsNull)(),
669
+ },
670
+ {
671
+ ...baseWhere,
672
+ effectiveFrom: (0, typeorm_2.LessThanOrEqual)(date),
673
+ effectiveTo: (0, typeorm_2.MoreThanOrEqual)(date),
674
+ },
675
+ ];
676
+ }
677
+ function createPaginationFindOptions({ page, pageSize, }) {
678
+ const normalizedPageSize = normalizePageSize(pageSize);
679
+ if (!normalizedPageSize) {
680
+ return {};
681
+ }
682
+ return {
683
+ skip: (normalizePage(page) - 1) * normalizedPageSize,
684
+ take: normalizedPageSize,
685
+ };
686
+ }
687
+ function normalizePage(page) {
688
+ if (typeof page !== 'number' || !Number.isFinite(page)) {
689
+ return 1;
690
+ }
691
+ return Math.max(1, Math.floor(page));
692
+ }
693
+ function normalizePageSize(pageSize) {
694
+ if (typeof pageSize !== 'number' || !Number.isFinite(pageSize)) {
695
+ return null;
696
+ }
697
+ return Math.min(100, Math.max(1, Math.floor(pageSize)));
698
+ }
699
+ function collectOrgUnitTreeDraftIds(moves) {
700
+ return [
701
+ ...new Set(moves.flatMap((move) => move.parentId ? [move.id, move.parentId] : [move.id])),
702
+ ];
703
+ }
704
+ function parseBaseUpdatedAt(move) {
705
+ const baseUpdatedAt = new Date(move.baseUpdatedAt);
706
+ if (Number.isNaN(baseUpdatedAt.getTime())) {
707
+ throw new common_1.BadRequestException(`Org unit ${move.id} baseUpdatedAt is invalid`);
708
+ }
709
+ return baseUpdatedAt;
710
+ }
711
+ function assertOrgUnitTreeDraftHasNoCycles(moves) {
712
+ const parentById = new Map(moves.map((move) => [
713
+ move.id,
714
+ move.parentId,
715
+ ]));
716
+ for (const move of moves) {
717
+ const visited = new Set();
718
+ let parentId = move.parentId;
719
+ while (parentId && parentById.has(parentId)) {
720
+ if (parentId === move.id || visited.has(parentId)) {
721
+ throw new common_1.BadRequestException('Org unit tree draft cannot create a cycle');
722
+ }
723
+ visited.add(parentId);
724
+ parentId = parentById.get(parentId) ?? null;
725
+ }
726
+ }
727
+ }
728
+ function sortOrgUnitTreeDraftMoves(moves) {
729
+ const moveById = new Map(moves.map((move) => [
730
+ move.id,
731
+ move,
732
+ ]));
733
+ return [...moves].sort((left, right) => {
734
+ const leftDepth = calculateOrgUnitTreeDraftMoveDepth(left, moveById);
735
+ const rightDepth = calculateOrgUnitTreeDraftMoveDepth(right, moveById);
736
+ return leftDepth - rightDepth || left.id.localeCompare(right.id);
737
+ });
738
+ }
739
+ function calculateOrgUnitTreeDraftMoveDepth(move, moveById) {
740
+ let depth = 0;
741
+ let parentId = move.parentId;
742
+ while (parentId && moveById.has(parentId)) {
743
+ depth += 1;
744
+ parentId = moveById.get(parentId)?.parentId ?? null;
745
+ }
746
+ return depth;
747
+ }
748
+ function compareOrgUnitPath(left, right) {
749
+ return left.path.localeCompare(right.path);
750
+ }
751
+ //# sourceMappingURL=organization.service.js.map