@tomei/sso 0.50.8 → 0.51.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (431) hide show
  1. package/.commitlintrc.json +22 -22
  2. package/.eslintrc +16 -16
  3. package/.eslintrc.js +35 -35
  4. package/.gitlab-ci.yml +16 -16
  5. package/.husky/commit-msg +15 -15
  6. package/.husky/pre-commit +7 -7
  7. package/.prettierrc +4 -4
  8. package/Jenkinsfile +57 -57
  9. package/README.md +23 -23
  10. package/__tests__/unit/components/group/group.spec.ts +79 -79
  11. package/__tests__/unit/components/group-object-privilege/group-object-privilege.spec.ts +88 -88
  12. package/__tests__/unit/components/group-privilege/group-privilege.spec.ts +68 -68
  13. package/__tests__/unit/components/group-reporting-user/group-reporting-user.spec.ts +66 -66
  14. package/__tests__/unit/components/group-system-access/group-system-access.spec.ts +83 -83
  15. package/__tests__/unit/components/login-user/l.spec.ts +746 -746
  16. package/__tests__/unit/components/login-user/login.spec.ts +1164 -1164
  17. package/__tests__/unit/components/password-hash/password-hash.service.spec.ts +31 -31
  18. package/__tests__/unit/components/system/system.spec.ts +254 -254
  19. package/__tests__/unit/components/system-privilege/system-privilege.spec.ts +83 -83
  20. package/__tests__/unit/components/user-group/user-group.spec.ts +86 -86
  21. package/__tests__/unit/components/user-object-privilege/user-object-privilege.spec.ts +78 -78
  22. package/__tests__/unit/components/user-privilege/user-privilege.spec.ts +72 -72
  23. package/__tests__/unit/components/user-system-access/user-system-access.spec.ts +89 -89
  24. package/__tests__/unit/redis-client/redis.service.spec.ts +23 -23
  25. package/__tests__/unit/session/session.service.spec.ts +47 -47
  26. package/__tests__/unit/system-privilege/system-privilage.spec.ts +91 -91
  27. package/coverage/clover.xml +1452 -1452
  28. package/coverage/coverage-final.json +47 -47
  29. package/coverage/lcov-report/base.css +224 -224
  30. package/coverage/lcov-report/block-navigation.js +87 -87
  31. package/coverage/lcov-report/components/group/group.repository.ts.html +117 -117
  32. package/coverage/lcov-report/components/group/group.ts.html +327 -327
  33. package/coverage/lcov-report/components/group/index.html +130 -130
  34. package/coverage/lcov-report/components/group-object-privilege/group-object-privilege.repository.ts.html +117 -117
  35. package/coverage/lcov-report/components/group-object-privilege/group-object-privilege.ts.html +321 -321
  36. package/coverage/lcov-report/components/group-object-privilege/index.html +130 -130
  37. package/coverage/lcov-report/components/group-privilege/group-privilege.repository.ts.html +117 -117
  38. package/coverage/lcov-report/components/group-privilege/group-privilege.ts.html +303 -303
  39. package/coverage/lcov-report/components/group-privilege/index.html +130 -130
  40. package/coverage/lcov-report/components/group-reporting-user/group-reporting-user.repository.ts.html +117 -117
  41. package/coverage/lcov-report/components/group-reporting-user/group-reporting-user.ts.html +327 -327
  42. package/coverage/lcov-report/components/group-reporting-user/index.html +130 -130
  43. package/coverage/lcov-report/components/group-system-access/group-system-access.repository.ts.html +117 -117
  44. package/coverage/lcov-report/components/group-system-access/group-system-access.ts.html +309 -309
  45. package/coverage/lcov-report/components/group-system-access/index.html +130 -130
  46. package/coverage/lcov-report/components/login-history/index.html +115 -115
  47. package/coverage/lcov-report/components/login-history/login-history.repository.ts.html +117 -117
  48. package/coverage/lcov-report/components/login-user/index.html +130 -130
  49. package/coverage/lcov-report/components/login-user/login-user.ts.html +5007 -5007
  50. package/coverage/lcov-report/components/login-user/user.repository.ts.html +117 -117
  51. package/coverage/lcov-report/components/password-hash/index.html +115 -115
  52. package/coverage/lcov-report/components/password-hash/password-hash.service.ts.html +126 -126
  53. package/coverage/lcov-report/components/system/index.html +130 -130
  54. package/coverage/lcov-report/components/system/system.repository.ts.html +117 -117
  55. package/coverage/lcov-report/components/system/system.ts.html +909 -909
  56. package/coverage/lcov-report/components/system-privilege/index.html +130 -130
  57. package/coverage/lcov-report/components/system-privilege/system-privilege.repository.ts.html +120 -120
  58. package/coverage/lcov-report/components/system-privilege/system-privilege.ts.html +390 -390
  59. package/coverage/lcov-report/components/user-group/index.html +130 -130
  60. package/coverage/lcov-report/components/user-group/user-group.repository.ts.html +117 -117
  61. package/coverage/lcov-report/components/user-group/user-group.ts.html +354 -354
  62. package/coverage/lcov-report/components/user-object-privilege/index.html +130 -130
  63. package/coverage/lcov-report/components/user-object-privilege/user-object-privilege.repository.ts.html +117 -117
  64. package/coverage/lcov-report/components/user-object-privilege/user-object-privilege.ts.html +312 -312
  65. package/coverage/lcov-report/components/user-privilege/index.html +130 -130
  66. package/coverage/lcov-report/components/user-privilege/user-privilege.repository.ts.html +117 -117
  67. package/coverage/lcov-report/components/user-privilege/user-privilege.ts.html +306 -306
  68. package/coverage/lcov-report/components/user-system-access/index.html +130 -130
  69. package/coverage/lcov-report/components/user-system-access/user-system-access.repository.ts.html +117 -117
  70. package/coverage/lcov-report/components/user-system-access/user-system-access.ts.html +312 -312
  71. package/coverage/lcov-report/enum/group-type.enum.ts.html +108 -108
  72. package/coverage/lcov-report/enum/index.html +160 -160
  73. package/coverage/lcov-report/enum/index.ts.html +93 -93
  74. package/coverage/lcov-report/enum/user-status.enum.ts.html +105 -105
  75. package/coverage/lcov-report/enum/yn.enum.ts.html +96 -96
  76. package/coverage/lcov-report/index.html +370 -370
  77. package/coverage/lcov-report/models/group-object-privilege.entity.ts.html +333 -333
  78. package/coverage/lcov-report/models/group-privilege.entity.ts.html +315 -315
  79. package/coverage/lcov-report/models/group-reporting-user.entity.ts.html +339 -339
  80. package/coverage/lcov-report/models/group-system-access.entity.ts.html +324 -324
  81. package/coverage/lcov-report/models/group.entity.ts.html +435 -435
  82. package/coverage/lcov-report/models/index.html +310 -310
  83. package/coverage/lcov-report/models/login-history.entity.ts.html +252 -252
  84. package/coverage/lcov-report/models/staff.entity.ts.html +411 -411
  85. package/coverage/lcov-report/models/system-privilege.entity.ts.html +354 -354
  86. package/coverage/lcov-report/models/system.entity.ts.html +423 -423
  87. package/coverage/lcov-report/models/user-group.entity.ts.html +354 -354
  88. package/coverage/lcov-report/models/user-object-privilege.entity.ts.html +330 -330
  89. package/coverage/lcov-report/models/user-privilege.entity.ts.html +315 -315
  90. package/coverage/lcov-report/models/user-system-access.entity.ts.html +315 -315
  91. package/coverage/lcov-report/models/user.entity.ts.html +522 -522
  92. package/coverage/lcov-report/prettify.css +1 -1
  93. package/coverage/lcov-report/prettify.js +2 -2
  94. package/coverage/lcov-report/redis-client/index.html +115 -115
  95. package/coverage/lcov-report/redis-client/redis.service.ts.html +240 -240
  96. package/coverage/lcov-report/session/index.html +115 -115
  97. package/coverage/lcov-report/session/session.service.ts.html +246 -246
  98. package/coverage/lcov-report/sorter.js +196 -196
  99. package/coverage/lcov.info +2490 -2490
  100. package/coverage/test-report.xml +128 -128
  101. package/create-sso-user.sql +39 -39
  102. package/dist/__tests__/unit/components/group/group.spec.d.ts +1 -1
  103. package/dist/__tests__/unit/components/group/group.spec.js +71 -71
  104. package/dist/__tests__/unit/components/group-object-privilege/group-object-privilege.spec.d.ts +1 -1
  105. package/dist/__tests__/unit/components/group-object-privilege/group-object-privilege.spec.js +85 -85
  106. package/dist/__tests__/unit/components/group-privilege/group-privilege.spec.d.ts +1 -1
  107. package/dist/__tests__/unit/components/group-privilege/group-privilege.spec.js +70 -70
  108. package/dist/__tests__/unit/components/group-privilege/group-privilege.test.d.ts +1 -0
  109. package/dist/__tests__/unit/components/group-privilege/group-privilege.test.js +71 -0
  110. package/dist/__tests__/unit/components/group-privilege/group-privilege.test.js.map +1 -0
  111. package/dist/__tests__/unit/components/group-reporting-user/group-reporting-user.spec.d.ts +1 -1
  112. package/dist/__tests__/unit/components/group-reporting-user/group-reporting-user.spec.js +57 -57
  113. package/dist/__tests__/unit/components/group-system-access/group-system-access.spec.d.ts +1 -1
  114. package/dist/__tests__/unit/components/group-system-access/group-system-access.spec.js +82 -82
  115. package/dist/__tests__/unit/components/login-user/l.spec.js +5 -5
  116. package/dist/__tests__/unit/components/login-user/login-user.spec.d.ts +0 -0
  117. package/dist/__tests__/unit/components/login-user/login-user.spec.js +6 -0
  118. package/dist/__tests__/unit/components/login-user/login-user.spec.js.map +1 -0
  119. package/dist/__tests__/unit/components/login-user/login.spec.d.ts +1 -1
  120. package/dist/__tests__/unit/components/login-user/login.spec.js +2 -2
  121. package/dist/__tests__/unit/components/password-hash/password-hash.service.spec.d.ts +1 -1
  122. package/dist/__tests__/unit/components/password-hash/password-hash.service.spec.js +37 -37
  123. package/dist/__tests__/unit/components/system/system.spec.d.ts +1 -1
  124. package/dist/__tests__/unit/components/system/system.spec.js +203 -203
  125. package/dist/__tests__/unit/components/system-privilege/system-privilege.spec.d.ts +1 -1
  126. package/dist/__tests__/unit/components/system-privilege/system-privilege.spec.js +84 -84
  127. package/dist/__tests__/unit/components/user-group/user-group.spec.d.ts +1 -1
  128. package/dist/__tests__/unit/components/user-group/user-group.spec.js +81 -81
  129. package/dist/__tests__/unit/components/user-object-privilege/user-object-privilege.spec.d.ts +1 -1
  130. package/dist/__tests__/unit/components/user-object-privilege/user-object-privilege.spec.js +78 -78
  131. package/dist/__tests__/unit/components/user-privilege/user-privilege.spec.d.ts +1 -1
  132. package/dist/__tests__/unit/components/user-privilege/user-privilege.spec.js +75 -75
  133. package/dist/__tests__/unit/components/user-system-access/user-system-access.spec.d.ts +1 -1
  134. package/dist/__tests__/unit/components/user-system-access/user-system-access.spec.js +82 -82
  135. package/dist/__tests__/unit/components/user-system-access/user-system-access.spec.js.map +1 -1
  136. package/dist/__tests__/unit/redis-client/redis.service.spec.d.ts +1 -1
  137. package/dist/__tests__/unit/redis-client/redis.service.spec.js +31 -31
  138. package/dist/__tests__/unit/session/session.service.spec.d.ts +1 -1
  139. package/dist/__tests__/unit/session/session.service.spec.js +54 -54
  140. package/dist/__tests__/unit/system-privilege/system-privilage.spec.js +5 -5
  141. package/dist/index.d.ts +1 -1
  142. package/dist/index.js +17 -17
  143. package/dist/src/components/api-key/api-key.d.ts +84 -84
  144. package/dist/src/components/api-key/api-key.js +255 -255
  145. package/dist/src/components/api-key/api-key.js.map +1 -1
  146. package/dist/src/components/api-key/api-key.repository.d.ts +6 -6
  147. package/dist/src/components/api-key/api-key.repository.js +25 -25
  148. package/dist/src/components/api-key/index.d.ts +3 -3
  149. package/dist/src/components/api-key/index.js +7 -7
  150. package/dist/src/components/building/building.repository.d.ts +6 -6
  151. package/dist/src/components/building/building.repository.js +37 -37
  152. package/dist/src/components/building/building.repository.js.map +1 -1
  153. package/dist/src/components/building/index.d.ts +1 -1
  154. package/dist/src/components/building/index.js +17 -17
  155. package/dist/src/components/group/group.d.ts +112 -112
  156. package/dist/src/components/group/group.js +1240 -1240
  157. package/dist/src/components/group/group.js.map +1 -1
  158. package/dist/src/components/group/group.repository.d.ts +7 -7
  159. package/dist/src/components/group/group.repository.js +36 -36
  160. package/dist/src/components/group/group.repository.js.map +1 -1
  161. package/dist/src/components/group/index.d.ts +2 -2
  162. package/dist/src/components/group/index.js +18 -18
  163. package/dist/src/components/group-object-privilege/group-object-privilege.d.ts +27 -27
  164. package/dist/src/components/group-object-privilege/group-object-privilege.js +177 -177
  165. package/dist/src/components/group-object-privilege/group-object-privilege.js.map +1 -1
  166. package/dist/src/components/group-object-privilege/group-object-privilege.repository.d.ts +6 -6
  167. package/dist/src/components/group-object-privilege/group-object-privilege.repository.js +33 -33
  168. package/dist/src/components/group-object-privilege/group-object-privilege.repository.js.map +1 -1
  169. package/dist/src/components/group-object-privilege/index.d.ts +2 -2
  170. package/dist/src/components/group-object-privilege/index.js +18 -18
  171. package/dist/src/components/group-privilege/group-privilege.d.ts +24 -24
  172. package/dist/src/components/group-privilege/group-privilege.js +77 -77
  173. package/dist/src/components/group-privilege/group-privilege.js.map +1 -1
  174. package/dist/src/components/group-privilege/group-privilege.repository.d.ts +6 -6
  175. package/dist/src/components/group-privilege/group-privilege.repository.js +35 -35
  176. package/dist/src/components/group-privilege/group-privilege.repository.js.map +1 -1
  177. package/dist/src/components/group-privilege/index.d.ts +2 -2
  178. package/dist/src/components/group-privilege/index.js +18 -18
  179. package/dist/src/components/group-reporting-user/group-reporting-user.d.ts +28 -28
  180. package/dist/src/components/group-reporting-user/group-reporting-user.js +208 -208
  181. package/dist/src/components/group-reporting-user/group-reporting-user.js.map +1 -1
  182. package/dist/src/components/group-reporting-user/group-reporting-user.repository.d.ts +6 -6
  183. package/dist/src/components/group-reporting-user/group-reporting-user.repository.js +30 -30
  184. package/dist/src/components/group-reporting-user/index.d.ts +2 -2
  185. package/dist/src/components/group-reporting-user/index.js +18 -18
  186. package/dist/src/components/group-system-access/group-system-access.d.ts +27 -27
  187. package/dist/src/components/group-system-access/group-system-access.js +80 -80
  188. package/dist/src/components/group-system-access/group-system-access.js.map +1 -1
  189. package/dist/src/components/group-system-access/group-system-access.repository.d.ts +7 -7
  190. package/dist/src/components/group-system-access/group-system-access.repository.js +55 -54
  191. package/dist/src/components/group-system-access/group-system-access.repository.js.map +1 -1
  192. package/dist/src/components/group-system-access/index.d.ts +2 -2
  193. package/dist/src/components/group-system-access/index.js +18 -18
  194. package/dist/src/components/index.d.ts +17 -17
  195. package/dist/src/components/index.js +33 -33
  196. package/dist/src/components/login-history/index.d.ts +1 -1
  197. package/dist/src/components/login-history/index.js +17 -17
  198. package/dist/src/components/login-history/login-history.repository.d.ts +5 -5
  199. package/dist/src/components/login-history/login-history.repository.js +11 -11
  200. package/dist/src/components/login-user/index.d.ts +4 -4
  201. package/dist/src/components/login-user/index.js +20 -20
  202. package/dist/src/components/login-user/interfaces/check-user-info-duplicated.interface.d.ts +7 -7
  203. package/dist/src/components/login-user/interfaces/check-user-info-duplicated.interface.js +2 -2
  204. package/dist/src/components/login-user/interfaces/index.d.ts +1 -1
  205. package/dist/src/components/login-user/interfaces/index.js +17 -17
  206. package/dist/src/components/login-user/interfaces/system-access.interface.d.ts +13 -13
  207. package/dist/src/components/login-user/interfaces/system-access.interface.js +2 -2
  208. package/dist/src/components/login-user/interfaces/user-info.interface.d.ts +30 -30
  209. package/dist/src/components/login-user/interfaces/user-info.interface.js +2 -2
  210. package/dist/src/components/login-user/login-user.d.ts +13 -13
  211. package/dist/src/components/login-user/login-user.js +140 -140
  212. package/dist/src/components/login-user/login-user.js.map +1 -1
  213. package/dist/src/components/login-user/user.d.ts +143 -142
  214. package/dist/src/components/login-user/user.js +1791 -1767
  215. package/dist/src/components/login-user/user.js.map +1 -1
  216. package/dist/src/components/login-user/user.repository.d.ts +5 -5
  217. package/dist/src/components/login-user/user.repository.js +11 -11
  218. package/dist/src/components/password-hash/index.d.ts +2 -2
  219. package/dist/src/components/password-hash/index.js +18 -18
  220. package/dist/src/components/password-hash/interfaces/index.d.ts +1 -1
  221. package/dist/src/components/password-hash/interfaces/index.js +17 -17
  222. package/dist/src/components/password-hash/interfaces/password-hash-service.interface.d.ts +4 -4
  223. package/dist/src/components/password-hash/interfaces/password-hash-service.interface.js +2 -2
  224. package/dist/src/components/password-hash/password-hash.service.d.ts +6 -6
  225. package/dist/src/components/password-hash/password-hash.service.js +27 -27
  226. package/dist/src/components/staff/index.d.ts +1 -1
  227. package/dist/src/components/staff/index.js +17 -17
  228. package/dist/src/components/staff/staff.repository.d.ts +6 -6
  229. package/dist/src/components/staff/staff.repository.js +37 -37
  230. package/dist/src/components/staff/staff.repository.js.map +1 -1
  231. package/dist/src/components/system/index.d.ts +2 -2
  232. package/dist/src/components/system/index.js +18 -18
  233. package/dist/src/components/system/system.d.ts +39 -39
  234. package/dist/src/components/system/system.js +300 -300
  235. package/dist/src/components/system/system.js.map +1 -1
  236. package/dist/src/components/system/system.repository.d.ts +5 -5
  237. package/dist/src/components/system/system.repository.js +11 -11
  238. package/dist/src/components/system-privilege/index.d.ts +3 -3
  239. package/dist/src/components/system-privilege/index.js +7 -7
  240. package/dist/src/components/system-privilege/system-privilege.d.ts +52 -52
  241. package/dist/src/components/system-privilege/system-privilege.js +335 -335
  242. package/dist/src/components/system-privilege/system-privilege.js.map +1 -1
  243. package/dist/src/components/system-privilege/system-privilege.repository.d.ts +6 -6
  244. package/dist/src/components/system-privilege/system-privilege.repository.js +28 -28
  245. package/dist/src/components/user-group/index.d.ts +2 -2
  246. package/dist/src/components/user-group/index.js +18 -18
  247. package/dist/src/components/user-group/user-group.d.ts +50 -50
  248. package/dist/src/components/user-group/user-group.js +352 -352
  249. package/dist/src/components/user-group/user-group.js.map +1 -1
  250. package/dist/src/components/user-group/user-group.repository.d.ts +5 -5
  251. package/dist/src/components/user-group/user-group.repository.js +11 -11
  252. package/dist/src/components/user-object-privilege/index.d.ts +2 -2
  253. package/dist/src/components/user-object-privilege/index.js +18 -18
  254. package/dist/src/components/user-object-privilege/user-object-privilege.d.ts +23 -23
  255. package/dist/src/components/user-object-privilege/user-object-privilege.js +69 -69
  256. package/dist/src/components/user-object-privilege/user-object-privilege.js.map +1 -1
  257. package/dist/src/components/user-object-privilege/user-object-privilege.repository.d.ts +5 -5
  258. package/dist/src/components/user-object-privilege/user-object-privilege.repository.js +11 -11
  259. package/dist/src/components/user-privilege/index.d.ts +2 -2
  260. package/dist/src/components/user-privilege/index.js +18 -18
  261. package/dist/src/components/user-privilege/user-privilege.d.ts +64 -64
  262. package/dist/src/components/user-privilege/user-privilege.js +406 -406
  263. package/dist/src/components/user-privilege/user-privilege.js.map +1 -1
  264. package/dist/src/components/user-privilege/user-privilege.repository.d.ts +6 -6
  265. package/dist/src/components/user-privilege/user-privilege.repository.js +36 -36
  266. package/dist/src/components/user-privilege/user-privilege.repository.js.map +1 -1
  267. package/dist/src/components/user-system-access/index.d.ts +2 -2
  268. package/dist/src/components/user-system-access/index.js +18 -18
  269. package/dist/src/components/user-system-access/user-system-access.d.ts +56 -56
  270. package/dist/src/components/user-system-access/user-system-access.js +277 -277
  271. package/dist/src/components/user-system-access/user-system-access.js.map +1 -1
  272. package/dist/src/components/user-system-access/user-system-access.repository.d.ts +6 -6
  273. package/dist/src/components/user-system-access/user-system-access.repository.js +36 -36
  274. package/dist/src/components/user-system-access/user-system-access.repository.js.map +1 -1
  275. package/dist/src/database.d.ts +4 -4
  276. package/dist/src/database.js +13 -14
  277. package/dist/src/database.js.map +1 -1
  278. package/dist/src/enum/api-key.enum.d.ts +5 -5
  279. package/dist/src/enum/api-key.enum.js +9 -9
  280. package/dist/src/enum/api-key.enum.js.map +1 -1
  281. package/dist/src/enum/group-type.enum.d.ts +8 -8
  282. package/dist/src/enum/group-type.enum.js +12 -12
  283. package/dist/src/enum/group-type.enum.js.map +1 -1
  284. package/dist/src/enum/index.d.ts +6 -6
  285. package/dist/src/enum/index.js +22 -22
  286. package/dist/src/enum/login-status.enum.d.ts +4 -4
  287. package/dist/src/enum/login-status.enum.js +8 -8
  288. package/dist/src/enum/login-status.enum.js.map +1 -1
  289. package/dist/src/enum/object-status.enum.d.ts +4 -4
  290. package/dist/src/enum/object-status.enum.js +8 -8
  291. package/dist/src/enum/object-status.enum.js.map +1 -1
  292. package/dist/src/enum/user-status.enum.d.ts +7 -7
  293. package/dist/src/enum/user-status.enum.js +11 -11
  294. package/dist/src/enum/user-status.enum.js.map +1 -1
  295. package/dist/src/enum/yn.enum.d.ts +4 -4
  296. package/dist/src/enum/yn.enum.js +8 -8
  297. package/dist/src/enum/yn.enum.js.map +1 -1
  298. package/dist/src/index.d.ts +6 -6
  299. package/dist/src/index.js +24 -24
  300. package/dist/src/interfaces/api-key-attr.interface.d.ts +15 -15
  301. package/dist/src/interfaces/api-key-attr.interface.js +2 -2
  302. package/dist/src/interfaces/group-object-privilege.interface.d.ts +13 -13
  303. package/dist/src/interfaces/group-object-privilege.interface.js +2 -2
  304. package/dist/src/interfaces/group-privilege.interface.d.ts +10 -10
  305. package/dist/src/interfaces/group-privilege.interface.js +2 -2
  306. package/dist/src/interfaces/group-reporting-user.interface.d.ts +11 -11
  307. package/dist/src/interfaces/group-reporting-user.interface.js +2 -2
  308. package/dist/src/interfaces/group-search-attr.interface.d.ts +8 -8
  309. package/dist/src/interfaces/group-search-attr.interface.js +2 -2
  310. package/dist/src/interfaces/group-system-access.interface.d.ts +10 -10
  311. package/dist/src/interfaces/group-system-access.interface.js +2 -2
  312. package/dist/src/interfaces/group.interface.d.ts +16 -16
  313. package/dist/src/interfaces/group.interface.js +2 -2
  314. package/dist/src/interfaces/index.d.ts +13 -13
  315. package/dist/src/interfaces/index.js +29 -29
  316. package/dist/src/interfaces/system-login.interface.d.ts +6 -6
  317. package/dist/src/interfaces/system-login.interface.js +2 -2
  318. package/dist/src/interfaces/system-privilege-search.interface.d.ts +5 -5
  319. package/dist/src/interfaces/system-privilege-search.interface.js +2 -2
  320. package/dist/src/interfaces/system-privilege.interface.d.ts +11 -11
  321. package/dist/src/interfaces/system-privilege.interface.js +2 -2
  322. package/dist/src/interfaces/system-search-attr.interface.d.ts +5 -5
  323. package/dist/src/interfaces/system-search-attr.interface.js +2 -2
  324. package/dist/src/interfaces/system.interface.d.ts +15 -15
  325. package/dist/src/interfaces/system.interface.js +2 -2
  326. package/dist/src/interfaces/user-group.interface.d.ts +12 -12
  327. package/dist/src/interfaces/user-group.interface.js +2 -2
  328. package/dist/src/interfaces/user-object-privilege.interface.d.ts +13 -13
  329. package/dist/src/interfaces/user-object-privilege.interface.js +2 -2
  330. package/dist/src/interfaces/user-privilege.interface.d.ts +10 -10
  331. package/dist/src/interfaces/user-privilege.interface.js +2 -2
  332. package/dist/src/interfaces/user-session.interface.d.ts +4 -4
  333. package/dist/src/interfaces/user-session.interface.js +2 -2
  334. package/dist/src/interfaces/user-system-access.interface.d.ts +10 -10
  335. package/dist/src/interfaces/user-system-access.interface.js +2 -2
  336. package/dist/src/models/api-key-entity.d.ts +21 -21
  337. package/dist/src/models/api-key-entity.js +121 -121
  338. package/dist/src/models/api-key-entity.js.map +1 -1
  339. package/dist/src/models/building.entity.d.ts +29 -29
  340. package/dist/src/models/building.entity.js +212 -212
  341. package/dist/src/models/building.entity.js.map +1 -1
  342. package/dist/src/models/group-object-privilege.entity.d.ts +21 -21
  343. package/dist/src/models/group-object-privilege.entity.js +110 -110
  344. package/dist/src/models/group-object-privilege.entity.js.map +1 -1
  345. package/dist/src/models/group-privilege.entity.d.ts +18 -18
  346. package/dist/src/models/group-privilege.entity.js +95 -95
  347. package/dist/src/models/group-privilege.entity.js.map +1 -1
  348. package/dist/src/models/group-reporting-user.entity.d.ts +17 -17
  349. package/dist/src/models/group-reporting-user.entity.js +113 -113
  350. package/dist/src/models/group-reporting-user.entity.js.map +1 -1
  351. package/dist/src/models/group-system-access.entity.d.ts +18 -18
  352. package/dist/src/models/group-system-access.entity.js +98 -98
  353. package/dist/src/models/group-system-access.entity.js.map +1 -1
  354. package/dist/src/models/group.entity.d.ts +32 -32
  355. package/dist/src/models/group.entity.js +153 -154
  356. package/dist/src/models/group.entity.js.map +1 -1
  357. package/dist/src/models/login-history.entity.d.ts +14 -14
  358. package/dist/src/models/login-history.entity.js +77 -77
  359. package/dist/src/models/login-history.entity.js.map +1 -1
  360. package/dist/src/models/staff.entity.d.ts +18 -18
  361. package/dist/src/models/staff.entity.js +109 -109
  362. package/dist/src/models/staff.entity.js.map +1 -1
  363. package/dist/src/models/system-privilege.entity.d.ts +18 -18
  364. package/dist/src/models/system-privilege.entity.js +107 -107
  365. package/dist/src/models/system-privilege.entity.js.map +1 -1
  366. package/dist/src/models/system.entity.d.ts +25 -25
  367. package/dist/src/models/system.entity.js +135 -135
  368. package/dist/src/models/system.entity.js.map +1 -1
  369. package/dist/src/models/user-group.entity.d.ts +19 -19
  370. package/dist/src/models/user-group.entity.js +110 -110
  371. package/dist/src/models/user-group.entity.js.map +1 -1
  372. package/dist/src/models/user-object-privilege.entity.d.ts +20 -20
  373. package/dist/src/models/user-object-privilege.entity.js +109 -109
  374. package/dist/src/models/user-object-privilege.entity.js.map +1 -1
  375. package/dist/src/models/user-privilege.entity.d.ts +17 -17
  376. package/dist/src/models/user-privilege.entity.js +95 -95
  377. package/dist/src/models/user-privilege.entity.js.map +1 -1
  378. package/dist/src/models/user-system-access.entity.d.ts +17 -17
  379. package/dist/src/models/user-system-access.entity.js +104 -104
  380. package/dist/src/models/user-system-access.entity.js.map +1 -1
  381. package/dist/src/models/user.entity.d.ts +40 -40
  382. package/dist/src/models/user.entity.js +214 -215
  383. package/dist/src/models/user.entity.js.map +1 -1
  384. package/dist/src/redis-client/__mocks__/jest-initial-setup.d.ts +1 -1
  385. package/dist/src/redis-client/__mocks__/jest-initial-setup.js +4 -4
  386. package/dist/src/redis-client/__mocks__/redis-mock.d.ts +2 -2
  387. package/dist/src/redis-client/__mocks__/redis-mock.js +22 -22
  388. package/dist/src/redis-client/index.d.ts +1 -1
  389. package/dist/src/redis-client/index.js +17 -17
  390. package/dist/src/redis-client/redis.service.d.ts +9 -9
  391. package/dist/src/redis-client/redis.service.js +87 -87
  392. package/dist/src/redis-client/redis.service.js.map +1 -1
  393. package/dist/src/session/index.d.ts +2 -2
  394. package/dist/src/session/index.js +18 -18
  395. package/dist/src/session/interfaces/index.d.ts +1 -1
  396. package/dist/src/session/interfaces/index.js +17 -17
  397. package/dist/src/session/interfaces/session-service.interface.d.ts +9 -9
  398. package/dist/src/session/interfaces/session-service.interface.js +2 -2
  399. package/dist/src/session/session.service.d.ts +13 -13
  400. package/dist/src/session/session.service.js +95 -95
  401. package/dist/src/session/session.service.js.map +1 -1
  402. package/dist/tsconfig.tsbuildinfo +1 -1
  403. package/jest.config.js +14 -14
  404. package/migrations/20240314080602-create-user-table.js +124 -124
  405. package/migrations/20240314080603-create-user-group-table.js +85 -85
  406. package/migrations/20240314080604-create-user-user-group-table.js +55 -55
  407. package/migrations/20240314080605-create-login-history-table.js +53 -53
  408. package/migrations/20240527064925-create-system-table.js +78 -78
  409. package/migrations/20240527064926-create-system-privilege-table.js +71 -71
  410. package/migrations/20240527065342-create-group-table.js +93 -93
  411. package/migrations/20240527065633-create-group-reporting-user-table.js +76 -76
  412. package/migrations/20240528011551-create-group-system-access-table.js +72 -72
  413. package/migrations/20240528023018-user-system-access-table.js +75 -75
  414. package/migrations/20240528032229-user-privilege-table.js +76 -76
  415. package/migrations/20240528063003-create-group-privilege-table.js +76 -76
  416. package/migrations/20240528063051-create-group-object-privilege-table.js +84 -84
  417. package/migrations/20240528063107-create-user-object-privilege-table.js +84 -84
  418. package/migrations/20240528063108-create-api-key-table.js +85 -85
  419. package/migrations/20241104104802-create-building-table.js +95 -95
  420. package/package.json +88 -89
  421. package/sampledotenv +7 -7
  422. package/sonar-project.properties +22 -22
  423. package/src/components/group/group.ts +2 -3
  424. package/src/components/group-system-access/group-system-access.repository.ts +2 -3
  425. package/src/components/login-user/login-user.ts +2 -3
  426. package/src/components/login-user/user.ts +44 -6
  427. package/src/components/system-privilege/system-privilege.ts +2 -3
  428. package/src/components/user-privilege/user-privilege.ts +2 -3
  429. package/src/components/user-system-access/user-system-access.ts +2 -3
  430. package/tsconfig.build.json +5 -5
  431. package/tsconfig.json +22 -22
@@ -1,1241 +1,1241 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Group = void 0;
13
- const general_1 = require("@tomei/general");
14
- const group_repository_1 = require("./group.repository");
15
- const config_1 = require("@tomei/config");
16
- const sequelize_1 = require("sequelize");
17
- const activity_history_1 = require("@tomei/activity-history");
18
- const group_system_access_repository_1 = require("../group-system-access/group-system-access.repository");
19
- const system_entity_1 = require("../../models/system.entity");
20
- const group_system_access_1 = require("../group-system-access");
21
- const redis_service_1 = require("../../redis-client/redis.service");
22
- const system_privilege_entity_1 = require("../../models/system-privilege.entity");
23
- const group_privilege_repository_1 = require("../group-privilege/group-privilege.repository");
24
- const system_privilege_1 = require("../system-privilege/system-privilege");
25
- const group_privilege_entity_1 = require("../../models/group-privilege.entity");
26
- const group_object_privilege_repository_1 = require("../group-object-privilege/group-object-privilege.repository");
27
- const group_object_privilege_1 = require("../group-object-privilege/group-object-privilege");
28
- const group_privilege_1 = require("../group-privilege/group-privilege");
29
- const group_reporting_user_entity_1 = require("../../models/group-reporting-user.entity");
30
- const user_entity_1 = require("../../models/user.entity");
31
- class Group extends general_1.TreeNodeBase {
32
- get GroupCode() {
33
- return this.ObjectId;
34
- }
35
- set GroupCode(value) {
36
- this.ObjectId = value;
37
- }
38
- get CreatedById() {
39
- return this._CreatedById;
40
- }
41
- get CreatedAt() {
42
- return this._CreatedAt;
43
- }
44
- get UpdatedById() {
45
- return this._UpdatedById;
46
- }
47
- get UpdatedAt() {
48
- return this._UpdatedAt;
49
- }
50
- get Path() {
51
- return this._Path;
52
- }
53
- set Path(value) {
54
- this._Path = value;
55
- }
56
- constructor(groupAttr) {
57
- super();
58
- this.ObjectType = 'Group';
59
- this._Path = '';
60
- this.isChildrenLoaded = false;
61
- this.isParentLoaded = false;
62
- if (groupAttr) {
63
- this.GroupCode = groupAttr.GroupCode;
64
- this.Name = groupAttr.Name;
65
- this.Description = groupAttr === null || groupAttr === void 0 ? void 0 : groupAttr.Description;
66
- this.Type = groupAttr === null || groupAttr === void 0 ? void 0 : groupAttr.Type;
67
- this.ParentGroupCode = groupAttr === null || groupAttr === void 0 ? void 0 : groupAttr.ParentGroupCode;
68
- this.InheritParentPrivilegeYN = groupAttr === null || groupAttr === void 0 ? void 0 : groupAttr.InheritParentPrivilegeYN;
69
- this.InheritParentSystemAccessYN = groupAttr === null || groupAttr === void 0 ? void 0 : groupAttr.InheritParentSystemAccessYN;
70
- this.Status = groupAttr === null || groupAttr === void 0 ? void 0 : groupAttr.Status;
71
- this._Path = groupAttr === null || groupAttr === void 0 ? void 0 : groupAttr.Path;
72
- this._CreatedById = groupAttr.CreatedById;
73
- this._CreatedAt = groupAttr.CreatedAt;
74
- this._UpdatedById = groupAttr.UpdatedById;
75
- this._UpdatedAt = groupAttr.UpdatedAt;
76
- }
77
- }
78
- static init(dbTransaction, GroupCode) {
79
- return __awaiter(this, void 0, void 0, function* () {
80
- try {
81
- Group._RedisService = yield redis_service_1.RedisService.init();
82
- if (GroupCode) {
83
- const group = yield Group._Repo.findByPk(GroupCode, {
84
- transaction: dbTransaction,
85
- });
86
- if (group) {
87
- return new Group(group);
88
- }
89
- else {
90
- throw Error('Group not found');
91
- }
92
- }
93
- return new Group();
94
- }
95
- catch (error) {
96
- throw new general_1.ClassError('Group', 'GroupErrMsg01', 'Failed To Initialize Group');
97
- }
98
- });
99
- }
100
- loadChildren(dbTransaction) {
101
- return __awaiter(this, void 0, void 0, function* () {
102
- if (!this.GroupCode) {
103
- throw Error('GroupCode is missing.');
104
- }
105
- const children = yield Group._Repo.findAll({
106
- where: { ParentGroupCode: this.GroupCode },
107
- order: [['CreatedAt', 'ASC']],
108
- transaction: dbTransaction,
109
- });
110
- this.children = children.map((child) => {
111
- return new Group(child.get({ plain: true }));
112
- });
113
- this.isChildrenLoaded = true;
114
- });
115
- }
116
- loadParent(dbTransaction) {
117
- return __awaiter(this, void 0, void 0, function* () {
118
- if (!this.GroupCode) {
119
- throw Error('GroupCode are missing.');
120
- }
121
- if (this.ParentGroupCode) {
122
- if (this.ParentGroupCode !== this.GroupCode) {
123
- const parent = yield Group._Repo.findByPk(this.ParentGroupCode, {
124
- transaction: dbTransaction,
125
- });
126
- this.parent = new Group(parent.get({ plain: true }));
127
- }
128
- }
129
- this.isParentLoaded = true;
130
- });
131
- }
132
- isLeaf(dbTransaction) {
133
- return __awaiter(this, void 0, void 0, function* () {
134
- if (!this.isChildrenLoaded) {
135
- yield this.loadChildren(dbTransaction);
136
- }
137
- return this.children.length === 0;
138
- });
139
- }
140
- getPath(dbTransaction) {
141
- return __awaiter(this, void 0, void 0, function* () {
142
- if (!this.isParentLoaded) {
143
- yield this.loadParent(dbTransaction);
144
- }
145
- if (this.parent) {
146
- this._Path =
147
- (yield this.parent.getPath(dbTransaction)) + '/' + this.GroupCode;
148
- return this._Path;
149
- }
150
- this._Path = this.GroupCode;
151
- return this._Path;
152
- });
153
- }
154
- updatePath(dbTransaction) {
155
- return __awaiter(this, void 0, void 0, function* () {
156
- const path = yield this.getPath(dbTransaction);
157
- this._Path = path;
158
- });
159
- }
160
- setParent(parent, dbTransaction) {
161
- return __awaiter(this, void 0, void 0, function* () {
162
- this.parent = parent;
163
- yield this.updatePath(dbTransaction);
164
- });
165
- }
166
- getPathDetail(dbTransaction) {
167
- return __awaiter(this, void 0, void 0, function* () {
168
- const path = this._Path.split('/');
169
- const groups = [];
170
- for (let i = 0; i < path.length; i++) {
171
- const group = yield Group.init(dbTransaction, path[i]);
172
- groups.push(group);
173
- }
174
- return groups;
175
- });
176
- }
177
- static findAll(page, row, dbTransaction, loginUser, search) {
178
- return __awaiter(this, void 0, void 0, function* () {
179
- const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
180
- const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'GROUP_LIST');
181
- if (!isPrivileged) {
182
- throw new general_1.ClassError('Group', 'GroupErrMsg04', 'User is not privileged to list group');
183
- }
184
- const queryObj = {};
185
- let options = {
186
- transaction: dbTransaction,
187
- };
188
- if (page && row) {
189
- options = Object.assign(Object.assign({}, options), { limit: row, offset: row * (page - 1), order: [['CreatedAt', 'DESC']] });
190
- }
191
- if (search) {
192
- Object.entries(search).forEach(([key, value]) => {
193
- queryObj[key] = {
194
- [sequelize_1.Op.substring]: value,
195
- };
196
- });
197
- options = Object.assign(Object.assign({}, options), { where: queryObj });
198
- const result = yield Group._Repo.findAllWithPagination(options);
199
- return {
200
- Count: result.count,
201
- Groups: result.rows.map((group) => new Group(group.get({ plain: true }))),
202
- };
203
- }
204
- });
205
- }
206
- static create(loginUser, dbTransaction, group) {
207
- return __awaiter(this, void 0, void 0, function* () {
208
- try {
209
- const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
210
- const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'GROUP_CREATE');
211
- if (!isPrivileged) {
212
- throw new Error('You do not have permission to create group');
213
- }
214
- if (!group.GroupCode) {
215
- throw new general_1.ClassError('Group', 'GroupErrMsg02', 'Group Code is required');
216
- }
217
- if (!group.Name) {
218
- throw new general_1.ClassError('Group', 'GroupErrMsg02', 'Group Name is required');
219
- }
220
- if (!group.Type) {
221
- throw new general_1.ClassError('Group', 'GroupErrMsg02', 'Group Type is required');
222
- }
223
- const existingGroupCode = yield Group._Repo.findByPk(group.GroupCode, {
224
- transaction: dbTransaction,
225
- });
226
- if (existingGroupCode) {
227
- throw new general_1.ClassError('Group', 'GroupErrMsg03', 'Duplicate GroupCode found.');
228
- }
229
- if (group.ParentGroupCode) {
230
- const parentGroup = yield Group._Repo.findByPk(group.ParentGroupCode, {
231
- transaction: dbTransaction,
232
- });
233
- if (!parentGroup) {
234
- throw new general_1.ClassError('Group', 'GroupErrMsg04', 'ParentGroupCode is not found.');
235
- }
236
- if (group.GroupCode === group.ParentGroupCode) {
237
- throw new general_1.ClassError('Group', 'GroupErrMsg05', 'GroupCode and ParentGroupCode cannot be the same.');
238
- }
239
- }
240
- const newGroup = new Group(group);
241
- newGroup.ObjectId = group.GroupCode;
242
- newGroup.Name = group.Name;
243
- newGroup.Type = group.Type;
244
- newGroup.Description = group.Description;
245
- newGroup.ParentGroupCode = group.ParentGroupCode;
246
- newGroup.InheritParentPrivilegeYN = group.InheritParentPrivilegeYN;
247
- newGroup.InheritParentSystemAccessYN = group.InheritParentSystemAccessYN;
248
- newGroup.Status = 'Active';
249
- newGroup._CreatedById = loginUser.UserId;
250
- newGroup._UpdatedById = loginUser.UserId;
251
- newGroup._Path = yield newGroup.getPath(dbTransaction);
252
- const entityGroupAfter = {
253
- GroupCode: newGroup.ObjectId,
254
- Name: newGroup.Name,
255
- Type: newGroup.Type,
256
- Description: newGroup.Description,
257
- ParentGroupCode: newGroup.ParentGroupCode,
258
- InheritParentPrivilegeYN: newGroup.InheritParentPrivilegeYN,
259
- InheritParentSystemAccessYN: newGroup.InheritParentSystemAccessYN,
260
- Path: newGroup._Path,
261
- Status: newGroup.Status,
262
- CreatedById: newGroup._CreatedById,
263
- UpdatedById: newGroup._UpdatedById,
264
- CreatedAt: newGroup._CreatedAt,
265
- UpdatedAt: newGroup._UpdatedAt,
266
- };
267
- yield Group._Repo.create(entityGroupAfter, {
268
- transaction: dbTransaction,
269
- });
270
- const entityValueBefore = {};
271
- const activity = new activity_history_1.Activity();
272
- activity.ActivityId = activity.createId();
273
- activity.Action = activity_history_1.ActionEnum.CREATE;
274
- activity.Description = 'Create Group';
275
- activity.EntityType = 'Group';
276
- activity.EntityId = newGroup.ObjectId;
277
- activity.EntityValueBefore = JSON.stringify(entityValueBefore);
278
- activity.EntityValueAfter = JSON.stringify(entityGroupAfter);
279
- yield activity.create(loginUser.ObjectId, dbTransaction);
280
- return newGroup;
281
- }
282
- catch (error) {
283
- throw error;
284
- }
285
- });
286
- }
287
- static checkDuplicateGroupCode(dbTransaction, GroupCode) {
288
- return __awaiter(this, void 0, void 0, function* () {
289
- const isGroupCodeExist = yield Group._Repo.findOne({
290
- where: { GroupCode },
291
- transaction: dbTransaction,
292
- });
293
- if (isGroupCodeExist) {
294
- throw new general_1.ClassError('Group', 'GroupErrMsg07', 'GroupCode already exists.');
295
- }
296
- });
297
- }
298
- updateChildrenPath(oldGroupCode, dbTransaction) {
299
- return __awaiter(this, void 0, void 0, function* () {
300
- try {
301
- const isLeaf = yield this.isLeaf(dbTransaction);
302
- if (isLeaf) {
303
- return;
304
- }
305
- const childrens = yield Group._Repo.findAll({
306
- where: {
307
- Path: {
308
- [sequelize_1.Op.like]: `${oldGroupCode}/%`,
309
- },
310
- },
311
- transaction: dbTransaction,
312
- });
313
- childrens.forEach((children) => __awaiter(this, void 0, void 0, function* () {
314
- const path = children.Path.split(`${oldGroupCode}/`);
315
- const childPath = path[1];
316
- yield children.update({ Path: `${this._Path}/${childPath}` }, { transaction: dbTransaction });
317
- }));
318
- }
319
- catch (error) {
320
- throw error;
321
- }
322
- });
323
- }
324
- update(loginUser, dbTransaction, group) {
325
- return __awaiter(this, void 0, void 0, function* () {
326
- const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
327
- const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'GROUP_UPDATE');
328
- if (!isPrivileged) {
329
- throw new general_1.ClassError('Group', 'GroupErrMsg06', 'You do not have the privilege to update Group');
330
- }
331
- try {
332
- if (group.NewGroupCode) {
333
- yield Group.checkDuplicateGroupCode(dbTransaction, group.NewGroupCode);
334
- }
335
- const entityValueBefore = {
336
- GroupCode: this.GroupCode,
337
- Name: this.Name,
338
- Type: this.Type,
339
- Description: this.Description,
340
- ParentGroupCode: this.ParentGroupCode,
341
- InheritParentPrivilegeYN: this.InheritParentPrivilegeYN,
342
- InheritParentSystemAccessYN: this.InheritParentSystemAccessYN,
343
- Path: this.Path,
344
- Status: this.Status,
345
- CreatedById: this._CreatedById,
346
- UpdatedById: this._UpdatedById,
347
- CreatedAt: this._CreatedAt,
348
- UpdatedAt: this._UpdatedAt,
349
- };
350
- let isPathChanged = false;
351
- const oldGroupCode = this.GroupCode;
352
- if (group.NewGroupCode) {
353
- this.GroupCode = group.NewGroupCode;
354
- isPathChanged = true;
355
- }
356
- if ((group.ParentGroupCode &&
357
- this.ParentGroupCode !== group.ParentGroupCode) ||
358
- (group.ParentGroupCode && !this.ParentGroupCode)) {
359
- const parentGroup = yield Group.init(dbTransaction, group.ParentGroupCode);
360
- if (!parentGroup) {
361
- throw new general_1.ClassError('Group', 'GroupErrMsg08', 'Parent Group Code not found');
362
- }
363
- yield this.setParent(parentGroup);
364
- isPathChanged = true;
365
- }
366
- else if (!group.ParentGroupCode && this.ParentGroupCode) {
367
- yield this.setParent(null);
368
- isPathChanged = true;
369
- }
370
- if (isPathChanged) {
371
- yield this.updateChildrenPath(oldGroupCode, dbTransaction);
372
- }
373
- this.Name = (group === null || group === void 0 ? void 0 : group.Name) || this.Name;
374
- this.Type = (group === null || group === void 0 ? void 0 : group.Type) || this.Type;
375
- this.Description = (group === null || group === void 0 ? void 0 : group.Description) || this.Description;
376
- this.ParentGroupCode = (group === null || group === void 0 ? void 0 : group.ParentGroupCode) || this.ParentGroupCode;
377
- this.InheritParentPrivilegeYN =
378
- (group === null || group === void 0 ? void 0 : group.InheritParentPrivilegeYN) || this.InheritParentPrivilegeYN;
379
- this.InheritParentSystemAccessYN =
380
- (group === null || group === void 0 ? void 0 : group.InheritParentSystemAccessYN) || this.InheritParentSystemAccessYN;
381
- this.Status = (group === null || group === void 0 ? void 0 : group.Status) || this.Status;
382
- this._UpdatedById = loginUser.UserId;
383
- this._UpdatedAt = new Date();
384
- yield Group._Repo.update({
385
- GroupCode: this.GroupCode,
386
- Name: this.Name,
387
- Type: this.Type,
388
- Description: this.Description,
389
- ParentGroupCode: this.ParentGroupCode,
390
- InheritParentPrivilegeYN: this.InheritParentPrivilegeYN,
391
- InheritParentSystemAccessYN: this.InheritParentSystemAccessYN,
392
- Status: this.Status,
393
- Path: this._Path,
394
- UpdatedById: this._UpdatedById,
395
- UpdatedAt: this._UpdatedAt,
396
- }, {
397
- where: {
398
- GroupCode: group.GroupCode,
399
- },
400
- transaction: dbTransaction,
401
- });
402
- const entityValueAfter = {
403
- GroupCode: this.GroupCode,
404
- Name: this.Name,
405
- Type: this.Type,
406
- Description: this.Description,
407
- ParentGroupCode: this.ParentGroupCode,
408
- InheritParentPrivilegeYN: this.InheritParentPrivilegeYN,
409
- InheritParentSystemAccessYN: this.InheritParentSystemAccessYN,
410
- Status: this.Status,
411
- Path: this._Path,
412
- CreatedById: this._CreatedById,
413
- UpdatedById: this._UpdatedById,
414
- CreatedAt: this._CreatedAt,
415
- UpdatedAt: this._UpdatedAt,
416
- };
417
- const activity = new activity_history_1.Activity();
418
- activity.ActivityId = activity.createId();
419
- activity.Action = activity_history_1.ActionEnum.UPDATE;
420
- activity.Description = `Update Group ${group.Type}`;
421
- activity.EntityType = 'Group';
422
- activity.EntityId = group.GroupCode;
423
- activity.EntityValueBefore = JSON.stringify(entityValueBefore);
424
- activity.EntityValueAfter = JSON.stringify(entityValueAfter);
425
- yield activity.create(loginUser.ObjectId, dbTransaction);
426
- return this;
427
- }
428
- catch (error) {
429
- throw error;
430
- }
431
- });
432
- }
433
- static delete(loginUser, dbTransaction, GroupCode) {
434
- return __awaiter(this, void 0, void 0, function* () {
435
- const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
436
- const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'GROUP_DELETE');
437
- if (!isPrivileged) {
438
- throw new general_1.ClassError('Group', 'GroupErrMsg03', 'You do not have the privilege to delete groups records.');
439
- }
440
- try {
441
- const group = yield Group.init(dbTransaction, GroupCode);
442
- if (group.Status === 'Active') {
443
- throw new general_1.ClassError('Group', 'GroupErrMsg03', 'Active Group cant be deleted');
444
- }
445
- const relatedGroup = yield Group.findAll(1, Number.MAX_SAFE_INTEGER, dbTransaction, loginUser, {
446
- ParentGroupCode: GroupCode,
447
- });
448
- if (relatedGroup.Count > 0) {
449
- const listOfRelatedGroup = relatedGroup.Groups.map((group) => {
450
- return group.GroupCode;
451
- });
452
- throw new general_1.ClassError('Group', 'GroupErrMsg03', `Group still has associated user group ${listOfRelatedGroup}`);
453
- }
454
- yield Group._Repo.delete(GroupCode, dbTransaction);
455
- const EntityValueBefore = {
456
- GroupCode: group.GroupCode,
457
- Name: group.Name,
458
- Type: group.Type,
459
- Description: group.Description,
460
- ParentGroupCode: group.ParentGroupCode,
461
- InheritParentPrivilegeYN: group.InheritParentPrivilegeYN,
462
- InheritParentSystemAccessYN: group.InheritParentSystemAccessYN,
463
- Status: group.Status,
464
- CreatedById: group._CreatedById,
465
- UpdatedById: group._UpdatedById,
466
- CreatedAt: group._CreatedAt,
467
- UpdatedAt: group._UpdatedAt,
468
- };
469
- const activity = new activity_history_1.Activity();
470
- activity.ActivityId = activity.createId();
471
- activity.Action = activity_history_1.ActionEnum.DELETE;
472
- activity.Description = 'Delete Group';
473
- activity.EntityType = 'Group';
474
- activity.EntityId = group.ObjectId;
475
- activity.EntityValueBefore = JSON.stringify(EntityValueBefore);
476
- activity.EntityValueAfter = JSON.stringify({});
477
- yield activity.create(loginUser.ObjectId, dbTransaction);
478
- return { Message: 'Group removed.' };
479
- }
480
- catch (error) {
481
- throw error;
482
- }
483
- });
484
- }
485
- static getSystemAccesses(loginUser, dbTransaction, GroupCode, Page, Rows, Search) {
486
- return __awaiter(this, void 0, void 0, function* () {
487
- const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
488
- const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'SYSTEM_ACCESS_VIEW');
489
- if (!isPrivileged) {
490
- throw new general_1.ClassError('Group', 'GroupErrMsg06', 'You do not have the privilege to view system access');
491
- }
492
- try {
493
- yield Group.init(dbTransaction, GroupCode);
494
- const queryObj = { GroupCode: GroupCode };
495
- if (Search) {
496
- Object.entries(Search).forEach(([key, value]) => {
497
- queryObj[key] = value;
498
- });
499
- }
500
- let options = {
501
- where: queryObj,
502
- distinct: true,
503
- transaction: dbTransaction,
504
- };
505
- if (Page && Rows) {
506
- options = Object.assign(Object.assign({}, options), { limit: Rows, offset: Rows * (Page - 1), order: [['CreatedAt', 'DESC']] });
507
- }
508
- const systemAccess = yield Group._GroupSystemAccessRepo.findAndCountAll(options);
509
- return systemAccess;
510
- }
511
- catch (error) {
512
- return error;
513
- }
514
- });
515
- }
516
- static getInheritedSystemAccess(dbTransaction, group) {
517
- return __awaiter(this, void 0, void 0, function* () {
518
- const options = {
519
- where: {
520
- GroupCode: group.GroupCode,
521
- Status: 'Active',
522
- },
523
- include: [
524
- {
525
- model: system_entity_1.default,
526
- },
527
- ],
528
- transaction: dbTransaction,
529
- };
530
- let systemAccess = yield Group._GroupSystemAccessRepo.findAll(options);
531
- if (group.InheritParentSystemAccessYN === 'Y' && group.ParentGroupCode) {
532
- const parentGroup = yield Group.init(dbTransaction, group.ParentGroupCode);
533
- const parentSystemAccesses = yield this.getInheritedSystemAccess(dbTransaction, parentGroup);
534
- systemAccess = systemAccess.concat(parentSystemAccesses);
535
- }
536
- return systemAccess;
537
- });
538
- }
539
- static isGroupCodeInHierarchy(dbTransaction, GroupCode, ListGroupCode = []) {
540
- return __awaiter(this, void 0, void 0, function* () {
541
- ListGroupCode.push(GroupCode);
542
- const group = yield Group._Repo.findOne({
543
- where: { GroupCode },
544
- transaction: dbTransaction,
545
- });
546
- if (group === null || group === void 0 ? void 0 : group.ParentGroupCode) {
547
- const isGroupCodeExist = ListGroupCode.includes(group.ParentGroupCode);
548
- if (!isGroupCodeExist) {
549
- yield this.isGroupCodeInHierarchy(dbTransaction, group.ParentGroupCode, ListGroupCode);
550
- }
551
- {
552
- return false;
553
- }
554
- }
555
- else {
556
- return true;
557
- }
558
- });
559
- }
560
- static getParentSystemAccesses(loginUser, dbTransaction, GroupCode) {
561
- return __awaiter(this, void 0, void 0, function* () {
562
- const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
563
- const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'SYSTEM_ACCESS_VIEW');
564
- if (!isPrivileged) {
565
- throw new general_1.ClassError('Group', 'GroupErrMsg06', 'You do not have the privilege to view system access');
566
- }
567
- try {
568
- const group = yield Group.init(dbTransaction, GroupCode);
569
- if (group.InheritParentSystemAccessYN !== 'Y' || !group.ParentGroupCode) {
570
- return [];
571
- }
572
- else {
573
- const parentGroup = yield Group.init(dbTransaction, group.ParentGroupCode);
574
- const inheritSystemAccess = yield Group.getInheritedSystemAccess(dbTransaction, parentGroup);
575
- return inheritSystemAccess;
576
- }
577
- }
578
- catch (error) {
579
- throw error;
580
- }
581
- });
582
- }
583
- static addSystemAccesses(loginUser, dbTransaction, GroupCode, SystemCodes) {
584
- var _a;
585
- return __awaiter(this, void 0, void 0, function* () {
586
- const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
587
- const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'SYSTEM_ACCESS_CREATE');
588
- if (!isPrivileged) {
589
- throw new general_1.ClassError('Group', 'GroupErrMsg07', 'You do not have the privilege to create system access');
590
- }
591
- try {
592
- if (SystemCodes.length > 0) {
593
- for (const element of SystemCodes) {
594
- const CurrentGroupSystemAccess = yield Group.getSystemAccesses(loginUser, dbTransaction, GroupCode, 1, Number.MAX_SAFE_INTEGER, { SystemCode: element });
595
- if ((CurrentGroupSystemAccess === null || CurrentGroupSystemAccess === void 0 ? void 0 : CurrentGroupSystemAccess.count) > 0) {
596
- throw new general_1.ClassError('Group', 'GroupErrMsg08', 'System access already exists');
597
- }
598
- const groupSystemAccess = yield group_system_access_1.GroupSystemAccess.init(dbTransaction);
599
- groupSystemAccess.createId();
600
- groupSystemAccess.GroupCode = GroupCode;
601
- groupSystemAccess.SystemCode = element;
602
- groupSystemAccess.Status = 'Active';
603
- groupSystemAccess.CreatedById = +loginUser.ObjectId;
604
- groupSystemAccess.CreatedAt = new Date();
605
- groupSystemAccess.UpdatedById = +loginUser.ObjectId;
606
- groupSystemAccess.UpdatedAt = new Date();
607
- const EntityValueAfter = {
608
- GroupCode: groupSystemAccess.GroupCode,
609
- SystemCode: groupSystemAccess.SystemCode,
610
- Status: groupSystemAccess.Status,
611
- CreatedById: groupSystemAccess.CreatedById,
612
- CreatedAt: groupSystemAccess.CreatedAt,
613
- UpdatedById: groupSystemAccess.UpdatedById,
614
- UpdatedAt: groupSystemAccess.UpdatedAt,
615
- };
616
- const systemAccess = yield Group._GroupSystemAccessRepo.create(EntityValueAfter, {
617
- transaction: dbTransaction,
618
- });
619
- const activity = new activity_history_1.Activity();
620
- activity.ActivityId = activity.createId();
621
- activity.Action = activity_history_1.ActionEnum.CREATE;
622
- activity.Description = 'Create Group System Access';
623
- activity.EntityType = 'GroupSystemAccess';
624
- activity.EntityId = (_a = systemAccess.GroupSystemAccessId) === null || _a === void 0 ? void 0 : _a.toString();
625
- activity.EntityValueBefore = JSON.stringify({});
626
- activity.EntityValueAfter = JSON.stringify(EntityValueAfter);
627
- yield activity.create(loginUser.ObjectId, dbTransaction);
628
- }
629
- return { Message: 'Successfully added.' };
630
- }
631
- }
632
- catch (error) {
633
- throw error;
634
- }
635
- });
636
- }
637
- static deleteSystemAccess(loginUser, dbTransaction, GroupCode, SystemCode) {
638
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
639
- return __awaiter(this, void 0, void 0, function* () {
640
- const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
641
- const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'SYSTEM_ACCESS_DELETE');
642
- if (!isPrivileged) {
643
- throw new general_1.ClassError('Group', 'GroupErrMsg08', 'You do not have the privilege to delete system access');
644
- }
645
- try {
646
- const currentGroupSystemAccess = yield Group.getSystemAccesses(loginUser, dbTransaction, GroupCode, 1, Number.MAX_SAFE_INTEGER, { SystemCode: SystemCode });
647
- if (currentGroupSystemAccess.count < 1) {
648
- throw new general_1.ClassError('Group', 'GroupErrMsg10', 'No associated system access found.');
649
- }
650
- yield Group._GroupSystemAccessRepo.delete(GroupCode, SystemCode, dbTransaction);
651
- const EntityValueBefore = {
652
- GroupCode: (_a = currentGroupSystemAccess === null || currentGroupSystemAccess === void 0 ? void 0 : currentGroupSystemAccess.rows[0]) === null || _a === void 0 ? void 0 : _a.GroupCode,
653
- SystemCode: (_b = currentGroupSystemAccess === null || currentGroupSystemAccess === void 0 ? void 0 : currentGroupSystemAccess.rows[0]) === null || _b === void 0 ? void 0 : _b.SystemCode,
654
- Status: (_c = currentGroupSystemAccess === null || currentGroupSystemAccess === void 0 ? void 0 : currentGroupSystemAccess.rows[0]) === null || _c === void 0 ? void 0 : _c.Status,
655
- CreatedById: (_d = currentGroupSystemAccess === null || currentGroupSystemAccess === void 0 ? void 0 : currentGroupSystemAccess.rows[0]) === null || _d === void 0 ? void 0 : _d.CreatedById,
656
- CreatedAt: (_e = currentGroupSystemAccess === null || currentGroupSystemAccess === void 0 ? void 0 : currentGroupSystemAccess.rows[0]) === null || _e === void 0 ? void 0 : _e.CreatedAt,
657
- UpdatedById: (_f = currentGroupSystemAccess === null || currentGroupSystemAccess === void 0 ? void 0 : currentGroupSystemAccess.rows[0]) === null || _f === void 0 ? void 0 : _f.UpdatedById,
658
- UpdatedAt: (_g = currentGroupSystemAccess === null || currentGroupSystemAccess === void 0 ? void 0 : currentGroupSystemAccess.rows[0]) === null || _g === void 0 ? void 0 : _g.UpdatedAt,
659
- };
660
- const activity = new activity_history_1.Activity();
661
- activity.ActivityId = activity.createId();
662
- activity.Action = activity_history_1.ActionEnum.DELETE;
663
- activity.Description = 'Delete Group System Access';
664
- activity.EntityType = 'GroupSystemAccess';
665
- activity.EntityId =
666
- (_j = (_h = currentGroupSystemAccess === null || currentGroupSystemAccess === void 0 ? void 0 : currentGroupSystemAccess.rows[0]) === null || _h === void 0 ? void 0 : _h.GroupSystemAccessId) === null || _j === void 0 ? void 0 : _j.toString();
667
- activity.EntityValueBefore = JSON.stringify(EntityValueBefore);
668
- activity.EntityValueAfter = JSON.stringify({});
669
- yield activity.create(loginUser.ObjectId, dbTransaction);
670
- return { Message: 'System access removed.', SystemCode: SystemCode };
671
- }
672
- catch (error) {
673
- throw error;
674
- }
675
- });
676
- }
677
- static getSystemPrivileges(loginUser, dbTransaction, GroupCode, search) {
678
- return __awaiter(this, void 0, void 0, function* () {
679
- try {
680
- const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
681
- const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'GROUP_PRIVILEGE_VIEW');
682
- if (!isPrivileged) {
683
- throw new general_1.ClassError('Group', 'GroupErrMsg11', 'You do not have the privilege to view group privileges');
684
- }
685
- yield Group.init(dbTransaction, GroupCode);
686
- let where = {
687
- GroupCode,
688
- };
689
- let systemWhere = {};
690
- if (search) {
691
- if (search.Status) {
692
- where = Object.assign(Object.assign({}, where), { Status: search.Status });
693
- }
694
- if (search.SystemCode) {
695
- systemWhere = {
696
- SystemCode: {
697
- [sequelize_1.Op.substring]: search.SystemCode,
698
- },
699
- };
700
- }
701
- }
702
- const groupOwnPrivileges = yield Group._GroupPrivilegeRepo.findAll({
703
- where,
704
- include: [
705
- {
706
- model: system_privilege_entity_1.default,
707
- where: systemWhere,
708
- },
709
- ],
710
- transaction: dbTransaction,
711
- });
712
- const privileges = [];
713
- for (const groupPrivilege of groupOwnPrivileges) {
714
- const systemPrivilege = yield system_privilege_1.SystemPrivilege.init(dbTransaction);
715
- systemPrivilege.setAttributes(groupPrivilege.Privilege.get({ plain: true }));
716
- privileges.push(systemPrivilege);
717
- }
718
- return privileges;
719
- }
720
- catch (error) {
721
- throw error;
722
- }
723
- });
724
- }
725
- static getInheritedSystemPrivileges(dbTransaction, GroupCode, search) {
726
- return __awaiter(this, void 0, void 0, function* () {
727
- try {
728
- const where = {
729
- GroupCode,
730
- };
731
- let groupPrivilegeWhere = {};
732
- let systemPrivilegeWhere = {};
733
- if (search) {
734
- if (search.Status) {
735
- groupPrivilegeWhere = {
736
- Status: search.Status,
737
- };
738
- }
739
- if (search.SystemCode) {
740
- systemPrivilegeWhere = {
741
- SystemCode: {
742
- [sequelize_1.Op.substring]: search.SystemCode,
743
- },
744
- };
745
- }
746
- if (search.PrivilegeCode) {
747
- systemPrivilegeWhere = Object.assign(Object.assign({}, systemPrivilegeWhere), { PrivilegeCode: {
748
- [sequelize_1.Op.substring]: search.PrivilegeCode,
749
- } });
750
- }
751
- }
752
- const group = yield Group._Repo.findOne({
753
- where: where,
754
- include: [
755
- {
756
- model: group_privilege_entity_1.default,
757
- where: groupPrivilegeWhere,
758
- separate: true,
759
- include: [
760
- {
761
- model: system_privilege_entity_1.default,
762
- where: systemPrivilegeWhere,
763
- },
764
- ],
765
- },
766
- ],
767
- transaction: dbTransaction,
768
- });
769
- const objectWhere = {
770
- GroupCode,
771
- };
772
- const systemWhere = {};
773
- if (search) {
774
- Object.entries(search).forEach(([key, value]) => {
775
- if (key === 'Status') {
776
- objectWhere[key] = {
777
- [sequelize_1.Op.substring]: value,
778
- };
779
- }
780
- else {
781
- systemWhere[key] = {
782
- [sequelize_1.Op.substring]: value,
783
- };
784
- }
785
- });
786
- }
787
- const groupObjectPrivileges = yield Group._GroupObjectPrivilegeRepo.findAll({
788
- where: objectWhere,
789
- include: [
790
- {
791
- model: system_privilege_entity_1.default,
792
- where: systemWhere,
793
- },
794
- ],
795
- transaction: dbTransaction,
796
- });
797
- let privileges = [];
798
- for (const groupPrivilege of group.GroupPrivileges) {
799
- const systemPrivilege = yield system_privilege_1.SystemPrivilege.init(dbTransaction);
800
- systemPrivilege.setAttributes(groupPrivilege.Privilege.get({ plain: true }));
801
- privileges.push(systemPrivilege);
802
- }
803
- for (const groupObjectPrivilege of groupObjectPrivileges) {
804
- const systemPrivilege = yield system_privilege_1.SystemPrivilege.init(dbTransaction);
805
- systemPrivilege.setAttributes(groupObjectPrivilege.Privilege.get({ plain: true }));
806
- privileges.push(systemPrivilege);
807
- }
808
- if (group.InheritParentPrivilegeYN === 'Y' && group.ParentGroupCode) {
809
- const inheritedPrivileges = yield Group.getInheritedSystemPrivileges(dbTransaction, group.ParentGroupCode, search);
810
- privileges = privileges.concat(inheritedPrivileges);
811
- }
812
- const uniquePrivileges = Array.from(new Set(privileges.map((a) => a.SystemPrivilegeId))).map((SystemPrivilegeId) => {
813
- return privileges.find((a) => a.SystemPrivilegeId === SystemPrivilegeId);
814
- });
815
- return uniquePrivileges;
816
- }
817
- catch (error) {
818
- throw error;
819
- }
820
- });
821
- }
822
- static getParentSystemPrivileges(loginUser, dbTransaction, GroupCode, search) {
823
- return __awaiter(this, void 0, void 0, function* () {
824
- try {
825
- const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
826
- const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'GROUP_PRIVILEGE_VIEW');
827
- if (!isPrivileged) {
828
- throw new general_1.ClassError('Group', 'GroupErrMsg11', 'You do not have the privilege to view group privileges');
829
- }
830
- const group = yield Group.init(dbTransaction, GroupCode);
831
- if (group.InheritParentPrivilegeYN !== 'Y' || !group.ParentGroupCode) {
832
- return [];
833
- }
834
- const privileges = yield Group.getInheritedSystemPrivileges(dbTransaction, group.ParentGroupCode, search);
835
- return privileges;
836
- }
837
- catch (error) {
838
- throw error;
839
- }
840
- });
841
- }
842
- static assignGroupObjectPrivilege(loginUser, dbTransaction, GroupCode, GroupObjectPrivileges, SystemCode) {
843
- return __awaiter(this, void 0, void 0, function* () {
844
- try {
845
- const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
846
- const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'GROUP_OBJECT_PRIVILEGE_ASSIGN');
847
- if (!isPrivileged) {
848
- throw new general_1.ClassError('Group', 'GroupErrMsg12', 'You do not have the privilege to assign group object privilege');
849
- }
850
- const group = yield Group.init(dbTransaction, GroupCode);
851
- const groupSystemAccesses = yield Group.getSystemAccesses(loginUser, dbTransaction, GroupCode, 1, Number.MAX_SAFE_INTEGER, {});
852
- let parentGroupSystemAccesses = {
853
- rows: [],
854
- count: 0,
855
- };
856
- if (group.InheritParentSystemAccessYN === 'Y' && group.ParentGroupCode) {
857
- parentGroupSystemAccesses = yield Group.getSystemAccesses(loginUser, dbTransaction, group.ParentGroupCode, 1, Number.MAX_SAFE_INTEGER, undefined);
858
- }
859
- for (const groupObjectPrivilege of GroupObjectPrivileges) {
860
- const systemPrivilege = yield system_privilege_1.SystemPrivilege.init(dbTransaction, groupObjectPrivilege.SystemPrivilegeId);
861
- const combinedSystemAccesses = Object.assign(Object.assign({}, groupSystemAccesses.rows), parentGroupSystemAccesses.rows);
862
- const systemAccess = combinedSystemAccesses.find((systemAccess) => systemAccess.SystemCode === systemPrivilege.SystemCode);
863
- if (!systemAccess) {
864
- throw new general_1.ClassError('Group', 'GroupErrMsg13', 'Failed to assign privilege ' +
865
- groupObjectPrivilege.SystemPrivilegeId +
866
- ' due to non-existent system access.');
867
- }
868
- const groupObjectPrivilegeData = yield Group._GroupObjectPrivilegeRepo.findOne({
869
- where: {
870
- GroupCode,
871
- SystemPrivilegeId: groupObjectPrivilege.SystemPrivilegeId,
872
- ObjectId: groupObjectPrivilege.ObjectId,
873
- ObjectType: groupObjectPrivilege.ObjectType,
874
- },
875
- transaction: dbTransaction,
876
- });
877
- if (groupObjectPrivilegeData) {
878
- continue;
879
- }
880
- else {
881
- yield group_object_privilege_1.GroupObjectPrivilege.create(loginUser, dbTransaction, groupObjectPrivilege);
882
- }
883
- }
884
- return 'Successfully added.';
885
- }
886
- catch (error) {
887
- throw error;
888
- }
889
- });
890
- }
891
- static getGroubObjectPrivileges(loginUser, dbTransaction, GroupCode, search) {
892
- return __awaiter(this, void 0, void 0, function* () {
893
- try {
894
- const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
895
- const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'GROUP_PRIVILEGE_VIEW');
896
- if (!isPrivileged) {
897
- throw new general_1.ClassError('Group', 'GroupErrMsg11', 'You do not have the privilege to view group privileges');
898
- }
899
- yield Group.init(dbTransaction, GroupCode);
900
- const where = {
901
- GroupCode,
902
- };
903
- const systemWhere = {};
904
- if (search) {
905
- Object.entries(search).forEach(([key, value]) => {
906
- if (key === 'SystemCode' || key === 'PrivilegeCode') {
907
- systemWhere[key] = {
908
- [sequelize_1.Op.substring]: value,
909
- };
910
- }
911
- else {
912
- where[key] = {
913
- [sequelize_1.Op.substring]: value,
914
- };
915
- }
916
- });
917
- }
918
- const groupObjectPrivileges = yield Group._GroupObjectPrivilegeRepo.findAll({
919
- where,
920
- include: [
921
- {
922
- model: system_privilege_entity_1.default,
923
- where: systemWhere,
924
- },
925
- ],
926
- transaction: dbTransaction,
927
- });
928
- const privileges = [];
929
- for (const groupObjectPrivilege of groupObjectPrivileges) {
930
- const systemPrivilege = yield system_privilege_1.SystemPrivilege.init(dbTransaction);
931
- systemPrivilege.setAttributes(groupObjectPrivilege.Privilege.get({ plain: true }));
932
- privileges.push(systemPrivilege);
933
- }
934
- const uniquePrivileges = Array.from(new Set(privileges.map((a) => a.SystemPrivilegeId))).map((SystemPrivilegeId) => {
935
- return privileges.find((a) => a.SystemPrivilegeId === SystemPrivilegeId);
936
- });
937
- return uniquePrivileges;
938
- }
939
- catch (error) {
940
- throw error;
941
- }
942
- });
943
- }
944
- static assignGroupPrivileges(loginUser, dbTransaction, GroupCode, SystemPrivilegeIds) {
945
- return __awaiter(this, void 0, void 0, function* () {
946
- try {
947
- const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
948
- const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'GROUP_PRIVILEGE_ASSIGN');
949
- if (!isPrivileged) {
950
- throw new general_1.ClassError('Group', 'GroupErrMsg06', 'You do not have the privilege to assign group privileges');
951
- }
952
- const group = yield Group.init(dbTransaction, GroupCode);
953
- const groupSystemAccesses = yield Group.getSystemAccesses(loginUser, dbTransaction, GroupCode, 1, Number.MAX_SAFE_INTEGER, {});
954
- let parentGroupSystemAccesses = {
955
- rows: [],
956
- count: 0,
957
- };
958
- if (group.InheritParentSystemAccessYN === 'Y' && group.ParentGroupCode) {
959
- parentGroupSystemAccesses = yield Group.getSystemAccesses(loginUser, dbTransaction, group.ParentGroupCode, 1, Number.MAX_SAFE_INTEGER, {});
960
- }
961
- for (const SystemPrivilegeId of SystemPrivilegeIds) {
962
- const systemPrivilege = yield system_privilege_1.SystemPrivilege.init(dbTransaction, SystemPrivilegeId);
963
- const combinedSystemAccesses = [
964
- ...groupSystemAccesses.rows,
965
- ...parentGroupSystemAccesses.rows,
966
- ];
967
- const systemAccess = combinedSystemAccesses.find((systemAccess) => systemAccess.SystemCode === systemPrivilege.SystemCode);
968
- if (!systemAccess) {
969
- throw new general_1.ClassError('Group', 'GroupErrMsg13', 'Failed to assign privilege ' +
970
- SystemPrivilegeId +
971
- ' due to non-existent system access.');
972
- }
973
- const groupPrivilege = yield Group._GroupPrivilegeRepo.findOne({
974
- where: {
975
- GroupCode,
976
- SystemPrivilegeId,
977
- },
978
- include: [
979
- {
980
- model: system_privilege_entity_1.default,
981
- },
982
- ],
983
- transaction: dbTransaction,
984
- });
985
- if (groupPrivilege && groupPrivilege.Status === 'Active') {
986
- continue;
987
- }
988
- let entityValueBefore = {};
989
- let entityValueAfter = {};
990
- let action = activity_history_1.ActionEnum.CREATE;
991
- let description = 'Create Group Privilege';
992
- let entityId = null;
993
- if (groupPrivilege && groupPrivilege.Status !== 'Active') {
994
- entityValueBefore = {
995
- GroupCode: groupPrivilege.GroupCode,
996
- SystemPrivilegeId: groupPrivilege.SystemPrivilegeId,
997
- Status: groupPrivilege.Status,
998
- CreatedById: groupPrivilege.CreatedById,
999
- CreatedAt: groupPrivilege.CreatedAt,
1000
- UpdatedById: groupPrivilege.UpdatedById,
1001
- UpdatedAt: groupPrivilege.UpdatedAt,
1002
- };
1003
- const updatedPayload = {
1004
- Status: 'Active',
1005
- UpdatedById: loginUser.UserId,
1006
- UpdatedAt: new Date(),
1007
- };
1008
- const data = yield Group._GroupPrivilegeRepo.findOne({
1009
- where: {
1010
- GroupCode,
1011
- SystemPrivilegeId,
1012
- },
1013
- include: [
1014
- {
1015
- model: system_privilege_entity_1.default,
1016
- },
1017
- ],
1018
- transaction: dbTransaction,
1019
- });
1020
- data.Status = 'Active';
1021
- data.UpdatedById = updatedPayload.UpdatedById;
1022
- data.UpdatedAt = updatedPayload.UpdatedAt;
1023
- yield data.save({ transaction: dbTransaction });
1024
- entityValueAfter = {
1025
- GroupCode: groupPrivilege.GroupCode,
1026
- SystemPrivilegeId: groupPrivilege.SystemPrivilegeId,
1027
- Status: updatedPayload.Status,
1028
- CreatedById: groupPrivilege.CreatedById,
1029
- CreatedAt: groupPrivilege.CreatedAt,
1030
- UpdatedById: updatedPayload.UpdatedById,
1031
- UpdatedAt: updatedPayload.UpdatedAt,
1032
- };
1033
- action = activity_history_1.ActionEnum.UPDATE;
1034
- description = 'Update Group Privilege';
1035
- entityId = groupPrivilege.GroupPrivilegeId;
1036
- }
1037
- else {
1038
- const newGroupPrivilege = yield group_privilege_1.GroupPrivilege.init(dbTransaction);
1039
- newGroupPrivilege.setAttributes({
1040
- GroupCode,
1041
- SystemPrivilegeId,
1042
- Status: 'Active',
1043
- CreatedById: loginUser.UserId,
1044
- CreatedAt: new Date(),
1045
- UpdatedById: loginUser.UserId,
1046
- UpdatedAt: new Date(),
1047
- });
1048
- entityValueAfter = {
1049
- GroupCode: newGroupPrivilege.GroupCode,
1050
- SystemPrivilegeId: newGroupPrivilege.SystemPrivilegeId,
1051
- Status: newGroupPrivilege.Status,
1052
- CreatedById: newGroupPrivilege.CreatedById,
1053
- CreatedAt: newGroupPrivilege.CreatedAt,
1054
- UpdatedById: newGroupPrivilege.UpdatedById,
1055
- UpdatedAt: newGroupPrivilege.UpdatedAt,
1056
- };
1057
- const groupPrivilege = yield Group._GroupPrivilegeRepo.create(entityValueAfter, {
1058
- transaction: dbTransaction,
1059
- });
1060
- action = activity_history_1.ActionEnum.CREATE;
1061
- description = 'Create Group Privilege';
1062
- entityId = groupPrivilege.GroupPrivilegeId;
1063
- }
1064
- const activity = new activity_history_1.Activity();
1065
- activity.ActivityId = activity.createId();
1066
- activity.Action = action;
1067
- activity.Description = description;
1068
- activity.EntityType = 'GroupPrivilege';
1069
- activity.EntityId = entityId;
1070
- activity.EntityValueBefore = JSON.stringify(entityValueBefore);
1071
- activity.EntityValueAfter = JSON.stringify(entityValueAfter);
1072
- yield activity.create(loginUser.ObjectId, dbTransaction);
1073
- }
1074
- return 'Successfully added.';
1075
- }
1076
- catch (error) {
1077
- throw error;
1078
- }
1079
- });
1080
- }
1081
- static deleteGroupPrivilege(loginUser, dbTransaction, GroupCode, SystemPrivilegeIds) {
1082
- return __awaiter(this, void 0, void 0, function* () {
1083
- try {
1084
- const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
1085
- const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'GROUP_PRIVILEGE_DELETE');
1086
- if (!isPrivileged) {
1087
- throw new general_1.ClassError('Group', 'GroupErrMsg06', 'You do not have the privilege to delete group privileges');
1088
- }
1089
- for (const SystemPrivilegeId of SystemPrivilegeIds) {
1090
- const groupPrivilege = yield Group._GroupPrivilegeRepo.findOne({
1091
- where: {
1092
- GroupCode,
1093
- SystemPrivilegeId,
1094
- },
1095
- include: [
1096
- {
1097
- model: system_privilege_entity_1.default,
1098
- },
1099
- ],
1100
- transaction: dbTransaction,
1101
- });
1102
- if (!groupPrivilege) {
1103
- throw new general_1.ClassError('Group', 'GroupErrMsg14', 'GroupPrivilege not found.');
1104
- }
1105
- const entityValueBefore = {
1106
- GroupCode: groupPrivilege.GroupCode,
1107
- SystemPrivilegeId: groupPrivilege.SystemPrivilegeId,
1108
- Status: groupPrivilege.Status,
1109
- CreatedById: groupPrivilege.CreatedById,
1110
- CreatedAt: groupPrivilege.CreatedAt,
1111
- UpdatedById: groupPrivilege.UpdatedById,
1112
- UpdatedAt: groupPrivilege.UpdatedAt,
1113
- };
1114
- yield Group._GroupPrivilegeRepo.delete(GroupCode, SystemPrivilegeId, dbTransaction);
1115
- const activity = new activity_history_1.Activity();
1116
- activity.ActivityId = activity.createId();
1117
- activity.Action = activity_history_1.ActionEnum.DELETE;
1118
- activity.Description = 'DELETE Group Privilege';
1119
- activity.EntityType = 'GroupPrivilege';
1120
- activity.EntityId = groupPrivilege.GroupPrivilegeId.toString();
1121
- activity.EntityValueBefore = JSON.stringify(entityValueBefore);
1122
- activity.EntityValueAfter = JSON.stringify({});
1123
- yield activity.create(loginUser.ObjectId, dbTransaction);
1124
- }
1125
- return 'Successfully deleted.';
1126
- }
1127
- catch (error) {
1128
- throw error;
1129
- }
1130
- });
1131
- }
1132
- static getHierarchy(loginUser, dbTransaction, Status, Type, ParentGroupCode) {
1133
- return __awaiter(this, void 0, void 0, function* () {
1134
- const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
1135
- const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'GROUP_VIEW');
1136
- if (!isPrivileged) {
1137
- throw new general_1.ClassError('Group', 'GroupErrMsg04', 'User is not privileged to view group');
1138
- }
1139
- const queryObj = {};
1140
- let options = {
1141
- transaction: dbTransaction,
1142
- };
1143
- const search = {
1144
- Status: Status ? Status : 'Active',
1145
- Type: Type,
1146
- ParentGroupCode: ParentGroupCode,
1147
- };
1148
- if (search) {
1149
- Object.entries(search).forEach(([key, value]) => {
1150
- if (value) {
1151
- queryObj[key] = {
1152
- [sequelize_1.Op.substring]: value,
1153
- };
1154
- }
1155
- });
1156
- options = Object.assign(Object.assign({}, options), { where: queryObj });
1157
- const result = yield Group._Repo.findAll(options);
1158
- const data = result.map((group) => new Group(group.get({ plain: true })));
1159
- const generateTree = (groups) => __awaiter(this, void 0, void 0, function* () {
1160
- const data = groups.map((group) => {
1161
- return {
1162
- GroupCode: group.ObjectId,
1163
- Name: group.Name,
1164
- Description: group.Description,
1165
- Type: group.Type,
1166
- ParentGroupCode: group.ParentGroupCode,
1167
- InheritParentPrivilegeYN: group.InheritParentPrivilegeYN,
1168
- InheritParentSystemAccessYN: group.InheritParentSystemAccessYN,
1169
- Path: group._Path,
1170
- Status: group.Status,
1171
- CreatedById: group._CreatedById,
1172
- CreatedAt: group._CreatedAt,
1173
- UpdatedById: group._UpdatedById,
1174
- UpdatedAt: group._UpdatedAt,
1175
- childrens: [],
1176
- };
1177
- });
1178
- const groupMap = {};
1179
- data.forEach((group) => {
1180
- group.childrens = [];
1181
- groupMap[group.GroupCode] = group;
1182
- });
1183
- const tree = [];
1184
- data.forEach((group) => {
1185
- if (group.ParentGroupCode) {
1186
- const parent = groupMap[group.ParentGroupCode];
1187
- if (parent) {
1188
- parent.childrens.push(group);
1189
- }
1190
- }
1191
- else {
1192
- tree.push(group);
1193
- }
1194
- });
1195
- return tree;
1196
- });
1197
- const tree = yield generateTree(data);
1198
- return tree;
1199
- }
1200
- });
1201
- }
1202
- static getGroupsWithReportingUser(loginUser, dbTransaction, whereOptions) {
1203
- return __awaiter(this, void 0, void 0, function* () {
1204
- try {
1205
- const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
1206
- const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'GROUP_VIEW');
1207
- if (!isPrivileged) {
1208
- throw new general_1.ClassError('Group', 'GroupErrMsg04', 'User is not privileged to view group');
1209
- }
1210
- const options = {
1211
- where: whereOptions,
1212
- include: [
1213
- {
1214
- model: group_reporting_user_entity_1.default,
1215
- where: { Status: 'Active' },
1216
- include: [
1217
- {
1218
- model: user_entity_1.default,
1219
- as: 'User',
1220
- attributes: ['UserId', 'FullName'],
1221
- },
1222
- ],
1223
- },
1224
- ],
1225
- transaction: dbTransaction,
1226
- };
1227
- const groups = yield Group._Repo.findAll(options);
1228
- return groups;
1229
- }
1230
- catch (error) {
1231
- throw error;
1232
- }
1233
- });
1234
- }
1235
- }
1236
- exports.Group = Group;
1237
- Group._Repo = new group_repository_1.GroupRepository();
1238
- Group._GroupSystemAccessRepo = new group_system_access_repository_1.GroupSystemAccessRepository();
1239
- Group._GroupPrivilegeRepo = new group_privilege_repository_1.GroupPrivilegeRepository();
1240
- Group._GroupObjectPrivilegeRepo = new group_object_privilege_repository_1.GroupObjectPrivilegeRepository();
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Group = void 0;
13
+ const general_1 = require("@tomei/general");
14
+ const group_repository_1 = require("./group.repository");
15
+ const config_1 = require("@tomei/config");
16
+ const sequelize_1 = require("sequelize");
17
+ const activity_history_1 = require("@tomei/activity-history");
18
+ const group_system_access_repository_1 = require("../group-system-access/group-system-access.repository");
19
+ const system_entity_1 = require("../../models/system.entity");
20
+ const group_system_access_1 = require("../group-system-access");
21
+ const redis_service_1 = require("../../redis-client/redis.service");
22
+ const system_privilege_entity_1 = require("../../models/system-privilege.entity");
23
+ const group_privilege_repository_1 = require("../group-privilege/group-privilege.repository");
24
+ const system_privilege_1 = require("../system-privilege/system-privilege");
25
+ const group_privilege_entity_1 = require("../../models/group-privilege.entity");
26
+ const group_object_privilege_repository_1 = require("../group-object-privilege/group-object-privilege.repository");
27
+ const group_object_privilege_1 = require("../group-object-privilege/group-object-privilege");
28
+ const group_privilege_1 = require("../group-privilege/group-privilege");
29
+ const group_reporting_user_entity_1 = require("../../models/group-reporting-user.entity");
30
+ const user_entity_1 = require("../../models/user.entity");
31
+ class Group extends general_1.TreeNodeBase {
32
+ get GroupCode() {
33
+ return this.ObjectId;
34
+ }
35
+ set GroupCode(value) {
36
+ this.ObjectId = value;
37
+ }
38
+ get CreatedById() {
39
+ return this._CreatedById;
40
+ }
41
+ get CreatedAt() {
42
+ return this._CreatedAt;
43
+ }
44
+ get UpdatedById() {
45
+ return this._UpdatedById;
46
+ }
47
+ get UpdatedAt() {
48
+ return this._UpdatedAt;
49
+ }
50
+ get Path() {
51
+ return this._Path;
52
+ }
53
+ set Path(value) {
54
+ this._Path = value;
55
+ }
56
+ constructor(groupAttr) {
57
+ super();
58
+ this.ObjectType = 'Group';
59
+ this._Path = '';
60
+ this.isChildrenLoaded = false;
61
+ this.isParentLoaded = false;
62
+ if (groupAttr) {
63
+ this.GroupCode = groupAttr.GroupCode;
64
+ this.Name = groupAttr.Name;
65
+ this.Description = groupAttr === null || groupAttr === void 0 ? void 0 : groupAttr.Description;
66
+ this.Type = groupAttr === null || groupAttr === void 0 ? void 0 : groupAttr.Type;
67
+ this.ParentGroupCode = groupAttr === null || groupAttr === void 0 ? void 0 : groupAttr.ParentGroupCode;
68
+ this.InheritParentPrivilegeYN = groupAttr === null || groupAttr === void 0 ? void 0 : groupAttr.InheritParentPrivilegeYN;
69
+ this.InheritParentSystemAccessYN = groupAttr === null || groupAttr === void 0 ? void 0 : groupAttr.InheritParentSystemAccessYN;
70
+ this.Status = groupAttr === null || groupAttr === void 0 ? void 0 : groupAttr.Status;
71
+ this._Path = groupAttr === null || groupAttr === void 0 ? void 0 : groupAttr.Path;
72
+ this._CreatedById = groupAttr.CreatedById;
73
+ this._CreatedAt = groupAttr.CreatedAt;
74
+ this._UpdatedById = groupAttr.UpdatedById;
75
+ this._UpdatedAt = groupAttr.UpdatedAt;
76
+ }
77
+ }
78
+ static init(dbTransaction, GroupCode) {
79
+ return __awaiter(this, void 0, void 0, function* () {
80
+ try {
81
+ Group._RedisService = yield redis_service_1.RedisService.init();
82
+ if (GroupCode) {
83
+ const group = yield Group._Repo.findByPk(GroupCode, {
84
+ transaction: dbTransaction,
85
+ });
86
+ if (group) {
87
+ return new Group(group);
88
+ }
89
+ else {
90
+ throw Error('Group not found');
91
+ }
92
+ }
93
+ return new Group();
94
+ }
95
+ catch (error) {
96
+ throw new general_1.ClassError('Group', 'GroupErrMsg01', 'Failed To Initialize Group');
97
+ }
98
+ });
99
+ }
100
+ loadChildren(dbTransaction) {
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ if (!this.GroupCode) {
103
+ throw Error('GroupCode is missing.');
104
+ }
105
+ const children = yield Group._Repo.findAll({
106
+ where: { ParentGroupCode: this.GroupCode },
107
+ order: [['CreatedAt', 'ASC']],
108
+ transaction: dbTransaction,
109
+ });
110
+ this.children = children.map((child) => {
111
+ return new Group(child.get({ plain: true }));
112
+ });
113
+ this.isChildrenLoaded = true;
114
+ });
115
+ }
116
+ loadParent(dbTransaction) {
117
+ return __awaiter(this, void 0, void 0, function* () {
118
+ if (!this.GroupCode) {
119
+ throw Error('GroupCode are missing.');
120
+ }
121
+ if (this.ParentGroupCode) {
122
+ if (this.ParentGroupCode !== this.GroupCode) {
123
+ const parent = yield Group._Repo.findByPk(this.ParentGroupCode, {
124
+ transaction: dbTransaction,
125
+ });
126
+ this.parent = new Group(parent.get({ plain: true }));
127
+ }
128
+ }
129
+ this.isParentLoaded = true;
130
+ });
131
+ }
132
+ isLeaf(dbTransaction) {
133
+ return __awaiter(this, void 0, void 0, function* () {
134
+ if (!this.isChildrenLoaded) {
135
+ yield this.loadChildren(dbTransaction);
136
+ }
137
+ return this.children.length === 0;
138
+ });
139
+ }
140
+ getPath(dbTransaction) {
141
+ return __awaiter(this, void 0, void 0, function* () {
142
+ if (!this.isParentLoaded) {
143
+ yield this.loadParent(dbTransaction);
144
+ }
145
+ if (this.parent) {
146
+ this._Path =
147
+ (yield this.parent.getPath(dbTransaction)) + '/' + this.GroupCode;
148
+ return this._Path;
149
+ }
150
+ this._Path = this.GroupCode;
151
+ return this._Path;
152
+ });
153
+ }
154
+ updatePath(dbTransaction) {
155
+ return __awaiter(this, void 0, void 0, function* () {
156
+ const path = yield this.getPath(dbTransaction);
157
+ this._Path = path;
158
+ });
159
+ }
160
+ setParent(parent, dbTransaction) {
161
+ return __awaiter(this, void 0, void 0, function* () {
162
+ this.parent = parent;
163
+ yield this.updatePath(dbTransaction);
164
+ });
165
+ }
166
+ getPathDetail(dbTransaction) {
167
+ return __awaiter(this, void 0, void 0, function* () {
168
+ const path = this._Path.split('/');
169
+ const groups = [];
170
+ for (let i = 0; i < path.length; i++) {
171
+ const group = yield Group.init(dbTransaction, path[i]);
172
+ groups.push(group);
173
+ }
174
+ return groups;
175
+ });
176
+ }
177
+ static findAll(page, row, dbTransaction, loginUser, search) {
178
+ return __awaiter(this, void 0, void 0, function* () {
179
+ const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
180
+ const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'GROUP_LIST');
181
+ if (!isPrivileged) {
182
+ throw new general_1.ClassError('Group', 'GroupErrMsg04', 'User is not privileged to list group');
183
+ }
184
+ const queryObj = {};
185
+ let options = {
186
+ transaction: dbTransaction,
187
+ };
188
+ if (page && row) {
189
+ options = Object.assign(Object.assign({}, options), { limit: row, offset: row * (page - 1), order: [['CreatedAt', 'DESC']] });
190
+ }
191
+ if (search) {
192
+ Object.entries(search).forEach(([key, value]) => {
193
+ queryObj[key] = {
194
+ [sequelize_1.Op.substring]: value,
195
+ };
196
+ });
197
+ options = Object.assign(Object.assign({}, options), { where: queryObj });
198
+ const result = yield Group._Repo.findAllWithPagination(options);
199
+ return {
200
+ Count: result.count,
201
+ Groups: result.rows.map((group) => new Group(group.get({ plain: true }))),
202
+ };
203
+ }
204
+ });
205
+ }
206
+ static create(loginUser, dbTransaction, group) {
207
+ return __awaiter(this, void 0, void 0, function* () {
208
+ try {
209
+ const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
210
+ const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'GROUP_CREATE');
211
+ if (!isPrivileged) {
212
+ throw new Error('You do not have permission to create group');
213
+ }
214
+ if (!group.GroupCode) {
215
+ throw new general_1.ClassError('Group', 'GroupErrMsg02', 'Group Code is required');
216
+ }
217
+ if (!group.Name) {
218
+ throw new general_1.ClassError('Group', 'GroupErrMsg02', 'Group Name is required');
219
+ }
220
+ if (!group.Type) {
221
+ throw new general_1.ClassError('Group', 'GroupErrMsg02', 'Group Type is required');
222
+ }
223
+ const existingGroupCode = yield Group._Repo.findByPk(group.GroupCode, {
224
+ transaction: dbTransaction,
225
+ });
226
+ if (existingGroupCode) {
227
+ throw new general_1.ClassError('Group', 'GroupErrMsg03', 'Duplicate GroupCode found.');
228
+ }
229
+ if (group.ParentGroupCode) {
230
+ const parentGroup = yield Group._Repo.findByPk(group.ParentGroupCode, {
231
+ transaction: dbTransaction,
232
+ });
233
+ if (!parentGroup) {
234
+ throw new general_1.ClassError('Group', 'GroupErrMsg04', 'ParentGroupCode is not found.');
235
+ }
236
+ if (group.GroupCode === group.ParentGroupCode) {
237
+ throw new general_1.ClassError('Group', 'GroupErrMsg05', 'GroupCode and ParentGroupCode cannot be the same.');
238
+ }
239
+ }
240
+ const newGroup = new Group(group);
241
+ newGroup.ObjectId = group.GroupCode;
242
+ newGroup.Name = group.Name;
243
+ newGroup.Type = group.Type;
244
+ newGroup.Description = group.Description;
245
+ newGroup.ParentGroupCode = group.ParentGroupCode;
246
+ newGroup.InheritParentPrivilegeYN = group.InheritParentPrivilegeYN;
247
+ newGroup.InheritParentSystemAccessYN = group.InheritParentSystemAccessYN;
248
+ newGroup.Status = 'Active';
249
+ newGroup._CreatedById = loginUser.UserId;
250
+ newGroup._UpdatedById = loginUser.UserId;
251
+ newGroup._Path = yield newGroup.getPath(dbTransaction);
252
+ const entityGroupAfter = {
253
+ GroupCode: newGroup.ObjectId,
254
+ Name: newGroup.Name,
255
+ Type: newGroup.Type,
256
+ Description: newGroup.Description,
257
+ ParentGroupCode: newGroup.ParentGroupCode,
258
+ InheritParentPrivilegeYN: newGroup.InheritParentPrivilegeYN,
259
+ InheritParentSystemAccessYN: newGroup.InheritParentSystemAccessYN,
260
+ Path: newGroup._Path,
261
+ Status: newGroup.Status,
262
+ CreatedById: newGroup._CreatedById,
263
+ UpdatedById: newGroup._UpdatedById,
264
+ CreatedAt: newGroup._CreatedAt,
265
+ UpdatedAt: newGroup._UpdatedAt,
266
+ };
267
+ yield Group._Repo.create(entityGroupAfter, {
268
+ transaction: dbTransaction,
269
+ });
270
+ const entityValueBefore = {};
271
+ const activity = new activity_history_1.Activity();
272
+ activity.ActivityId = activity.createId();
273
+ activity.Action = activity_history_1.ActionEnum.CREATE;
274
+ activity.Description = 'Create Group';
275
+ activity.EntityType = 'Group';
276
+ activity.EntityId = newGroup.ObjectId;
277
+ activity.EntityValueBefore = JSON.stringify(entityValueBefore);
278
+ activity.EntityValueAfter = JSON.stringify(entityGroupAfter);
279
+ yield activity.create(loginUser.ObjectId, dbTransaction);
280
+ return newGroup;
281
+ }
282
+ catch (error) {
283
+ throw error;
284
+ }
285
+ });
286
+ }
287
+ static checkDuplicateGroupCode(dbTransaction, GroupCode) {
288
+ return __awaiter(this, void 0, void 0, function* () {
289
+ const isGroupCodeExist = yield Group._Repo.findOne({
290
+ where: { GroupCode },
291
+ transaction: dbTransaction,
292
+ });
293
+ if (isGroupCodeExist) {
294
+ throw new general_1.ClassError('Group', 'GroupErrMsg07', 'GroupCode already exists.');
295
+ }
296
+ });
297
+ }
298
+ updateChildrenPath(oldGroupCode, dbTransaction) {
299
+ return __awaiter(this, void 0, void 0, function* () {
300
+ try {
301
+ const isLeaf = yield this.isLeaf(dbTransaction);
302
+ if (isLeaf) {
303
+ return;
304
+ }
305
+ const childrens = yield Group._Repo.findAll({
306
+ where: {
307
+ Path: {
308
+ [sequelize_1.Op.like]: `${oldGroupCode}/%`,
309
+ },
310
+ },
311
+ transaction: dbTransaction,
312
+ });
313
+ childrens.forEach((children) => __awaiter(this, void 0, void 0, function* () {
314
+ const path = children.Path.split(`${oldGroupCode}/`);
315
+ const childPath = path[1];
316
+ yield children.update({ Path: `${this._Path}/${childPath}` }, { transaction: dbTransaction });
317
+ }));
318
+ }
319
+ catch (error) {
320
+ throw error;
321
+ }
322
+ });
323
+ }
324
+ update(loginUser, dbTransaction, group) {
325
+ return __awaiter(this, void 0, void 0, function* () {
326
+ const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
327
+ const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'GROUP_UPDATE');
328
+ if (!isPrivileged) {
329
+ throw new general_1.ClassError('Group', 'GroupErrMsg06', 'You do not have the privilege to update Group');
330
+ }
331
+ try {
332
+ if (group.NewGroupCode) {
333
+ yield Group.checkDuplicateGroupCode(dbTransaction, group.NewGroupCode);
334
+ }
335
+ const entityValueBefore = {
336
+ GroupCode: this.GroupCode,
337
+ Name: this.Name,
338
+ Type: this.Type,
339
+ Description: this.Description,
340
+ ParentGroupCode: this.ParentGroupCode,
341
+ InheritParentPrivilegeYN: this.InheritParentPrivilegeYN,
342
+ InheritParentSystemAccessYN: this.InheritParentSystemAccessYN,
343
+ Path: this.Path,
344
+ Status: this.Status,
345
+ CreatedById: this._CreatedById,
346
+ UpdatedById: this._UpdatedById,
347
+ CreatedAt: this._CreatedAt,
348
+ UpdatedAt: this._UpdatedAt,
349
+ };
350
+ let isPathChanged = false;
351
+ const oldGroupCode = this.GroupCode;
352
+ if (group.NewGroupCode) {
353
+ this.GroupCode = group.NewGroupCode;
354
+ isPathChanged = true;
355
+ }
356
+ if ((group.ParentGroupCode &&
357
+ this.ParentGroupCode !== group.ParentGroupCode) ||
358
+ (group.ParentGroupCode && !this.ParentGroupCode)) {
359
+ const parentGroup = yield Group.init(dbTransaction, group.ParentGroupCode);
360
+ if (!parentGroup) {
361
+ throw new general_1.ClassError('Group', 'GroupErrMsg08', 'Parent Group Code not found');
362
+ }
363
+ yield this.setParent(parentGroup);
364
+ isPathChanged = true;
365
+ }
366
+ else if (!group.ParentGroupCode && this.ParentGroupCode) {
367
+ yield this.setParent(null);
368
+ isPathChanged = true;
369
+ }
370
+ if (isPathChanged) {
371
+ yield this.updateChildrenPath(oldGroupCode, dbTransaction);
372
+ }
373
+ this.Name = (group === null || group === void 0 ? void 0 : group.Name) || this.Name;
374
+ this.Type = (group === null || group === void 0 ? void 0 : group.Type) || this.Type;
375
+ this.Description = (group === null || group === void 0 ? void 0 : group.Description) || this.Description;
376
+ this.ParentGroupCode = (group === null || group === void 0 ? void 0 : group.ParentGroupCode) || this.ParentGroupCode;
377
+ this.InheritParentPrivilegeYN =
378
+ (group === null || group === void 0 ? void 0 : group.InheritParentPrivilegeYN) || this.InheritParentPrivilegeYN;
379
+ this.InheritParentSystemAccessYN =
380
+ (group === null || group === void 0 ? void 0 : group.InheritParentSystemAccessYN) || this.InheritParentSystemAccessYN;
381
+ this.Status = (group === null || group === void 0 ? void 0 : group.Status) || this.Status;
382
+ this._UpdatedById = loginUser.UserId;
383
+ this._UpdatedAt = new Date();
384
+ yield Group._Repo.update({
385
+ GroupCode: this.GroupCode,
386
+ Name: this.Name,
387
+ Type: this.Type,
388
+ Description: this.Description,
389
+ ParentGroupCode: this.ParentGroupCode,
390
+ InheritParentPrivilegeYN: this.InheritParentPrivilegeYN,
391
+ InheritParentSystemAccessYN: this.InheritParentSystemAccessYN,
392
+ Status: this.Status,
393
+ Path: this._Path,
394
+ UpdatedById: this._UpdatedById,
395
+ UpdatedAt: this._UpdatedAt,
396
+ }, {
397
+ where: {
398
+ GroupCode: group.GroupCode,
399
+ },
400
+ transaction: dbTransaction,
401
+ });
402
+ const entityValueAfter = {
403
+ GroupCode: this.GroupCode,
404
+ Name: this.Name,
405
+ Type: this.Type,
406
+ Description: this.Description,
407
+ ParentGroupCode: this.ParentGroupCode,
408
+ InheritParentPrivilegeYN: this.InheritParentPrivilegeYN,
409
+ InheritParentSystemAccessYN: this.InheritParentSystemAccessYN,
410
+ Status: this.Status,
411
+ Path: this._Path,
412
+ CreatedById: this._CreatedById,
413
+ UpdatedById: this._UpdatedById,
414
+ CreatedAt: this._CreatedAt,
415
+ UpdatedAt: this._UpdatedAt,
416
+ };
417
+ const activity = new activity_history_1.Activity();
418
+ activity.ActivityId = activity.createId();
419
+ activity.Action = activity_history_1.ActionEnum.UPDATE;
420
+ activity.Description = `Update Group ${group.Type}`;
421
+ activity.EntityType = 'Group';
422
+ activity.EntityId = group.GroupCode;
423
+ activity.EntityValueBefore = JSON.stringify(entityValueBefore);
424
+ activity.EntityValueAfter = JSON.stringify(entityValueAfter);
425
+ yield activity.create(loginUser.ObjectId, dbTransaction);
426
+ return this;
427
+ }
428
+ catch (error) {
429
+ throw error;
430
+ }
431
+ });
432
+ }
433
+ static delete(loginUser, dbTransaction, GroupCode) {
434
+ return __awaiter(this, void 0, void 0, function* () {
435
+ const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
436
+ const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'GROUP_DELETE');
437
+ if (!isPrivileged) {
438
+ throw new general_1.ClassError('Group', 'GroupErrMsg03', 'You do not have the privilege to delete groups records.');
439
+ }
440
+ try {
441
+ const group = yield Group.init(dbTransaction, GroupCode);
442
+ if (group.Status === 'Active') {
443
+ throw new general_1.ClassError('Group', 'GroupErrMsg03', 'Active Group cant be deleted');
444
+ }
445
+ const relatedGroup = yield Group.findAll(1, Number.MAX_SAFE_INTEGER, dbTransaction, loginUser, {
446
+ ParentGroupCode: GroupCode,
447
+ });
448
+ if (relatedGroup.Count > 0) {
449
+ const listOfRelatedGroup = relatedGroup.Groups.map((group) => {
450
+ return group.GroupCode;
451
+ });
452
+ throw new general_1.ClassError('Group', 'GroupErrMsg03', `Group still has associated user group ${listOfRelatedGroup}`);
453
+ }
454
+ yield Group._Repo.delete(GroupCode, dbTransaction);
455
+ const EntityValueBefore = {
456
+ GroupCode: group.GroupCode,
457
+ Name: group.Name,
458
+ Type: group.Type,
459
+ Description: group.Description,
460
+ ParentGroupCode: group.ParentGroupCode,
461
+ InheritParentPrivilegeYN: group.InheritParentPrivilegeYN,
462
+ InheritParentSystemAccessYN: group.InheritParentSystemAccessYN,
463
+ Status: group.Status,
464
+ CreatedById: group._CreatedById,
465
+ UpdatedById: group._UpdatedById,
466
+ CreatedAt: group._CreatedAt,
467
+ UpdatedAt: group._UpdatedAt,
468
+ };
469
+ const activity = new activity_history_1.Activity();
470
+ activity.ActivityId = activity.createId();
471
+ activity.Action = activity_history_1.ActionEnum.DELETE;
472
+ activity.Description = 'Delete Group';
473
+ activity.EntityType = 'Group';
474
+ activity.EntityId = group.ObjectId;
475
+ activity.EntityValueBefore = JSON.stringify(EntityValueBefore);
476
+ activity.EntityValueAfter = JSON.stringify({});
477
+ yield activity.create(loginUser.ObjectId, dbTransaction);
478
+ return { Message: 'Group removed.' };
479
+ }
480
+ catch (error) {
481
+ throw error;
482
+ }
483
+ });
484
+ }
485
+ static getSystemAccesses(loginUser, dbTransaction, GroupCode, Page, Rows, Search) {
486
+ return __awaiter(this, void 0, void 0, function* () {
487
+ const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
488
+ const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'SYSTEM_ACCESS_VIEW');
489
+ if (!isPrivileged) {
490
+ throw new general_1.ClassError('Group', 'GroupErrMsg06', 'You do not have the privilege to view system access');
491
+ }
492
+ try {
493
+ yield Group.init(dbTransaction, GroupCode);
494
+ const queryObj = { GroupCode: GroupCode };
495
+ if (Search) {
496
+ Object.entries(Search).forEach(([key, value]) => {
497
+ queryObj[key] = value;
498
+ });
499
+ }
500
+ let options = {
501
+ where: queryObj,
502
+ distinct: true,
503
+ transaction: dbTransaction,
504
+ };
505
+ if (Page && Rows) {
506
+ options = Object.assign(Object.assign({}, options), { limit: Rows, offset: Rows * (Page - 1), order: [['CreatedAt', 'DESC']] });
507
+ }
508
+ const systemAccess = yield Group._GroupSystemAccessRepo.findAndCountAll(options);
509
+ return systemAccess;
510
+ }
511
+ catch (error) {
512
+ return error;
513
+ }
514
+ });
515
+ }
516
+ static getInheritedSystemAccess(dbTransaction, group) {
517
+ return __awaiter(this, void 0, void 0, function* () {
518
+ const options = {
519
+ where: {
520
+ GroupCode: group.GroupCode,
521
+ Status: 'Active',
522
+ },
523
+ include: [
524
+ {
525
+ model: system_entity_1.default,
526
+ },
527
+ ],
528
+ transaction: dbTransaction,
529
+ };
530
+ let systemAccess = yield Group._GroupSystemAccessRepo.findAll(options);
531
+ if (group.InheritParentSystemAccessYN === 'Y' && group.ParentGroupCode) {
532
+ const parentGroup = yield Group.init(dbTransaction, group.ParentGroupCode);
533
+ const parentSystemAccesses = yield this.getInheritedSystemAccess(dbTransaction, parentGroup);
534
+ systemAccess = systemAccess.concat(parentSystemAccesses);
535
+ }
536
+ return systemAccess;
537
+ });
538
+ }
539
+ static isGroupCodeInHierarchy(dbTransaction_1, GroupCode_1) {
540
+ return __awaiter(this, arguments, void 0, function* (dbTransaction, GroupCode, ListGroupCode = []) {
541
+ ListGroupCode.push(GroupCode);
542
+ const group = yield Group._Repo.findOne({
543
+ where: { GroupCode },
544
+ transaction: dbTransaction,
545
+ });
546
+ if (group === null || group === void 0 ? void 0 : group.ParentGroupCode) {
547
+ const isGroupCodeExist = ListGroupCode.includes(group.ParentGroupCode);
548
+ if (!isGroupCodeExist) {
549
+ yield this.isGroupCodeInHierarchy(dbTransaction, group.ParentGroupCode, ListGroupCode);
550
+ }
551
+ {
552
+ return false;
553
+ }
554
+ }
555
+ else {
556
+ return true;
557
+ }
558
+ });
559
+ }
560
+ static getParentSystemAccesses(loginUser, dbTransaction, GroupCode) {
561
+ return __awaiter(this, void 0, void 0, function* () {
562
+ const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
563
+ const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'SYSTEM_ACCESS_VIEW');
564
+ if (!isPrivileged) {
565
+ throw new general_1.ClassError('Group', 'GroupErrMsg06', 'You do not have the privilege to view system access');
566
+ }
567
+ try {
568
+ const group = yield Group.init(dbTransaction, GroupCode);
569
+ if (group.InheritParentSystemAccessYN !== 'Y' || !group.ParentGroupCode) {
570
+ return [];
571
+ }
572
+ else {
573
+ const parentGroup = yield Group.init(dbTransaction, group.ParentGroupCode);
574
+ const inheritSystemAccess = yield Group.getInheritedSystemAccess(dbTransaction, parentGroup);
575
+ return inheritSystemAccess;
576
+ }
577
+ }
578
+ catch (error) {
579
+ throw error;
580
+ }
581
+ });
582
+ }
583
+ static addSystemAccesses(loginUser, dbTransaction, GroupCode, SystemCodes) {
584
+ return __awaiter(this, void 0, void 0, function* () {
585
+ var _a;
586
+ const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
587
+ const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'SYSTEM_ACCESS_CREATE');
588
+ if (!isPrivileged) {
589
+ throw new general_1.ClassError('Group', 'GroupErrMsg07', 'You do not have the privilege to create system access');
590
+ }
591
+ try {
592
+ if (SystemCodes.length > 0) {
593
+ for (const element of SystemCodes) {
594
+ const CurrentGroupSystemAccess = yield Group.getSystemAccesses(loginUser, dbTransaction, GroupCode, 1, Number.MAX_SAFE_INTEGER, { SystemCode: element });
595
+ if ((CurrentGroupSystemAccess === null || CurrentGroupSystemAccess === void 0 ? void 0 : CurrentGroupSystemAccess.count) > 0) {
596
+ throw new general_1.ClassError('Group', 'GroupErrMsg08', 'System access already exists');
597
+ }
598
+ const groupSystemAccess = yield group_system_access_1.GroupSystemAccess.init(dbTransaction);
599
+ groupSystemAccess.createId();
600
+ groupSystemAccess.GroupCode = GroupCode;
601
+ groupSystemAccess.SystemCode = element;
602
+ groupSystemAccess.Status = 'Active';
603
+ groupSystemAccess.CreatedById = +loginUser.ObjectId;
604
+ groupSystemAccess.CreatedAt = new Date();
605
+ groupSystemAccess.UpdatedById = +loginUser.ObjectId;
606
+ groupSystemAccess.UpdatedAt = new Date();
607
+ const EntityValueAfter = {
608
+ GroupCode: groupSystemAccess.GroupCode,
609
+ SystemCode: groupSystemAccess.SystemCode,
610
+ Status: groupSystemAccess.Status,
611
+ CreatedById: groupSystemAccess.CreatedById,
612
+ CreatedAt: groupSystemAccess.CreatedAt,
613
+ UpdatedById: groupSystemAccess.UpdatedById,
614
+ UpdatedAt: groupSystemAccess.UpdatedAt,
615
+ };
616
+ const systemAccess = yield Group._GroupSystemAccessRepo.create(EntityValueAfter, {
617
+ transaction: dbTransaction,
618
+ });
619
+ const activity = new activity_history_1.Activity();
620
+ activity.ActivityId = activity.createId();
621
+ activity.Action = activity_history_1.ActionEnum.CREATE;
622
+ activity.Description = 'Create Group System Access';
623
+ activity.EntityType = 'GroupSystemAccess';
624
+ activity.EntityId = (_a = systemAccess.GroupSystemAccessId) === null || _a === void 0 ? void 0 : _a.toString();
625
+ activity.EntityValueBefore = JSON.stringify({});
626
+ activity.EntityValueAfter = JSON.stringify(EntityValueAfter);
627
+ yield activity.create(loginUser.ObjectId, dbTransaction);
628
+ }
629
+ return { Message: 'Successfully added.' };
630
+ }
631
+ }
632
+ catch (error) {
633
+ throw error;
634
+ }
635
+ });
636
+ }
637
+ static deleteSystemAccess(loginUser, dbTransaction, GroupCode, SystemCode) {
638
+ return __awaiter(this, void 0, void 0, function* () {
639
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
640
+ const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
641
+ const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'SYSTEM_ACCESS_DELETE');
642
+ if (!isPrivileged) {
643
+ throw new general_1.ClassError('Group', 'GroupErrMsg08', 'You do not have the privilege to delete system access');
644
+ }
645
+ try {
646
+ const currentGroupSystemAccess = yield Group.getSystemAccesses(loginUser, dbTransaction, GroupCode, 1, Number.MAX_SAFE_INTEGER, { SystemCode: SystemCode });
647
+ if (currentGroupSystemAccess.count < 1) {
648
+ throw new general_1.ClassError('Group', 'GroupErrMsg10', 'No associated system access found.');
649
+ }
650
+ yield Group._GroupSystemAccessRepo.delete(GroupCode, SystemCode, dbTransaction);
651
+ const EntityValueBefore = {
652
+ GroupCode: (_a = currentGroupSystemAccess === null || currentGroupSystemAccess === void 0 ? void 0 : currentGroupSystemAccess.rows[0]) === null || _a === void 0 ? void 0 : _a.GroupCode,
653
+ SystemCode: (_b = currentGroupSystemAccess === null || currentGroupSystemAccess === void 0 ? void 0 : currentGroupSystemAccess.rows[0]) === null || _b === void 0 ? void 0 : _b.SystemCode,
654
+ Status: (_c = currentGroupSystemAccess === null || currentGroupSystemAccess === void 0 ? void 0 : currentGroupSystemAccess.rows[0]) === null || _c === void 0 ? void 0 : _c.Status,
655
+ CreatedById: (_d = currentGroupSystemAccess === null || currentGroupSystemAccess === void 0 ? void 0 : currentGroupSystemAccess.rows[0]) === null || _d === void 0 ? void 0 : _d.CreatedById,
656
+ CreatedAt: (_e = currentGroupSystemAccess === null || currentGroupSystemAccess === void 0 ? void 0 : currentGroupSystemAccess.rows[0]) === null || _e === void 0 ? void 0 : _e.CreatedAt,
657
+ UpdatedById: (_f = currentGroupSystemAccess === null || currentGroupSystemAccess === void 0 ? void 0 : currentGroupSystemAccess.rows[0]) === null || _f === void 0 ? void 0 : _f.UpdatedById,
658
+ UpdatedAt: (_g = currentGroupSystemAccess === null || currentGroupSystemAccess === void 0 ? void 0 : currentGroupSystemAccess.rows[0]) === null || _g === void 0 ? void 0 : _g.UpdatedAt,
659
+ };
660
+ const activity = new activity_history_1.Activity();
661
+ activity.ActivityId = activity.createId();
662
+ activity.Action = activity_history_1.ActionEnum.DELETE;
663
+ activity.Description = 'Delete Group System Access';
664
+ activity.EntityType = 'GroupSystemAccess';
665
+ activity.EntityId =
666
+ (_j = (_h = currentGroupSystemAccess === null || currentGroupSystemAccess === void 0 ? void 0 : currentGroupSystemAccess.rows[0]) === null || _h === void 0 ? void 0 : _h.GroupSystemAccessId) === null || _j === void 0 ? void 0 : _j.toString();
667
+ activity.EntityValueBefore = JSON.stringify(EntityValueBefore);
668
+ activity.EntityValueAfter = JSON.stringify({});
669
+ yield activity.create(loginUser.ObjectId, dbTransaction);
670
+ return { Message: 'System access removed.', SystemCode: SystemCode };
671
+ }
672
+ catch (error) {
673
+ throw error;
674
+ }
675
+ });
676
+ }
677
+ static getSystemPrivileges(loginUser, dbTransaction, GroupCode, search) {
678
+ return __awaiter(this, void 0, void 0, function* () {
679
+ try {
680
+ const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
681
+ const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'GROUP_PRIVILEGE_VIEW');
682
+ if (!isPrivileged) {
683
+ throw new general_1.ClassError('Group', 'GroupErrMsg11', 'You do not have the privilege to view group privileges');
684
+ }
685
+ yield Group.init(dbTransaction, GroupCode);
686
+ let where = {
687
+ GroupCode,
688
+ };
689
+ let systemWhere = {};
690
+ if (search) {
691
+ if (search.Status) {
692
+ where = Object.assign(Object.assign({}, where), { Status: search.Status });
693
+ }
694
+ if (search.SystemCode) {
695
+ systemWhere = {
696
+ SystemCode: {
697
+ [sequelize_1.Op.substring]: search.SystemCode,
698
+ },
699
+ };
700
+ }
701
+ }
702
+ const groupOwnPrivileges = yield Group._GroupPrivilegeRepo.findAll({
703
+ where,
704
+ include: [
705
+ {
706
+ model: system_privilege_entity_1.default,
707
+ where: systemWhere,
708
+ },
709
+ ],
710
+ transaction: dbTransaction,
711
+ });
712
+ const privileges = [];
713
+ for (const groupPrivilege of groupOwnPrivileges) {
714
+ const systemPrivilege = yield system_privilege_1.SystemPrivilege.init(dbTransaction);
715
+ systemPrivilege.setAttributes(groupPrivilege.Privilege.get({ plain: true }));
716
+ privileges.push(systemPrivilege);
717
+ }
718
+ return privileges;
719
+ }
720
+ catch (error) {
721
+ throw error;
722
+ }
723
+ });
724
+ }
725
+ static getInheritedSystemPrivileges(dbTransaction, GroupCode, search) {
726
+ return __awaiter(this, void 0, void 0, function* () {
727
+ try {
728
+ const where = {
729
+ GroupCode,
730
+ };
731
+ let groupPrivilegeWhere = {};
732
+ let systemPrivilegeWhere = {};
733
+ if (search) {
734
+ if (search.Status) {
735
+ groupPrivilegeWhere = {
736
+ Status: search.Status,
737
+ };
738
+ }
739
+ if (search.SystemCode) {
740
+ systemPrivilegeWhere = {
741
+ SystemCode: {
742
+ [sequelize_1.Op.substring]: search.SystemCode,
743
+ },
744
+ };
745
+ }
746
+ if (search.PrivilegeCode) {
747
+ systemPrivilegeWhere = Object.assign(Object.assign({}, systemPrivilegeWhere), { PrivilegeCode: {
748
+ [sequelize_1.Op.substring]: search.PrivilegeCode,
749
+ } });
750
+ }
751
+ }
752
+ const group = yield Group._Repo.findOne({
753
+ where: where,
754
+ include: [
755
+ {
756
+ model: group_privilege_entity_1.default,
757
+ where: groupPrivilegeWhere,
758
+ separate: true,
759
+ include: [
760
+ {
761
+ model: system_privilege_entity_1.default,
762
+ where: systemPrivilegeWhere,
763
+ },
764
+ ],
765
+ },
766
+ ],
767
+ transaction: dbTransaction,
768
+ });
769
+ const objectWhere = {
770
+ GroupCode,
771
+ };
772
+ const systemWhere = {};
773
+ if (search) {
774
+ Object.entries(search).forEach(([key, value]) => {
775
+ if (key === 'Status') {
776
+ objectWhere[key] = {
777
+ [sequelize_1.Op.substring]: value,
778
+ };
779
+ }
780
+ else {
781
+ systemWhere[key] = {
782
+ [sequelize_1.Op.substring]: value,
783
+ };
784
+ }
785
+ });
786
+ }
787
+ const groupObjectPrivileges = yield Group._GroupObjectPrivilegeRepo.findAll({
788
+ where: objectWhere,
789
+ include: [
790
+ {
791
+ model: system_privilege_entity_1.default,
792
+ where: systemWhere,
793
+ },
794
+ ],
795
+ transaction: dbTransaction,
796
+ });
797
+ let privileges = [];
798
+ for (const groupPrivilege of group.GroupPrivileges) {
799
+ const systemPrivilege = yield system_privilege_1.SystemPrivilege.init(dbTransaction);
800
+ systemPrivilege.setAttributes(groupPrivilege.Privilege.get({ plain: true }));
801
+ privileges.push(systemPrivilege);
802
+ }
803
+ for (const groupObjectPrivilege of groupObjectPrivileges) {
804
+ const systemPrivilege = yield system_privilege_1.SystemPrivilege.init(dbTransaction);
805
+ systemPrivilege.setAttributes(groupObjectPrivilege.Privilege.get({ plain: true }));
806
+ privileges.push(systemPrivilege);
807
+ }
808
+ if (group.InheritParentPrivilegeYN === 'Y' && group.ParentGroupCode) {
809
+ const inheritedPrivileges = yield Group.getInheritedSystemPrivileges(dbTransaction, group.ParentGroupCode, search);
810
+ privileges = privileges.concat(inheritedPrivileges);
811
+ }
812
+ const uniquePrivileges = Array.from(new Set(privileges.map((a) => a.SystemPrivilegeId))).map((SystemPrivilegeId) => {
813
+ return privileges.find((a) => a.SystemPrivilegeId === SystemPrivilegeId);
814
+ });
815
+ return uniquePrivileges;
816
+ }
817
+ catch (error) {
818
+ throw error;
819
+ }
820
+ });
821
+ }
822
+ static getParentSystemPrivileges(loginUser, dbTransaction, GroupCode, search) {
823
+ return __awaiter(this, void 0, void 0, function* () {
824
+ try {
825
+ const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
826
+ const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'GROUP_PRIVILEGE_VIEW');
827
+ if (!isPrivileged) {
828
+ throw new general_1.ClassError('Group', 'GroupErrMsg11', 'You do not have the privilege to view group privileges');
829
+ }
830
+ const group = yield Group.init(dbTransaction, GroupCode);
831
+ if (group.InheritParentPrivilegeYN !== 'Y' || !group.ParentGroupCode) {
832
+ return [];
833
+ }
834
+ const privileges = yield Group.getInheritedSystemPrivileges(dbTransaction, group.ParentGroupCode, search);
835
+ return privileges;
836
+ }
837
+ catch (error) {
838
+ throw error;
839
+ }
840
+ });
841
+ }
842
+ static assignGroupObjectPrivilege(loginUser, dbTransaction, GroupCode, GroupObjectPrivileges, SystemCode) {
843
+ return __awaiter(this, void 0, void 0, function* () {
844
+ try {
845
+ const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
846
+ const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'GROUP_OBJECT_PRIVILEGE_ASSIGN');
847
+ if (!isPrivileged) {
848
+ throw new general_1.ClassError('Group', 'GroupErrMsg12', 'You do not have the privilege to assign group object privilege');
849
+ }
850
+ const group = yield Group.init(dbTransaction, GroupCode);
851
+ const groupSystemAccesses = yield Group.getSystemAccesses(loginUser, dbTransaction, GroupCode, 1, Number.MAX_SAFE_INTEGER, {});
852
+ let parentGroupSystemAccesses = {
853
+ rows: [],
854
+ count: 0,
855
+ };
856
+ if (group.InheritParentSystemAccessYN === 'Y' && group.ParentGroupCode) {
857
+ parentGroupSystemAccesses = yield Group.getSystemAccesses(loginUser, dbTransaction, group.ParentGroupCode, 1, Number.MAX_SAFE_INTEGER, undefined);
858
+ }
859
+ for (const groupObjectPrivilege of GroupObjectPrivileges) {
860
+ const systemPrivilege = yield system_privilege_1.SystemPrivilege.init(dbTransaction, groupObjectPrivilege.SystemPrivilegeId);
861
+ const combinedSystemAccesses = Object.assign(Object.assign({}, groupSystemAccesses.rows), parentGroupSystemAccesses.rows);
862
+ const systemAccess = combinedSystemAccesses.find((systemAccess) => systemAccess.SystemCode === systemPrivilege.SystemCode);
863
+ if (!systemAccess) {
864
+ throw new general_1.ClassError('Group', 'GroupErrMsg13', 'Failed to assign privilege ' +
865
+ groupObjectPrivilege.SystemPrivilegeId +
866
+ ' due to non-existent system access.');
867
+ }
868
+ const groupObjectPrivilegeData = yield Group._GroupObjectPrivilegeRepo.findOne({
869
+ where: {
870
+ GroupCode,
871
+ SystemPrivilegeId: groupObjectPrivilege.SystemPrivilegeId,
872
+ ObjectId: groupObjectPrivilege.ObjectId,
873
+ ObjectType: groupObjectPrivilege.ObjectType,
874
+ },
875
+ transaction: dbTransaction,
876
+ });
877
+ if (groupObjectPrivilegeData) {
878
+ continue;
879
+ }
880
+ else {
881
+ yield group_object_privilege_1.GroupObjectPrivilege.create(loginUser, dbTransaction, groupObjectPrivilege);
882
+ }
883
+ }
884
+ return 'Successfully added.';
885
+ }
886
+ catch (error) {
887
+ throw error;
888
+ }
889
+ });
890
+ }
891
+ static getGroubObjectPrivileges(loginUser, dbTransaction, GroupCode, search) {
892
+ return __awaiter(this, void 0, void 0, function* () {
893
+ try {
894
+ const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
895
+ const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'GROUP_PRIVILEGE_VIEW');
896
+ if (!isPrivileged) {
897
+ throw new general_1.ClassError('Group', 'GroupErrMsg11', 'You do not have the privilege to view group privileges');
898
+ }
899
+ yield Group.init(dbTransaction, GroupCode);
900
+ const where = {
901
+ GroupCode,
902
+ };
903
+ const systemWhere = {};
904
+ if (search) {
905
+ Object.entries(search).forEach(([key, value]) => {
906
+ if (key === 'SystemCode' || key === 'PrivilegeCode') {
907
+ systemWhere[key] = {
908
+ [sequelize_1.Op.substring]: value,
909
+ };
910
+ }
911
+ else {
912
+ where[key] = {
913
+ [sequelize_1.Op.substring]: value,
914
+ };
915
+ }
916
+ });
917
+ }
918
+ const groupObjectPrivileges = yield Group._GroupObjectPrivilegeRepo.findAll({
919
+ where,
920
+ include: [
921
+ {
922
+ model: system_privilege_entity_1.default,
923
+ where: systemWhere,
924
+ },
925
+ ],
926
+ transaction: dbTransaction,
927
+ });
928
+ const privileges = [];
929
+ for (const groupObjectPrivilege of groupObjectPrivileges) {
930
+ const systemPrivilege = yield system_privilege_1.SystemPrivilege.init(dbTransaction);
931
+ systemPrivilege.setAttributes(groupObjectPrivilege.Privilege.get({ plain: true }));
932
+ privileges.push(systemPrivilege);
933
+ }
934
+ const uniquePrivileges = Array.from(new Set(privileges.map((a) => a.SystemPrivilegeId))).map((SystemPrivilegeId) => {
935
+ return privileges.find((a) => a.SystemPrivilegeId === SystemPrivilegeId);
936
+ });
937
+ return uniquePrivileges;
938
+ }
939
+ catch (error) {
940
+ throw error;
941
+ }
942
+ });
943
+ }
944
+ static assignGroupPrivileges(loginUser, dbTransaction, GroupCode, SystemPrivilegeIds) {
945
+ return __awaiter(this, void 0, void 0, function* () {
946
+ try {
947
+ const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
948
+ const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'GROUP_PRIVILEGE_ASSIGN');
949
+ if (!isPrivileged) {
950
+ throw new general_1.ClassError('Group', 'GroupErrMsg06', 'You do not have the privilege to assign group privileges');
951
+ }
952
+ const group = yield Group.init(dbTransaction, GroupCode);
953
+ const groupSystemAccesses = yield Group.getSystemAccesses(loginUser, dbTransaction, GroupCode, 1, Number.MAX_SAFE_INTEGER, {});
954
+ let parentGroupSystemAccesses = {
955
+ rows: [],
956
+ count: 0,
957
+ };
958
+ if (group.InheritParentSystemAccessYN === 'Y' && group.ParentGroupCode) {
959
+ parentGroupSystemAccesses = yield Group.getSystemAccesses(loginUser, dbTransaction, group.ParentGroupCode, 1, Number.MAX_SAFE_INTEGER, {});
960
+ }
961
+ for (const SystemPrivilegeId of SystemPrivilegeIds) {
962
+ const systemPrivilege = yield system_privilege_1.SystemPrivilege.init(dbTransaction, SystemPrivilegeId);
963
+ const combinedSystemAccesses = [
964
+ ...groupSystemAccesses.rows,
965
+ ...parentGroupSystemAccesses.rows,
966
+ ];
967
+ const systemAccess = combinedSystemAccesses.find((systemAccess) => systemAccess.SystemCode === systemPrivilege.SystemCode);
968
+ if (!systemAccess) {
969
+ throw new general_1.ClassError('Group', 'GroupErrMsg13', 'Failed to assign privilege ' +
970
+ SystemPrivilegeId +
971
+ ' due to non-existent system access.');
972
+ }
973
+ const groupPrivilege = yield Group._GroupPrivilegeRepo.findOne({
974
+ where: {
975
+ GroupCode,
976
+ SystemPrivilegeId,
977
+ },
978
+ include: [
979
+ {
980
+ model: system_privilege_entity_1.default,
981
+ },
982
+ ],
983
+ transaction: dbTransaction,
984
+ });
985
+ if (groupPrivilege && groupPrivilege.Status === 'Active') {
986
+ continue;
987
+ }
988
+ let entityValueBefore = {};
989
+ let entityValueAfter = {};
990
+ let action = activity_history_1.ActionEnum.CREATE;
991
+ let description = 'Create Group Privilege';
992
+ let entityId = null;
993
+ if (groupPrivilege && groupPrivilege.Status !== 'Active') {
994
+ entityValueBefore = {
995
+ GroupCode: groupPrivilege.GroupCode,
996
+ SystemPrivilegeId: groupPrivilege.SystemPrivilegeId,
997
+ Status: groupPrivilege.Status,
998
+ CreatedById: groupPrivilege.CreatedById,
999
+ CreatedAt: groupPrivilege.CreatedAt,
1000
+ UpdatedById: groupPrivilege.UpdatedById,
1001
+ UpdatedAt: groupPrivilege.UpdatedAt,
1002
+ };
1003
+ const updatedPayload = {
1004
+ Status: 'Active',
1005
+ UpdatedById: loginUser.UserId,
1006
+ UpdatedAt: new Date(),
1007
+ };
1008
+ const data = yield Group._GroupPrivilegeRepo.findOne({
1009
+ where: {
1010
+ GroupCode,
1011
+ SystemPrivilegeId,
1012
+ },
1013
+ include: [
1014
+ {
1015
+ model: system_privilege_entity_1.default,
1016
+ },
1017
+ ],
1018
+ transaction: dbTransaction,
1019
+ });
1020
+ data.Status = 'Active';
1021
+ data.UpdatedById = updatedPayload.UpdatedById;
1022
+ data.UpdatedAt = updatedPayload.UpdatedAt;
1023
+ yield data.save({ transaction: dbTransaction });
1024
+ entityValueAfter = {
1025
+ GroupCode: groupPrivilege.GroupCode,
1026
+ SystemPrivilegeId: groupPrivilege.SystemPrivilegeId,
1027
+ Status: updatedPayload.Status,
1028
+ CreatedById: groupPrivilege.CreatedById,
1029
+ CreatedAt: groupPrivilege.CreatedAt,
1030
+ UpdatedById: updatedPayload.UpdatedById,
1031
+ UpdatedAt: updatedPayload.UpdatedAt,
1032
+ };
1033
+ action = activity_history_1.ActionEnum.UPDATE;
1034
+ description = 'Update Group Privilege';
1035
+ entityId = groupPrivilege.GroupPrivilegeId;
1036
+ }
1037
+ else {
1038
+ const newGroupPrivilege = yield group_privilege_1.GroupPrivilege.init(dbTransaction);
1039
+ newGroupPrivilege.setAttributes({
1040
+ GroupCode,
1041
+ SystemPrivilegeId,
1042
+ Status: 'Active',
1043
+ CreatedById: loginUser.UserId,
1044
+ CreatedAt: new Date(),
1045
+ UpdatedById: loginUser.UserId,
1046
+ UpdatedAt: new Date(),
1047
+ });
1048
+ entityValueAfter = {
1049
+ GroupCode: newGroupPrivilege.GroupCode,
1050
+ SystemPrivilegeId: newGroupPrivilege.SystemPrivilegeId,
1051
+ Status: newGroupPrivilege.Status,
1052
+ CreatedById: newGroupPrivilege.CreatedById,
1053
+ CreatedAt: newGroupPrivilege.CreatedAt,
1054
+ UpdatedById: newGroupPrivilege.UpdatedById,
1055
+ UpdatedAt: newGroupPrivilege.UpdatedAt,
1056
+ };
1057
+ const groupPrivilege = yield Group._GroupPrivilegeRepo.create(entityValueAfter, {
1058
+ transaction: dbTransaction,
1059
+ });
1060
+ action = activity_history_1.ActionEnum.CREATE;
1061
+ description = 'Create Group Privilege';
1062
+ entityId = groupPrivilege.GroupPrivilegeId;
1063
+ }
1064
+ const activity = new activity_history_1.Activity();
1065
+ activity.ActivityId = activity.createId();
1066
+ activity.Action = action;
1067
+ activity.Description = description;
1068
+ activity.EntityType = 'GroupPrivilege';
1069
+ activity.EntityId = entityId;
1070
+ activity.EntityValueBefore = JSON.stringify(entityValueBefore);
1071
+ activity.EntityValueAfter = JSON.stringify(entityValueAfter);
1072
+ yield activity.create(loginUser.ObjectId, dbTransaction);
1073
+ }
1074
+ return 'Successfully added.';
1075
+ }
1076
+ catch (error) {
1077
+ throw error;
1078
+ }
1079
+ });
1080
+ }
1081
+ static deleteGroupPrivilege(loginUser, dbTransaction, GroupCode, SystemPrivilegeIds) {
1082
+ return __awaiter(this, void 0, void 0, function* () {
1083
+ try {
1084
+ const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
1085
+ const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'GROUP_PRIVILEGE_DELETE');
1086
+ if (!isPrivileged) {
1087
+ throw new general_1.ClassError('Group', 'GroupErrMsg06', 'You do not have the privilege to delete group privileges');
1088
+ }
1089
+ for (const SystemPrivilegeId of SystemPrivilegeIds) {
1090
+ const groupPrivilege = yield Group._GroupPrivilegeRepo.findOne({
1091
+ where: {
1092
+ GroupCode,
1093
+ SystemPrivilegeId,
1094
+ },
1095
+ include: [
1096
+ {
1097
+ model: system_privilege_entity_1.default,
1098
+ },
1099
+ ],
1100
+ transaction: dbTransaction,
1101
+ });
1102
+ if (!groupPrivilege) {
1103
+ throw new general_1.ClassError('Group', 'GroupErrMsg14', 'GroupPrivilege not found.');
1104
+ }
1105
+ const entityValueBefore = {
1106
+ GroupCode: groupPrivilege.GroupCode,
1107
+ SystemPrivilegeId: groupPrivilege.SystemPrivilegeId,
1108
+ Status: groupPrivilege.Status,
1109
+ CreatedById: groupPrivilege.CreatedById,
1110
+ CreatedAt: groupPrivilege.CreatedAt,
1111
+ UpdatedById: groupPrivilege.UpdatedById,
1112
+ UpdatedAt: groupPrivilege.UpdatedAt,
1113
+ };
1114
+ yield Group._GroupPrivilegeRepo.delete(GroupCode, SystemPrivilegeId, dbTransaction);
1115
+ const activity = new activity_history_1.Activity();
1116
+ activity.ActivityId = activity.createId();
1117
+ activity.Action = activity_history_1.ActionEnum.DELETE;
1118
+ activity.Description = 'DELETE Group Privilege';
1119
+ activity.EntityType = 'GroupPrivilege';
1120
+ activity.EntityId = groupPrivilege.GroupPrivilegeId.toString();
1121
+ activity.EntityValueBefore = JSON.stringify(entityValueBefore);
1122
+ activity.EntityValueAfter = JSON.stringify({});
1123
+ yield activity.create(loginUser.ObjectId, dbTransaction);
1124
+ }
1125
+ return 'Successfully deleted.';
1126
+ }
1127
+ catch (error) {
1128
+ throw error;
1129
+ }
1130
+ });
1131
+ }
1132
+ static getHierarchy(loginUser, dbTransaction, Status, Type, ParentGroupCode) {
1133
+ return __awaiter(this, void 0, void 0, function* () {
1134
+ const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
1135
+ const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'GROUP_VIEW');
1136
+ if (!isPrivileged) {
1137
+ throw new general_1.ClassError('Group', 'GroupErrMsg04', 'User is not privileged to view group');
1138
+ }
1139
+ const queryObj = {};
1140
+ let options = {
1141
+ transaction: dbTransaction,
1142
+ };
1143
+ const search = {
1144
+ Status: Status ? Status : 'Active',
1145
+ Type: Type,
1146
+ ParentGroupCode: ParentGroupCode,
1147
+ };
1148
+ if (search) {
1149
+ Object.entries(search).forEach(([key, value]) => {
1150
+ if (value) {
1151
+ queryObj[key] = {
1152
+ [sequelize_1.Op.substring]: value,
1153
+ };
1154
+ }
1155
+ });
1156
+ options = Object.assign(Object.assign({}, options), { where: queryObj });
1157
+ const result = yield Group._Repo.findAll(options);
1158
+ const data = result.map((group) => new Group(group.get({ plain: true })));
1159
+ const generateTree = (groups) => __awaiter(this, void 0, void 0, function* () {
1160
+ const data = groups.map((group) => {
1161
+ return {
1162
+ GroupCode: group.ObjectId,
1163
+ Name: group.Name,
1164
+ Description: group.Description,
1165
+ Type: group.Type,
1166
+ ParentGroupCode: group.ParentGroupCode,
1167
+ InheritParentPrivilegeYN: group.InheritParentPrivilegeYN,
1168
+ InheritParentSystemAccessYN: group.InheritParentSystemAccessYN,
1169
+ Path: group._Path,
1170
+ Status: group.Status,
1171
+ CreatedById: group._CreatedById,
1172
+ CreatedAt: group._CreatedAt,
1173
+ UpdatedById: group._UpdatedById,
1174
+ UpdatedAt: group._UpdatedAt,
1175
+ childrens: [],
1176
+ };
1177
+ });
1178
+ const groupMap = {};
1179
+ data.forEach((group) => {
1180
+ group.childrens = [];
1181
+ groupMap[group.GroupCode] = group;
1182
+ });
1183
+ const tree = [];
1184
+ data.forEach((group) => {
1185
+ if (group.ParentGroupCode) {
1186
+ const parent = groupMap[group.ParentGroupCode];
1187
+ if (parent) {
1188
+ parent.childrens.push(group);
1189
+ }
1190
+ }
1191
+ else {
1192
+ tree.push(group);
1193
+ }
1194
+ });
1195
+ return tree;
1196
+ });
1197
+ const tree = yield generateTree(data);
1198
+ return tree;
1199
+ }
1200
+ });
1201
+ }
1202
+ static getGroupsWithReportingUser(loginUser, dbTransaction, whereOptions) {
1203
+ return __awaiter(this, void 0, void 0, function* () {
1204
+ try {
1205
+ const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
1206
+ const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'GROUP_VIEW');
1207
+ if (!isPrivileged) {
1208
+ throw new general_1.ClassError('Group', 'GroupErrMsg04', 'User is not privileged to view group');
1209
+ }
1210
+ const options = {
1211
+ where: whereOptions,
1212
+ include: [
1213
+ {
1214
+ model: group_reporting_user_entity_1.default,
1215
+ where: { Status: 'Active' },
1216
+ include: [
1217
+ {
1218
+ model: user_entity_1.default,
1219
+ as: 'User',
1220
+ attributes: ['UserId', 'FullName'],
1221
+ },
1222
+ ],
1223
+ },
1224
+ ],
1225
+ transaction: dbTransaction,
1226
+ };
1227
+ const groups = yield Group._Repo.findAll(options);
1228
+ return groups;
1229
+ }
1230
+ catch (error) {
1231
+ throw error;
1232
+ }
1233
+ });
1234
+ }
1235
+ }
1236
+ exports.Group = Group;
1237
+ Group._Repo = new group_repository_1.GroupRepository();
1238
+ Group._GroupSystemAccessRepo = new group_system_access_repository_1.GroupSystemAccessRepository();
1239
+ Group._GroupPrivilegeRepo = new group_privilege_repository_1.GroupPrivilegeRepository();
1240
+ Group._GroupObjectPrivilegeRepo = new group_object_privilege_repository_1.GroupObjectPrivilegeRepository();
1241
1241
  //# sourceMappingURL=group.js.map