rez_core 6.1.4 → 6.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (427) hide show
  1. package/.prettierrc +3 -3
  2. package/README.md +99 -99
  3. package/dist/migrations/1732612800000-AddEntityJsonGinIndex.js +10 -10
  4. package/dist/module/auth/guards/role.guard.js +3 -3
  5. package/dist/module/enterprise/service/organization.service.d.ts +1 -1
  6. package/dist/module/enterprise/service/organization.service.js +3 -4
  7. package/dist/module/enterprise/service/organization.service.js.map +1 -1
  8. package/dist/module/filter/repository/saved-filter.repository.js +2 -0
  9. package/dist/module/filter/repository/saved-filter.repository.js.map +1 -1
  10. package/dist/module/filter/service/filter.service.js +25 -21
  11. package/dist/module/filter/service/filter.service.js.map +1 -1
  12. package/dist/module/filter/service/flatjson-filter.service.js +5 -5
  13. package/dist/module/integration/examples/usage.example.js +9 -9
  14. package/dist/module/integration/service/integration.service.d.ts +5 -1
  15. package/dist/module/integration/service/integration.service.js +11 -1
  16. package/dist/module/integration/service/integration.service.js.map +1 -1
  17. package/dist/module/integration/service/oauth.service.js +2 -0
  18. package/dist/module/integration/service/oauth.service.js.map +1 -1
  19. package/dist/module/integration/strategies/email/gmail-api.strategy.js +23 -7
  20. package/dist/module/integration/strategies/email/gmail-api.strategy.js.map +1 -1
  21. package/dist/module/integration/strategies/email/sendgrid-api.strategy.js +8 -5
  22. package/dist/module/integration/strategies/email/sendgrid-api.strategy.js.map +1 -1
  23. package/dist/module/meta/controller/media.controller.d.ts +6 -0
  24. package/dist/module/meta/controller/media.controller.js +27 -0
  25. package/dist/module/meta/controller/media.controller.js.map +1 -1
  26. package/dist/module/meta/entity/media-data.entity.d.ts +2 -0
  27. package/dist/module/meta/entity/media-data.entity.js +8 -0
  28. package/dist/module/meta/entity/media-data.entity.js.map +1 -1
  29. package/dist/module/meta/repository/attribute-master.repository.js +8 -8
  30. package/dist/module/meta/service/entity-dynamic.service.js +18 -18
  31. package/dist/module/meta/service/entity-dynamic.service.js.map +1 -1
  32. package/dist/module/meta/service/media-data.service.d.ts +3 -0
  33. package/dist/module/meta/service/media-data.service.js +16 -6
  34. package/dist/module/meta/service/media-data.service.js.map +1 -1
  35. package/dist/module/meta/service/populate-meta.service.js +8 -2
  36. package/dist/module/meta/service/populate-meta.service.js.map +1 -1
  37. package/dist/module/meta/service/resolver.service.js +39 -15
  38. package/dist/module/meta/service/resolver.service.js.map +1 -1
  39. package/dist/module/module/repository/menu.repository.js +4 -4
  40. package/dist/module/user/controller/login.controller.js +19 -19
  41. package/dist/module/user/controller/login.controller.js.map +1 -1
  42. package/dist/module/user/service/user-session.service.js +1 -0
  43. package/dist/module/user/service/user-session.service.js.map +1 -1
  44. package/dist/module/workflow/repository/action.repository.js +2 -2
  45. package/dist/module/workflow/repository/stage.repository.js +8 -8
  46. package/dist/module/workflow/service/action-template-mapping.service.js +2 -2
  47. package/dist/module/workflow/service/action.service.js +5 -5
  48. package/dist/module/workflow/service/entity-modification.service.js +2 -2
  49. package/dist/module/workflow/service/populate-workflow.service.js +5 -0
  50. package/dist/module/workflow/service/populate-workflow.service.js.map +1 -1
  51. package/dist/module/workflow/service/task.service.js +8 -8
  52. package/dist/module/workflow-automation/service/schedule-handler.service.js +9 -9
  53. package/dist/tsconfig.build.tsbuildinfo +1 -1
  54. package/dist/utils/service/reflection-helper.service.js +2 -2
  55. package/docs/modules/event-driven-integration-design.md +91 -91
  56. package/docs/modules/integration.md +250 -250
  57. package/eslint.config.mjs +34 -34
  58. package/nest-cli.json +14 -14
  59. package/package.json +125 -125
  60. package/src/app.controller.ts +13 -13
  61. package/src/app.module.ts +68 -68
  62. package/src/app.service.ts +8 -8
  63. package/src/config/bull.config.ts +69 -69
  64. package/src/config/config.module.ts +17 -17
  65. package/src/config/database.config.ts +48 -48
  66. package/src/constant/global.constant.ts +67 -67
  67. package/src/core.module.ts +94 -94
  68. package/src/decorators/roles.decorator.ts +7 -7
  69. package/src/dtos/response.dto.ts +6 -6
  70. package/src/dtos/response.ts +5 -5
  71. package/src/index.ts +1 -1
  72. package/src/migrations/1732612800000-AddEntityJsonGinIndex.ts +41 -41
  73. package/src/module/auth/auth.module.ts +49 -49
  74. package/src/module/auth/controller/auth.controller.ts +28 -28
  75. package/src/module/auth/guards/google-auth.guard.ts +9 -9
  76. package/src/module/auth/guards/jwt.guard.ts +22 -22
  77. package/src/module/auth/guards/role.guard.ts +68 -68
  78. package/src/module/auth/services/auth.service.ts +56 -56
  79. package/src/module/auth/services/jwt.service.ts +11 -11
  80. package/src/module/auth/strategies/google.strategy.ts +54 -54
  81. package/src/module/auth/strategies/jwt.strategy.ts +58 -58
  82. package/src/module/auth/strategies/local.strategy.ts +13 -13
  83. package/src/module/dashboard/controller/dashboard.controller.ts +38 -38
  84. package/src/module/dashboard/dashboard.module.ts +21 -21
  85. package/src/module/dashboard/entity/dashboard_page_data.entity.ts +27 -27
  86. package/src/module/dashboard/entity/widget_master.entity.ts +18 -18
  87. package/src/module/dashboard/repository/dashboard.repository.ts +49 -49
  88. package/src/module/dashboard/service/dashboard.service.ts +72 -72
  89. package/src/module/enterprise/controller/organization.controller.ts +36 -36
  90. package/src/module/enterprise/enterprise.module.ts +45 -45
  91. package/src/module/enterprise/entity/enterprise.entity.ts +37 -37
  92. package/src/module/enterprise/entity/organization-app-mapping.entity.ts +13 -13
  93. package/src/module/enterprise/entity/organization.entity.ts +92 -92
  94. package/src/module/enterprise/repository/enterprise.repository.ts +31 -31
  95. package/src/module/enterprise/repository/organization.repository.ts +26 -26
  96. package/src/module/enterprise/repository/school.repository.ts +289 -289
  97. package/src/module/enterprise/service/brand.service.ts +5 -5
  98. package/src/module/enterprise/service/enterprise.service.ts +16 -16
  99. package/src/module/enterprise/service/organization-app-mapping.service.ts +4 -4
  100. package/src/module/enterprise/service/organization.service.ts +146 -145
  101. package/src/module/entity_json/controller/entity_json.controller.ts +60 -60
  102. package/src/module/entity_json/docs/FlatJson_Filterin_System.md +2803 -2803
  103. package/src/module/entity_json/entity/entityJson.entity.ts +42 -42
  104. package/src/module/entity_json/entity_json.module.ts +22 -22
  105. package/src/module/entity_json/service/entityJson.repository.ts +37 -37
  106. package/src/module/entity_json/service/entity_json.service.ts +486 -486
  107. package/src/module/export/controller/export.controller.ts +83 -83
  108. package/src/module/export/export.module.ts +14 -14
  109. package/src/module/export/service/export.service.ts +105 -105
  110. package/src/module/filter/controller/filter.controller.ts +87 -87
  111. package/src/module/filter/dto/filter-request.dto.ts +39 -39
  112. package/src/module/filter/entity/saved-filter-detail.entity.ts +41 -41
  113. package/src/module/filter/entity/saved-filter-master.entity.ts +35 -35
  114. package/src/module/filter/filter.module.ts +41 -41
  115. package/src/module/filter/repository/saved-filter.repository.ts +249 -247
  116. package/src/module/filter/repository/saved.filter-detail.repository.ts +19 -19
  117. package/src/module/filter/service/filter-evaluator.service.ts +82 -82
  118. package/src/module/filter/service/filter.service.ts +1406 -1370
  119. package/src/module/filter/service/flatjson-filter.service.ts +903 -903
  120. package/src/module/filter/service/saved-filter.service.ts +154 -154
  121. package/src/module/filter/test/flatjson-filter.service.spec.ts +415 -415
  122. package/src/module/ics/controller/ics.controller.ts +21 -21
  123. package/src/module/ics/dto/ics.dto.ts +55 -55
  124. package/src/module/ics/ics.module.ts +13 -13
  125. package/src/module/ics/service/ics.service.ts +57 -57
  126. package/src/module/integration/controller/calender-event.controller.ts +31 -31
  127. package/src/module/integration/controller/integration.controller.ts +662 -662
  128. package/src/module/integration/controller/wrapper.controller.ts +37 -37
  129. package/src/module/integration/dto/create-config.dto.ts +526 -526
  130. package/src/module/integration/entity/integration-config.entity.ts +112 -112
  131. package/src/module/integration/entity/integration-entity-mapper.entity.ts +14 -14
  132. package/src/module/integration/entity/integration-source.entity.ts +17 -17
  133. package/src/module/integration/entity/user-integration.entity.ts +71 -71
  134. package/src/module/integration/examples/usage.example.ts +338 -338
  135. package/src/module/integration/factories/base.factory.ts +7 -7
  136. package/src/module/integration/factories/email.factory.ts +49 -49
  137. package/src/module/integration/factories/integration.factory.ts +121 -121
  138. package/src/module/integration/factories/sms.factory.ts +51 -51
  139. package/src/module/integration/factories/telephone.factory.ts +41 -41
  140. package/src/module/integration/factories/whatsapp.factory.ts +56 -56
  141. package/src/module/integration/integration.module.ts +110 -110
  142. package/src/module/integration/service/calendar-event.service.ts +118 -118
  143. package/src/module/integration/service/integration-entity-mapper.service.ts +17 -17
  144. package/src/module/integration/service/integration-queue.service.ts +229 -229
  145. package/src/module/integration/service/integration.service.ts +2653 -2639
  146. package/src/module/integration/service/oauth.service.ts +226 -224
  147. package/src/module/integration/service/wrapper.service.ts +754 -754
  148. package/src/module/integration/strategies/email/gmail-api.strategy.ts +307 -281
  149. package/src/module/integration/strategies/email/outlook-api.strategy.ts +44 -44
  150. package/src/module/integration/strategies/email/outlook.strategy.ts +64 -64
  151. package/src/module/integration/strategies/email/sendgrid-api.strategy.ts +263 -260
  152. package/src/module/integration/strategies/integration.strategy.ts +97 -97
  153. package/src/module/integration/strategies/sms/gupshup-sms.strategy.ts +146 -146
  154. package/src/module/integration/strategies/sms/msg91-sms.strategy.ts +164 -164
  155. package/src/module/integration/strategies/sms/tubelight-sms.strategy.ts +163 -163
  156. package/src/module/integration/strategies/telephone/ozonetel-voice.strategy.ts +238 -238
  157. package/src/module/integration/strategies/telephone/tubelight-voice.strategy.ts +210 -210
  158. package/src/module/integration/strategies/whatsapp/gupshup-whatsapp.strategy.ts +359 -359
  159. package/src/module/integration/strategies/whatsapp/tubelight-whatsapp.strategy.ts +372 -372
  160. package/src/module/integration/strategies/whatsapp/whatsapp-cloud.strategy.ts +403 -403
  161. package/src/module/integration/strategies/whatsapp/whatsapp.strategy.ts +57 -57
  162. package/src/module/layout/controller/layout.controller.ts +47 -47
  163. package/src/module/layout/entity/header-items.entity.ts +28 -28
  164. package/src/module/layout/entity/header-section.entity.ts +19 -19
  165. package/src/module/layout/layout.module.ts +21 -21
  166. package/src/module/layout/repository/header-items.repository.ts +18 -18
  167. package/src/module/layout/repository/header-section.repository.ts +22 -22
  168. package/src/module/layout/service/header-section.service.ts +25 -25
  169. package/src/module/layout_preference/controller/layout_preference.controller.ts +76 -76
  170. package/src/module/layout_preference/entity/layout_preference.entity.ts +28 -28
  171. package/src/module/layout_preference/layout_preference.module.ts +22 -22
  172. package/src/module/layout_preference/repository/layout_preference.repository.ts +65 -65
  173. package/src/module/layout_preference/service/layout_preference.service.ts +191 -191
  174. package/src/module/lead/controller/lead.controller.ts +30 -30
  175. package/src/module/lead/lead.module.ts +14 -14
  176. package/src/module/lead/repository/lead.repository.ts +41 -41
  177. package/src/module/lead/service/lead.service.ts +54 -54
  178. package/src/module/linked_attributes/controller/linked_attributes.controller.ts +137 -137
  179. package/src/module/linked_attributes/dto/create-linked-attribute-smart.dto.ts +54 -54
  180. package/src/module/linked_attributes/entity/linked_attribute.entity.ts +51 -51
  181. package/src/module/linked_attributes/linked_attributes.module.ts +23 -23
  182. package/src/module/linked_attributes/repository/linked_attribute.repository.ts +12 -12
  183. package/src/module/linked_attributes/service/linked_attributes.service.ts +648 -648
  184. package/src/module/linked_attributes/test/linked-attributes.service.spec.ts +244 -244
  185. package/src/module/listmaster/controller/list-master.controller.ts +230 -230
  186. package/src/module/listmaster/entity/list-master-items.entity.ts +43 -43
  187. package/src/module/listmaster/entity/list-master.entity.ts +33 -33
  188. package/src/module/listmaster/listmaster.module.ts +46 -46
  189. package/src/module/listmaster/repository/list-master-items.repository.ts +173 -173
  190. package/src/module/listmaster/repository/list-master.repository.ts +56 -56
  191. package/src/module/listmaster/service/list-master-engine.ts +19 -19
  192. package/src/module/listmaster/service/list-master-extension.interface.ts +4 -4
  193. package/src/module/listmaster/service/list-master-item.service.ts +280 -280
  194. package/src/module/listmaster/service/list-master-registry.ts +15 -15
  195. package/src/module/listmaster/service/list-master.service.ts +527 -527
  196. package/src/module/mapper/controller/field-mapper.controller.ts +76 -76
  197. package/src/module/mapper/controller/mapper.controller.ts +20 -20
  198. package/src/module/mapper/dto/field-mapper.dto.ts +14 -14
  199. package/src/module/mapper/entity/field-lovs.entity.ts +19 -19
  200. package/src/module/mapper/entity/field-mapper.entity.ts +53 -53
  201. package/src/module/mapper/entity/mapper.entity.ts +16 -16
  202. package/src/module/mapper/mapper.module.ts +35 -35
  203. package/src/module/mapper/repository/field-lovs.repository.ts +35 -35
  204. package/src/module/mapper/repository/field-mapper.repository.ts +42 -42
  205. package/src/module/mapper/repository/mapper.repository.ts +32 -32
  206. package/src/module/mapper/service/field-mapper.service.ts +269 -269
  207. package/src/module/mapper/service/mapper.service.ts +80 -80
  208. package/src/module/master/controller/master.controller.ts +74 -74
  209. package/src/module/master/service/master.service.ts +484 -484
  210. package/src/module/meta/controller/app-master.controller.ts +38 -38
  211. package/src/module/meta/controller/attribute-master.controller.ts +96 -96
  212. package/src/module/meta/controller/entity-dynamic.controller.ts +125 -125
  213. package/src/module/meta/controller/entity-master.controller.ts +41 -41
  214. package/src/module/meta/controller/entity-relation.controller.ts +36 -36
  215. package/src/module/meta/controller/entity.controller.ts +308 -308
  216. package/src/module/meta/controller/entity.public.controller.ts +75 -75
  217. package/src/module/meta/controller/media.controller.ts +167 -135
  218. package/src/module/meta/controller/meta.controller.ts +101 -101
  219. package/src/module/meta/controller/view-master.controller.ts +79 -79
  220. package/src/module/meta/dto/entity-list-data.dto.ts +6 -6
  221. package/src/module/meta/dto/entity-tab.dto.ts +4 -4
  222. package/src/module/meta/dto/entity-table.dto.ts +12 -12
  223. package/src/module/meta/entity/app-master.entity.ts +37 -37
  224. package/src/module/meta/entity/attribute-master.entity.ts +92 -92
  225. package/src/module/meta/entity/base-entity.entity.ts +75 -75
  226. package/src/module/meta/entity/entity-master.entity.ts +91 -91
  227. package/src/module/meta/entity/entity-relation-data.entity.ts +29 -29
  228. package/src/module/meta/entity/entity-relation.entity.ts +23 -23
  229. package/src/module/meta/entity/entity-table-column.entity.ts +61 -61
  230. package/src/module/meta/entity/entity-table.entity.ts +50 -50
  231. package/src/module/meta/entity/media-data.entity.ts +38 -32
  232. package/src/module/meta/entity/preference.entity.ts +62 -62
  233. package/src/module/meta/entity/view-master.entity.ts +41 -41
  234. package/src/module/meta/entity.module.ts +165 -165
  235. package/src/module/meta/repository/app-master.repository.ts +20 -20
  236. package/src/module/meta/repository/attribute-master.repository.ts +164 -164
  237. package/src/module/meta/repository/entity-attribute-update.repository.ts +48 -48
  238. package/src/module/meta/repository/entity-master.repository.ts +120 -120
  239. package/src/module/meta/repository/entity-relation.repository.ts +22 -22
  240. package/src/module/meta/repository/entity-table-column.repository.ts +39 -39
  241. package/src/module/meta/repository/entity-table.repository.ts +53 -53
  242. package/src/module/meta/repository/media-data.repository.ts +50 -50
  243. package/src/module/meta/repository/preference.repository.ts +20 -20
  244. package/src/module/meta/repository/user-app-mapping.repository.ts +28 -28
  245. package/src/module/meta/repository/view-master.repository.ts +42 -42
  246. package/src/module/meta/service/app-master.service.ts +37 -37
  247. package/src/module/meta/service/attribute-master.service.ts +160 -160
  248. package/src/module/meta/service/common.service.ts +9 -9
  249. package/src/module/meta/service/entity-attribute-update.service.ts +26 -26
  250. package/src/module/meta/service/entity-dynamic.service.ts +835 -824
  251. package/src/module/meta/service/entity-master.service.ts +172 -172
  252. package/src/module/meta/service/entity-realation-data.service.ts +9 -9
  253. package/src/module/meta/service/entity-relation.service.ts +78 -78
  254. package/src/module/meta/service/entity-service-impl.service.ts +389 -389
  255. package/src/module/meta/service/entity-table-column.service.ts +26 -26
  256. package/src/module/meta/service/entity-table.service.ts +171 -171
  257. package/src/module/meta/service/entity-validation.service.ts +188 -188
  258. package/src/module/meta/service/entity.service.ts +48 -48
  259. package/src/module/meta/service/field-group.service.ts +103 -103
  260. package/src/module/meta/service/media-data.service.ts +610 -591
  261. package/src/module/meta/service/populate-meta.service.ts +228 -222
  262. package/src/module/meta/service/preference.service.ts +16 -16
  263. package/src/module/meta/service/resolver.service.ts +347 -319
  264. package/src/module/meta/service/section-master.service.ts +104 -104
  265. package/src/module/meta/service/update-form-json.service.ts +22 -22
  266. package/src/module/meta/service/user-app-mapping.service.ts +17 -17
  267. package/src/module/meta/service/view-master.service.ts +127 -127
  268. package/src/module/microservice-client/microservice-clients.module.ts +13 -13
  269. package/src/module/microservice-client/service/microservice-client-factory.ts +37 -37
  270. package/src/module/microservice-client/service/microservice-clients.ts +4 -4
  271. package/src/module/module/controller/menu.controller.ts +15 -15
  272. package/src/module/module/controller/module-access.controller.ts +133 -133
  273. package/src/module/module/entity/menu.entity.ts +43 -43
  274. package/src/module/module/entity/module-access.entity.ts +25 -25
  275. package/src/module/module/entity/module-action.entity.ts +17 -17
  276. package/src/module/module/entity/module.entity.ts +52 -52
  277. package/src/module/module/module.module.ts +42 -42
  278. package/src/module/module/repository/menu.repository.ts +186 -186
  279. package/src/module/module/repository/module-access.repository.ts +344 -344
  280. package/src/module/module/service/menu.service.ts +82 -82
  281. package/src/module/module/service/module-access.service.ts +189 -189
  282. package/src/module/notification/controller/notification.controller.ts +58 -58
  283. package/src/module/notification/controller/otp.controller.ts +117 -117
  284. package/src/module/notification/entity/notification.entity.ts +26 -26
  285. package/src/module/notification/entity/otp.entity.ts +28 -28
  286. package/src/module/notification/firebase-admin.config.ts +22 -22
  287. package/src/module/notification/notification.module.ts +71 -71
  288. package/src/module/notification/repository/notification.repository.ts +33 -33
  289. package/src/module/notification/repository/otp.repository.ts +27 -27
  290. package/src/module/notification/service/email.service.ts +127 -127
  291. package/src/module/notification/service/notification.service.ts +146 -146
  292. package/src/module/notification/service/otp.service.ts +133 -133
  293. package/src/module/third-party-module/entity/third-party-api-registry.entity.ts +52 -52
  294. package/src/module/third-party-module/repository/third-party-api-registry.repository.ts +20 -20
  295. package/src/module/third-party-module/service/api-registry.service.ts +13 -13
  296. package/src/module/third-party-module/third-party.module.ts +12 -12
  297. package/src/module/user/controller/login.controller.ts +199 -198
  298. package/src/module/user/controller/user.controller.ts +40 -40
  299. package/src/module/user/dto/create-user.dto.ts +62 -62
  300. package/src/module/user/dto/update-user.dto.ts +4 -4
  301. package/src/module/user/entity/role.entity.ts +33 -33
  302. package/src/module/user/entity/user-role-mapping.entity.ts +38 -38
  303. package/src/module/user/entity/user-session.entity.ts +73 -73
  304. package/src/module/user/entity/user.entity.ts +62 -62
  305. package/src/module/user/repository/role.repository.ts +96 -96
  306. package/src/module/user/repository/user-role-mapping.repository.ts +126 -126
  307. package/src/module/user/repository/user.repository.ts +50 -50
  308. package/src/module/user/repository/userSession.repository.ts +33 -33
  309. package/src/module/user/service/login.service.ts +326 -326
  310. package/src/module/user/service/role.service.ts +197 -197
  311. package/src/module/user/service/user-role-mapping.service.ts +98 -98
  312. package/src/module/user/service/user-session.service.ts +201 -200
  313. package/src/module/user/service/user.service.ts +368 -368
  314. package/src/module/user/user.module.ts +65 -65
  315. package/src/module/workflow/controller/action-category.controller.ts +54 -54
  316. package/src/module/workflow/controller/action-resource-mapping.controller.ts +23 -23
  317. package/src/module/workflow/controller/action-template-mapping.controller.ts +35 -35
  318. package/src/module/workflow/controller/action.controller.ts +111 -111
  319. package/src/module/workflow/controller/activity-log.controller.ts +55 -55
  320. package/src/module/workflow/controller/comm-template.controller.ts +43 -43
  321. package/src/module/workflow/controller/entity-modification.controller.ts +35 -35
  322. package/src/module/workflow/controller/form-master.controller.ts +43 -43
  323. package/src/module/workflow/controller/stage-group.controller.ts +49 -49
  324. package/src/module/workflow/controller/stage.controller.ts +51 -51
  325. package/src/module/workflow/controller/task.controller.ts +77 -77
  326. package/src/module/workflow/controller/workflow-list-master.controller.ts +44 -44
  327. package/src/module/workflow/controller/workflow-meta.controller.ts +80 -80
  328. package/src/module/workflow/controller/workflow.controller.ts +67 -67
  329. package/src/module/workflow/entity/action-category.entity.ts +38 -38
  330. package/src/module/workflow/entity/action-data.entity.ts +55 -55
  331. package/src/module/workflow/entity/action-resources-mapping.entity.ts +29 -29
  332. package/src/module/workflow/entity/action-template-mapping.entity.ts +17 -17
  333. package/src/module/workflow/entity/action.entity.ts +53 -53
  334. package/src/module/workflow/entity/activity-log.entity.ts +43 -43
  335. package/src/module/workflow/entity/comm-template.entity.ts +43 -43
  336. package/src/module/workflow/entity/entity-modification.entity.ts +38 -38
  337. package/src/module/workflow/entity/form.entity.ts +25 -25
  338. package/src/module/workflow/entity/stage-action-mapping.entity.ts +17 -17
  339. package/src/module/workflow/entity/stage-group.entity.ts +23 -23
  340. package/src/module/workflow/entity/stage-movement-data.entity.ts +38 -38
  341. package/src/module/workflow/entity/stage.entity.ts +20 -20
  342. package/src/module/workflow/entity/task-data.entity.ts +88 -88
  343. package/src/module/workflow/entity/template-attach-mapper.entity.ts +30 -30
  344. package/src/module/workflow/entity/workflow-data.entity.ts +11 -11
  345. package/src/module/workflow/entity/workflow-level-mapping.entity.ts +18 -18
  346. package/src/module/workflow/entity/workflow.entity.ts +20 -20
  347. package/src/module/workflow/repository/action-category.repository.ts +79 -79
  348. package/src/module/workflow/repository/action-data.repository.ts +354 -354
  349. package/src/module/workflow/repository/action.repository.ts +339 -339
  350. package/src/module/workflow/repository/activity-log.repository.ts +148 -148
  351. package/src/module/workflow/repository/comm-template.repository.ts +157 -157
  352. package/src/module/workflow/repository/form-master.repository.ts +50 -50
  353. package/src/module/workflow/repository/stage-group.repository.ts +186 -186
  354. package/src/module/workflow/repository/stage-movement.repository.ts +217 -217
  355. package/src/module/workflow/repository/stage.repository.ts +160 -160
  356. package/src/module/workflow/repository/task.repository.ts +156 -156
  357. package/src/module/workflow/repository/workflow.repository.ts +42 -42
  358. package/src/module/workflow/service/action-category.service.ts +33 -33
  359. package/src/module/workflow/service/action-data.service.ts +62 -62
  360. package/src/module/workflow/service/action-resources-mapping.service.ts +10 -10
  361. package/src/module/workflow/service/action-template-mapping.service.ts +137 -137
  362. package/src/module/workflow/service/action.service.ts +302 -302
  363. package/src/module/workflow/service/activity-log.service.ts +107 -107
  364. package/src/module/workflow/service/comm-template.service.ts +181 -181
  365. package/src/module/workflow/service/entity-modification.service.ts +61 -61
  366. package/src/module/workflow/service/form-master.service.ts +35 -35
  367. package/src/module/workflow/service/populate-workflow.service.ts +325 -320
  368. package/src/module/workflow/service/stage-action-mapping.service.ts +5 -5
  369. package/src/module/workflow/service/stage-group.service.ts +325 -325
  370. package/src/module/workflow/service/stage.service.ts +197 -197
  371. package/src/module/workflow/service/task.service.ts +551 -551
  372. package/src/module/workflow/service/workflow-list-master.service.ts +68 -68
  373. package/src/module/workflow/service/workflow-meta.service.ts +640 -640
  374. package/src/module/workflow/service/workflow.service.ts +213 -213
  375. package/src/module/workflow/workflow.module.ts +180 -180
  376. package/src/module/workflow-automation/SCHEDULING_GUIDE.md +145 -145
  377. package/src/module/workflow-automation/controller/workflow-automation.controller.ts +43 -43
  378. package/src/module/workflow-automation/entity/workflow-automation-action.entity.ts +26 -26
  379. package/src/module/workflow-automation/entity/workflow-automation.entity.ts +40 -40
  380. package/src/module/workflow-automation/interface/action.decorator.ts +7 -7
  381. package/src/module/workflow-automation/interface/action.interface.ts +5 -5
  382. package/src/module/workflow-automation/service/action-registery.service.ts +35 -35
  383. package/src/module/workflow-automation/service/schedule-handler.service.ts +168 -168
  384. package/src/module/workflow-automation/service/workflow-automation-engine.service.ts +219 -219
  385. package/src/module/workflow-automation/service/workflow-automation.service.ts +474 -474
  386. package/src/module/workflow-automation/workflow-automation.module.ts +54 -54
  387. package/src/module/workflow-schedule/INSTALLATION.md +244 -244
  388. package/src/module/workflow-schedule/MULTI_PROJECT_GUIDE.md +196 -196
  389. package/src/module/workflow-schedule/README.md +422 -422
  390. package/src/module/workflow-schedule/constants/schedule.constants.ts +48 -48
  391. package/src/module/workflow-schedule/controller/workflow-schedule.controller.ts +253 -253
  392. package/src/module/workflow-schedule/docs/CLAUDE_CODE_GUIDE.md +510 -510
  393. package/src/module/workflow-schedule/docs/CLAUDE_CODE_PROMPT.md +362 -362
  394. package/src/module/workflow-schedule/docs/RUN_CLAUDE_CODE.sh +68 -68
  395. package/src/module/workflow-schedule/dto/create-schedule.dto.ts +147 -147
  396. package/src/module/workflow-schedule/dto/get-execution-logs.dto.ts +119 -119
  397. package/src/module/workflow-schedule/dto/update-schedule.dto.ts +96 -96
  398. package/src/module/workflow-schedule/entities/scheduled-workflow.entity.ts +148 -148
  399. package/src/module/workflow-schedule/entities/workflow-execution-log.entity.ts +154 -154
  400. package/src/module/workflow-schedule/interfaces/schedule-job-data.interface.ts +53 -53
  401. package/src/module/workflow-schedule/interfaces/workflow-schedule-options.interface.ts +12 -12
  402. package/src/module/workflow-schedule/processors/schedule.processor.ts +620 -620
  403. package/src/module/workflow-schedule/service/workflow-schedule.service.ts +597 -597
  404. package/src/module/workflow-schedule/workflow-schedule.module.ts +67 -67
  405. package/src/resources/dev.properties.yaml +31 -31
  406. package/src/resources/local.properties.yaml +27 -27
  407. package/src/resources/properties.module.ts +12 -12
  408. package/src/resources/properties.yaml.ts +11 -11
  409. package/src/resources/uat.properties.yaml +31 -31
  410. package/src/table.config.ts +135 -135
  411. package/src/utils/dto/excel-data.dto.ts +14 -14
  412. package/src/utils/dto/excelsheet-data.dto.ts +5 -5
  413. package/src/utils/service/base64util.service.ts +18 -18
  414. package/src/utils/service/clockIDGenUtil.service.ts +21 -21
  415. package/src/utils/service/codeGenerator.service.ts +22 -22
  416. package/src/utils/service/dateUtil.service.ts +17 -17
  417. package/src/utils/service/encryptUtil.service.ts +97 -97
  418. package/src/utils/service/excel-helper.service.ts +72 -72
  419. package/src/utils/service/excelUtil.service.ts +15 -15
  420. package/src/utils/service/file-util.service.ts +11 -11
  421. package/src/utils/service/json-util.service.ts +23 -23
  422. package/src/utils/service/loggingUtil.service.ts +88 -88
  423. package/src/utils/service/reflection-helper.service.ts +62 -62
  424. package/src/utils/service/wbsCodeGen.service.ts +8 -8
  425. package/src/utils/utils.module.ts +27 -27
  426. package/tsconfig.build.json +4 -4
  427. package/tsconfig.json +24 -24
@@ -1,486 +1,486 @@
1
- import { Inject, Injectable, forwardRef } from '@nestjs/common';
2
- import { LinkedAttributes } from 'src/module/linked_attributes/entity/linked_attribute.entity';
3
- import { AttributeMaster } from 'src/module/meta/entity/attribute-master.entity';
4
- import { EntityRelation } from 'src/module/meta/entity/entity-relation.entity';
5
- import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service';
6
- import { LoggingService } from 'src/utils/service/loggingUtil.service';
7
- import { DataSource } from 'typeorm';
8
- import { EntityJSONRepository } from './entityJson.repository';
9
- import { FilterService } from '../../filter/service/filter.service';
10
- import { AttributeMasterService } from 'src/module/meta/service/attribute-master.service';
11
- import { ResolverService } from 'src/module/meta/service/resolver.service';
12
-
13
- @Injectable()
14
- export class EntityJSONService {
15
- constructor(
16
- private readonly dataSource: DataSource,
17
- private readonly loggerService: LoggingService,
18
- private readonly EntityJSONRepository: EntityJSONRepository,
19
- @Inject(forwardRef(() => FilterService)) private readonly filterService: FilterService,
20
- @Inject(forwardRef(() => EntityServiceImpl)) private readonly entityServiceImpl: EntityServiceImpl
21
- ) {
22
- }
23
-
24
- async getAttributeForFlatJSON(
25
- entityType: string,
26
- loggedInUser: any,
27
- flag?: 'flat_json' | 'dropdown' | 'all' | 'filter_attribute',
28
- ): Promise<any> {
29
- const entId = loggedInUser.enterprise_id;
30
-
31
- await this.loggerService.log(
32
- 'info',
33
- 'EntityJSONService',
34
- 'getAttributeForFlatJSON',
35
- `Loading attributes for entity: ${entityType}, org: ${entId}`,
36
- );
37
-
38
- // MAIN ATTRIBUTES
39
- const mainAttributes = await this.dataSource
40
- .getRepository(AttributeMaster)
41
- .createQueryBuilder('attr')
42
- .select([
43
- 'attr.id',
44
- 'attr.name',
45
- 'attr.flat_json_key',
46
- 'attr.attribute_key',
47
- 'attr.data_type',
48
- ])
49
- .where('attr.mapped_entity_type = :entityType', { entityType })
50
- .andWhere('attr.enterprise_id = :entId', { entId })
51
- .andWhere('attr.data_type != :uploadType', { uploadType: 'upload' })
52
- .getMany();
53
-
54
- await this.loggerService.log(
55
- 'debug',
56
- 'EntityJSONService',
57
- 'getAttributeForFlatJSON',
58
- `Loaded ${mainAttributes.length} main attributes`,
59
- );
60
-
61
- // RELATED ENTITY TYPES
62
- const relatedEntityTypes = await this.dataSource
63
- .getRepository(EntityRelation)
64
- .createQueryBuilder('rel')
65
- .select(['rel.target_entity_type'])
66
- .where('rel.source_entity_type = :entityType', { entityType })
67
- .andWhere('rel.enterprise_id = :entId', { entId })
68
- .andWhere('rel.relation_type = :relationType', { relationType: 'ONE_TO_ONE' })
69
- .getRawMany();
70
-
71
- const relatedTypesList = relatedEntityTypes.map(
72
- (x) => x.rel_target_entity_type,
73
- );
74
-
75
- await this.loggerService.log(
76
- 'debug',
77
- 'EntityJSONService',
78
- 'getAttributeForFlatJSON',
79
- `Found ${relatedTypesList.length} ONE-TO-ONE related entity types`,
80
- );
81
-
82
- // RELATED ATTRIBUTES
83
- const relatedAttributes = relatedTypesList.length
84
- ? await this.dataSource
85
- .getRepository(AttributeMaster)
86
- .createQueryBuilder('attr')
87
- .select([
88
- 'attr.id',
89
- 'attr.name',
90
- 'attr.flat_json_key',
91
- 'attr.mapped_entity_type',
92
- 'attr.attribute_key',
93
- 'attr.data_type',
94
- ])
95
- .where('attr.mapped_entity_type IN (:...types)', {
96
- types: relatedTypesList,
97
- })
98
- .andWhere('attr.enterprise_id = :entId', { entId })
99
- .andWhere('attr.data_type != :uploadType', { uploadType: 'upload' })
100
- .getMany()
101
- : [];
102
-
103
- await this.loggerService.log(
104
- 'debug',
105
- 'EntityJSONService',
106
- 'getAttributeForFlatJSON',
107
- `Loaded ${relatedAttributes.length} related attributes`,
108
- );
109
-
110
- // LINKED ATTRIBUTES
111
- const linkedAttributes = await this.dataSource
112
- .getRepository(LinkedAttributes)
113
- .createQueryBuilder('fla')
114
- .innerJoin(
115
- AttributeMaster,
116
- 'attr',
117
- 'fla.applicable_entity_type = attr.mapped_entity_type AND fla.applicable_attribute_key = attr.attribute_key',
118
- )
119
- .select([
120
- 'fla.applicable_entity_type AS applicable_entity_type',
121
- 'fla.applicable_attribute_key AS applicable_attribute_key',
122
- 'fla.attribute_key AS target_attribute_key',
123
- 'fla.saved_filter_code AS saved_filter_code',
124
- 'attr.name AS name',
125
- 'attr.id AS id',
126
- 'attr.data_type AS data_type',
127
- ])
128
- .where('attr.enterprise_id = :entId', { entId })
129
- .andWhere('attr.data_type != :uploadType', { uploadType: 'upload' })
130
- .getRawMany();
131
-
132
- await this.loggerService.log(
133
- 'debug',
134
- 'EntityJSONService',
135
- 'getAttributeForFlatJSON',
136
- `Loaded ${linkedAttributes.length} linked attributes`,
137
- );
138
-
139
- // -------------------------------------------------------------------------
140
- // ✅ FLAG: filter_attribute (NEW)
141
- // -------------------------------------------------------------------------
142
- if (flag === 'filter_attribute') {
143
- const filterAttributes: any[] = [];
144
-
145
- // MAIN
146
- filterAttributes.push(
147
- ...mainAttributes.map((a) => ({
148
- id: a.id,
149
- name: a.name,
150
- data_type: a.data_type,
151
- attribute_key: a.flat_json_key,
152
- source: 'main',
153
- })),
154
- );
155
-
156
- // RELATED
157
- filterAttributes.push(
158
- ...relatedAttributes.map((a) => ({
159
- id: a.id,
160
- name: a.name,
161
- data_type: a.data_type,
162
- attribute_key: a.flat_json_key,
163
- source: 'related',
164
- })),
165
- );
166
-
167
- // LINKED
168
- filterAttributes.push(
169
- ...linkedAttributes.map((l) => ({
170
- id: l.id,
171
- name: l.name,
172
- data_type: l.data_type,
173
- attribute_key: l.target_attribute_key, // attribute_key
174
- source: 'linked',
175
- })),
176
- );
177
-
178
- return filterAttributes;
179
- }
180
-
181
- // -------------------------------------------------------------------------
182
- // ORIGINAL flat_json FLAG (unchanged)
183
- // -------------------------------------------------------------------------
184
- if (flag === 'flat_json' || flag === 'all') {
185
- const result: Record<string, null> = {};
186
-
187
- mainAttributes.forEach((attr) => {
188
- if (attr.flat_json_key) result[attr.flat_json_key] = null;
189
- });
190
-
191
- relatedAttributes.forEach((attr) => {
192
- if (attr.flat_json_key) result[attr.flat_json_key] = null;
193
- });
194
-
195
- linkedAttributes.forEach((link) => {
196
- if (link.target_attribute_key) result[link.target_attribute_key] = null;
197
- });
198
-
199
- if (flag === 'all') {
200
- return {
201
- flat_json: result,
202
- attributes: {
203
- mainAttributes,
204
- relatedAttributes,
205
- linkedAttributes,
206
- },
207
- };
208
- }
209
-
210
- return result;
211
- }
212
-
213
- // -------------------------------------------------------------------------
214
- // ORIGINAL dropdown FLAG (unchanged)
215
- // -------------------------------------------------------------------------
216
- const dropdown: any[] = [];
217
-
218
- dropdown.push(
219
- ...mainAttributes.map((a) => ({ label: a.name, value: a.flat_json_key })),
220
- );
221
- dropdown.push(
222
- ...relatedAttributes.map((a) => ({
223
- label: a.name,
224
- value: a.flat_json_key,
225
- })),
226
- );
227
-
228
- if (linkedAttributes.length > 0) {
229
- dropdown.push(
230
- ...linkedAttributes.map((a) => ({
231
- label: a.name,
232
- value: a.target_attribute_key,
233
- })),
234
- );
235
- }
236
-
237
- return dropdown;
238
- }
239
-
240
- async updateEntityJSON(entityType: string, entityId: number, loggedInUser) {
241
- await this.loggerService.log(
242
- 'info',
243
- 'EntityJSONService',
244
- 'updateEntityJSON',
245
- `Building flat JSON for entity: ${entityType}#${entityId}`,
246
- );
247
-
248
- const response = await this.getAttributeForFlatJSON(
249
- entityType,
250
- loggedInUser,
251
- 'all',
252
- );
253
-
254
- if (
255
- !response ||
256
- !('flat_json' in response) ||
257
- !('attributes' in response) ||
258
- !response.attributes
259
- ) {
260
- await this.loggerService.log(
261
- 'error',
262
- 'EntityJSONService',
263
- 'updateEntityJSON',
264
- `getAttributeForFlatJSON() did not return expected structure`,
265
- );
266
- return null;
267
- }
268
-
269
- const { flat_json: flatJson, attributes } = response;
270
- if (!flatJson) return null;
271
-
272
- const safeAttributes = {
273
- mainAttributes: attributes.mainAttributes || [],
274
- relatedAttributes: attributes.relatedAttributes || [],
275
- linkedAttributes: attributes.linkedAttributes || [],
276
- };
277
-
278
- const attrMap: Record<string, string> = {};
279
- const dataTypeMap: Record<string, string> = {};
280
- const allAttrs = [
281
- ...safeAttributes.mainAttributes,
282
- ...safeAttributes.relatedAttributes,
283
- ];
284
- allAttrs.forEach((attr) => {
285
- if (attr.attribute_key) {
286
- const flatKey = attr.flat_json_key || attr.attribute_key;
287
- attrMap[attr.attribute_key] = flatKey;
288
- if (attr.data_type) {
289
- dataTypeMap[flatKey] = attr.data_type;
290
- }
291
- }
292
- });
293
-
294
- const mainData = await this.entityServiceImpl.getResolvedEntityData(
295
- entityType,
296
- entityId,
297
- loggedInUser,
298
- true
299
- );
300
- this.mergeEntityDataIntoFlatJson(flatJson, mainData, attrMap, dataTypeMap);
301
-
302
- const relations = await this.dataSource
303
- .getRepository('frm_entity_relation_data')
304
- .createQueryBuilder('erd')
305
- .select([
306
- 'erd.target_entity_id AS target_entity_id',
307
- 'erd.target_entity_type AS target_entity_type',
308
- ])
309
- .where('erd.source_entity_type = :entityType', { entityType })
310
- .andWhere('erd.source_entity_id = :entityId', { entityId })
311
- .andWhere('erd.relation_type = :rt', { rt: 'ONE_TO_ONE' })
312
- .getRawMany();
313
-
314
- for (const rel of relations) {
315
- const relatedData = await this.entityServiceImpl.getResolvedEntityData(
316
- rel.target_entity_type,
317
- rel.target_entity_id,
318
- loggedInUser,
319
- true
320
- );
321
- this.mergeEntityDataIntoFlatJson(flatJson, relatedData, attrMap, dataTypeMap);
322
- }
323
-
324
- for (const linkAttr of safeAttributes.linkedAttributes) {
325
- const childEntityType = linkAttr.applicable_entity_type;
326
- const sourceKey = linkAttr.applicable_attribute_key;
327
- const targetKey = linkAttr.target_attribute_key;
328
-
329
- if (!childEntityType || !sourceKey || !targetKey) continue;
330
-
331
- const mappingValue = mainData?.[sourceKey] ?? null;
332
-
333
- const value = await this.applyLinkedFilterUsingSavedFilter(
334
- childEntityType,
335
- linkAttr.saved_filter_code,
336
- sourceKey,
337
- mappingValue,
338
- targetKey,
339
- loggedInUser,
340
- entityId,
341
- );
342
-
343
- if (value !== null && value !== undefined) {
344
- let processedValue = typeof value === 'string' ? value.toLowerCase() : value;
345
-
346
- // Convert date/datetime to milliseconds for linked attributes
347
- const dataType = linkAttr.data_type?.toLowerCase();
348
- if (dataType === 'date' || dataType === 'datetime') {
349
- processedValue = this.convertToMilliseconds(processedValue);
350
- }
351
-
352
- flatJson[targetKey] = processedValue;
353
- }
354
- }
355
-
356
- await this.loggerService.log(
357
- 'info',
358
- 'EntityJSONService',
359
- 'updateEntityJSON',
360
- `Saving flat JSON for entity: ${entityType}#${entityId}`,
361
- );
362
- let JsonData = {
363
- entity_type: entityType,
364
- entity_id: entityId,
365
- json_data: flatJson,
366
- created_by: loggedInUser.id,
367
- };
368
-
369
- await this.EntityJSONRepository.create(JsonData);
370
-
371
- return flatJson;
372
- }
373
-
374
- private mergeEntityDataIntoFlatJson(
375
- flatJson: Record<string, any>,
376
- entityData: any | any[],
377
- attrMap: Record<string, string>,
378
- dataTypeMap: Record<string, string> = {},
379
- ) {
380
- const records = Array.isArray(entityData) ? entityData : [entityData];
381
-
382
- for (const record of records) {
383
- if (!record || typeof record !== 'object') continue;
384
- for (const key of Object.keys(record)) {
385
- const flatKey = attrMap[key] || key;
386
- if (flatJson.hasOwnProperty(flatKey)) {
387
- let value = record[key];
388
-
389
- // Convert date/datetime to milliseconds
390
- const dataType = dataTypeMap[flatKey]?.toLowerCase();
391
- if (dataType === 'date' || dataType === 'datetime') {
392
- value = this.convertToMilliseconds(value);
393
- } else if (typeof value === 'string') {
394
- // Convert string values to lowercase (only for non-date fields)
395
- value = value.toLowerCase();
396
- }
397
-
398
- flatJson[flatKey] = value;
399
- }
400
- }
401
- }
402
- }
403
-
404
- private async applyLinkedFilterUsingSavedFilter(
405
- childEntityType: string,
406
- savedFilterCode: string,
407
- childFilterAttribute: string,
408
- mappingValue: any,
409
- targetAttribute: string,
410
- loggedInUser,
411
- entity_id,
412
- ) {
413
- if (
414
- !savedFilterCode &&
415
- (mappingValue === null || mappingValue === undefined)
416
- )
417
- return null;
418
-
419
- const dto: any = {
420
- entity_type: childEntityType,
421
- savedFilterCode,
422
- page: 1,
423
- size: 1,
424
- loggedInUser
425
- };
426
-
427
- if (
428
- mappingValue !== null &&
429
- mappingValue !== undefined &&
430
- mappingValue !== ''
431
- ) {
432
- dto.quickFilter = [
433
- {
434
- filter_attribute: childFilterAttribute,
435
- filter_operator: 'equal',
436
- filter_value: mappingValue,
437
- },
438
- ];
439
- }
440
-
441
- dto.quickFilter = [
442
- {
443
- filter_attribute: 'parent_id',
444
- filter_operator: 'equal',
445
- filter_value: [entity_id],
446
- },
447
- ];
448
-
449
- const result = await this.filterService.applyFilter(dto);
450
- const rows = result?.data?.entity_list || [];
451
- return rows.length ? (rows[0][childFilterAttribute] ?? null) : null;
452
- }
453
-
454
- /**
455
- * Converts date/datetime values to milliseconds timestamp
456
- * @param value - The value to convert (can be Date, string, number, or null/undefined)
457
- * @returns milliseconds timestamp or null if invalid
458
- */
459
- private convertToMilliseconds(value: any): number | null {
460
- if (value === null || value === undefined) {
461
- return null;
462
- }
463
-
464
- // If already a number, assume it's already in milliseconds
465
- if (typeof value === 'number') {
466
- return value;
467
- }
468
-
469
- // If it's a Date object
470
- if (value instanceof Date) {
471
- return value.getTime();
472
- }
473
-
474
- // If it's a string, try to parse it
475
- if (typeof value === 'string') {
476
- const parsed = new Date(value);
477
- if (!isNaN(parsed.getTime())) {
478
- return parsed.getTime();
479
- }
480
- }
481
-
482
- // If we can't convert, return null
483
- return null;
484
- }
485
-
486
- }
1
+ import { Inject, Injectable, forwardRef } from '@nestjs/common';
2
+ import { LinkedAttributes } from 'src/module/linked_attributes/entity/linked_attribute.entity';
3
+ import { AttributeMaster } from 'src/module/meta/entity/attribute-master.entity';
4
+ import { EntityRelation } from 'src/module/meta/entity/entity-relation.entity';
5
+ import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service';
6
+ import { LoggingService } from 'src/utils/service/loggingUtil.service';
7
+ import { DataSource } from 'typeorm';
8
+ import { EntityJSONRepository } from './entityJson.repository';
9
+ import { FilterService } from '../../filter/service/filter.service';
10
+ import { AttributeMasterService } from 'src/module/meta/service/attribute-master.service';
11
+ import { ResolverService } from 'src/module/meta/service/resolver.service';
12
+
13
+ @Injectable()
14
+ export class EntityJSONService {
15
+ constructor(
16
+ private readonly dataSource: DataSource,
17
+ private readonly loggerService: LoggingService,
18
+ private readonly EntityJSONRepository: EntityJSONRepository,
19
+ @Inject(forwardRef(() => FilterService)) private readonly filterService: FilterService,
20
+ @Inject(forwardRef(() => EntityServiceImpl)) private readonly entityServiceImpl: EntityServiceImpl
21
+ ) {
22
+ }
23
+
24
+ async getAttributeForFlatJSON(
25
+ entityType: string,
26
+ loggedInUser: any,
27
+ flag?: 'flat_json' | 'dropdown' | 'all' | 'filter_attribute',
28
+ ): Promise<any> {
29
+ const entId = loggedInUser.enterprise_id;
30
+
31
+ await this.loggerService.log(
32
+ 'info',
33
+ 'EntityJSONService',
34
+ 'getAttributeForFlatJSON',
35
+ `Loading attributes for entity: ${entityType}, org: ${entId}`,
36
+ );
37
+
38
+ // MAIN ATTRIBUTES
39
+ const mainAttributes = await this.dataSource
40
+ .getRepository(AttributeMaster)
41
+ .createQueryBuilder('attr')
42
+ .select([
43
+ 'attr.id',
44
+ 'attr.name',
45
+ 'attr.flat_json_key',
46
+ 'attr.attribute_key',
47
+ 'attr.data_type',
48
+ ])
49
+ .where('attr.mapped_entity_type = :entityType', { entityType })
50
+ .andWhere('attr.enterprise_id = :entId', { entId })
51
+ .andWhere('attr.data_type != :uploadType', { uploadType: 'upload' })
52
+ .getMany();
53
+
54
+ await this.loggerService.log(
55
+ 'debug',
56
+ 'EntityJSONService',
57
+ 'getAttributeForFlatJSON',
58
+ `Loaded ${mainAttributes.length} main attributes`,
59
+ );
60
+
61
+ // RELATED ENTITY TYPES
62
+ const relatedEntityTypes = await this.dataSource
63
+ .getRepository(EntityRelation)
64
+ .createQueryBuilder('rel')
65
+ .select(['rel.target_entity_type'])
66
+ .where('rel.source_entity_type = :entityType', { entityType })
67
+ .andWhere('rel.enterprise_id = :entId', { entId })
68
+ .andWhere('rel.relation_type = :relationType', { relationType: 'ONE_TO_ONE' })
69
+ .getRawMany();
70
+
71
+ const relatedTypesList = relatedEntityTypes.map(
72
+ (x) => x.rel_target_entity_type,
73
+ );
74
+
75
+ await this.loggerService.log(
76
+ 'debug',
77
+ 'EntityJSONService',
78
+ 'getAttributeForFlatJSON',
79
+ `Found ${relatedTypesList.length} ONE-TO-ONE related entity types`,
80
+ );
81
+
82
+ // RELATED ATTRIBUTES
83
+ const relatedAttributes = relatedTypesList.length
84
+ ? await this.dataSource
85
+ .getRepository(AttributeMaster)
86
+ .createQueryBuilder('attr')
87
+ .select([
88
+ 'attr.id',
89
+ 'attr.name',
90
+ 'attr.flat_json_key',
91
+ 'attr.mapped_entity_type',
92
+ 'attr.attribute_key',
93
+ 'attr.data_type',
94
+ ])
95
+ .where('attr.mapped_entity_type IN (:...types)', {
96
+ types: relatedTypesList,
97
+ })
98
+ .andWhere('attr.enterprise_id = :entId', { entId })
99
+ .andWhere('attr.data_type != :uploadType', { uploadType: 'upload' })
100
+ .getMany()
101
+ : [];
102
+
103
+ await this.loggerService.log(
104
+ 'debug',
105
+ 'EntityJSONService',
106
+ 'getAttributeForFlatJSON',
107
+ `Loaded ${relatedAttributes.length} related attributes`,
108
+ );
109
+
110
+ // LINKED ATTRIBUTES
111
+ const linkedAttributes = await this.dataSource
112
+ .getRepository(LinkedAttributes)
113
+ .createQueryBuilder('fla')
114
+ .innerJoin(
115
+ AttributeMaster,
116
+ 'attr',
117
+ 'fla.applicable_entity_type = attr.mapped_entity_type AND fla.applicable_attribute_key = attr.attribute_key',
118
+ )
119
+ .select([
120
+ 'fla.applicable_entity_type AS applicable_entity_type',
121
+ 'fla.applicable_attribute_key AS applicable_attribute_key',
122
+ 'fla.attribute_key AS target_attribute_key',
123
+ 'fla.saved_filter_code AS saved_filter_code',
124
+ 'attr.name AS name',
125
+ 'attr.id AS id',
126
+ 'attr.data_type AS data_type',
127
+ ])
128
+ .where('attr.enterprise_id = :entId', { entId })
129
+ .andWhere('attr.data_type != :uploadType', { uploadType: 'upload' })
130
+ .getRawMany();
131
+
132
+ await this.loggerService.log(
133
+ 'debug',
134
+ 'EntityJSONService',
135
+ 'getAttributeForFlatJSON',
136
+ `Loaded ${linkedAttributes.length} linked attributes`,
137
+ );
138
+
139
+ // -------------------------------------------------------------------------
140
+ // ✅ FLAG: filter_attribute (NEW)
141
+ // -------------------------------------------------------------------------
142
+ if (flag === 'filter_attribute') {
143
+ const filterAttributes: any[] = [];
144
+
145
+ // MAIN
146
+ filterAttributes.push(
147
+ ...mainAttributes.map((a) => ({
148
+ id: a.id,
149
+ name: a.name,
150
+ data_type: a.data_type,
151
+ attribute_key: a.flat_json_key,
152
+ source: 'main',
153
+ })),
154
+ );
155
+
156
+ // RELATED
157
+ filterAttributes.push(
158
+ ...relatedAttributes.map((a) => ({
159
+ id: a.id,
160
+ name: a.name,
161
+ data_type: a.data_type,
162
+ attribute_key: a.flat_json_key,
163
+ source: 'related',
164
+ })),
165
+ );
166
+
167
+ // LINKED
168
+ filterAttributes.push(
169
+ ...linkedAttributes.map((l) => ({
170
+ id: l.id,
171
+ name: l.name,
172
+ data_type: l.data_type,
173
+ attribute_key: l.target_attribute_key, // attribute_key
174
+ source: 'linked',
175
+ })),
176
+ );
177
+
178
+ return filterAttributes;
179
+ }
180
+
181
+ // -------------------------------------------------------------------------
182
+ // ORIGINAL flat_json FLAG (unchanged)
183
+ // -------------------------------------------------------------------------
184
+ if (flag === 'flat_json' || flag === 'all') {
185
+ const result: Record<string, null> = {};
186
+
187
+ mainAttributes.forEach((attr) => {
188
+ if (attr.flat_json_key) result[attr.flat_json_key] = null;
189
+ });
190
+
191
+ relatedAttributes.forEach((attr) => {
192
+ if (attr.flat_json_key) result[attr.flat_json_key] = null;
193
+ });
194
+
195
+ linkedAttributes.forEach((link) => {
196
+ if (link.target_attribute_key) result[link.target_attribute_key] = null;
197
+ });
198
+
199
+ if (flag === 'all') {
200
+ return {
201
+ flat_json: result,
202
+ attributes: {
203
+ mainAttributes,
204
+ relatedAttributes,
205
+ linkedAttributes,
206
+ },
207
+ };
208
+ }
209
+
210
+ return result;
211
+ }
212
+
213
+ // -------------------------------------------------------------------------
214
+ // ORIGINAL dropdown FLAG (unchanged)
215
+ // -------------------------------------------------------------------------
216
+ const dropdown: any[] = [];
217
+
218
+ dropdown.push(
219
+ ...mainAttributes.map((a) => ({ label: a.name, value: a.flat_json_key })),
220
+ );
221
+ dropdown.push(
222
+ ...relatedAttributes.map((a) => ({
223
+ label: a.name,
224
+ value: a.flat_json_key,
225
+ })),
226
+ );
227
+
228
+ if (linkedAttributes.length > 0) {
229
+ dropdown.push(
230
+ ...linkedAttributes.map((a) => ({
231
+ label: a.name,
232
+ value: a.target_attribute_key,
233
+ })),
234
+ );
235
+ }
236
+
237
+ return dropdown;
238
+ }
239
+
240
+ async updateEntityJSON(entityType: string, entityId: number, loggedInUser) {
241
+ await this.loggerService.log(
242
+ 'info',
243
+ 'EntityJSONService',
244
+ 'updateEntityJSON',
245
+ `Building flat JSON for entity: ${entityType}#${entityId}`,
246
+ );
247
+
248
+ const response = await this.getAttributeForFlatJSON(
249
+ entityType,
250
+ loggedInUser,
251
+ 'all',
252
+ );
253
+
254
+ if (
255
+ !response ||
256
+ !('flat_json' in response) ||
257
+ !('attributes' in response) ||
258
+ !response.attributes
259
+ ) {
260
+ await this.loggerService.log(
261
+ 'error',
262
+ 'EntityJSONService',
263
+ 'updateEntityJSON',
264
+ `getAttributeForFlatJSON() did not return expected structure`,
265
+ );
266
+ return null;
267
+ }
268
+
269
+ const { flat_json: flatJson, attributes } = response;
270
+ if (!flatJson) return null;
271
+
272
+ const safeAttributes = {
273
+ mainAttributes: attributes.mainAttributes || [],
274
+ relatedAttributes: attributes.relatedAttributes || [],
275
+ linkedAttributes: attributes.linkedAttributes || [],
276
+ };
277
+
278
+ const attrMap: Record<string, string> = {};
279
+ const dataTypeMap: Record<string, string> = {};
280
+ const allAttrs = [
281
+ ...safeAttributes.mainAttributes,
282
+ ...safeAttributes.relatedAttributes,
283
+ ];
284
+ allAttrs.forEach((attr) => {
285
+ if (attr.attribute_key) {
286
+ const flatKey = attr.flat_json_key || attr.attribute_key;
287
+ attrMap[attr.attribute_key] = flatKey;
288
+ if (attr.data_type) {
289
+ dataTypeMap[flatKey] = attr.data_type;
290
+ }
291
+ }
292
+ });
293
+
294
+ const mainData = await this.entityServiceImpl.getResolvedEntityData(
295
+ entityType,
296
+ entityId,
297
+ loggedInUser,
298
+ true
299
+ );
300
+ this.mergeEntityDataIntoFlatJson(flatJson, mainData, attrMap, dataTypeMap);
301
+
302
+ const relations = await this.dataSource
303
+ .getRepository('frm_entity_relation_data')
304
+ .createQueryBuilder('erd')
305
+ .select([
306
+ 'erd.target_entity_id AS target_entity_id',
307
+ 'erd.target_entity_type AS target_entity_type',
308
+ ])
309
+ .where('erd.source_entity_type = :entityType', { entityType })
310
+ .andWhere('erd.source_entity_id = :entityId', { entityId })
311
+ .andWhere('erd.relation_type = :rt', { rt: 'ONE_TO_ONE' })
312
+ .getRawMany();
313
+
314
+ for (const rel of relations) {
315
+ const relatedData = await this.entityServiceImpl.getResolvedEntityData(
316
+ rel.target_entity_type,
317
+ rel.target_entity_id,
318
+ loggedInUser,
319
+ true
320
+ );
321
+ this.mergeEntityDataIntoFlatJson(flatJson, relatedData, attrMap, dataTypeMap);
322
+ }
323
+
324
+ for (const linkAttr of safeAttributes.linkedAttributes) {
325
+ const childEntityType = linkAttr.applicable_entity_type;
326
+ const sourceKey = linkAttr.applicable_attribute_key;
327
+ const targetKey = linkAttr.target_attribute_key;
328
+
329
+ if (!childEntityType || !sourceKey || !targetKey) continue;
330
+
331
+ const mappingValue = mainData?.[sourceKey] ?? null;
332
+
333
+ const value = await this.applyLinkedFilterUsingSavedFilter(
334
+ childEntityType,
335
+ linkAttr.saved_filter_code,
336
+ sourceKey,
337
+ mappingValue,
338
+ targetKey,
339
+ loggedInUser,
340
+ entityId,
341
+ );
342
+
343
+ if (value !== null && value !== undefined) {
344
+ let processedValue = typeof value === 'string' ? value.toLowerCase() : value;
345
+
346
+ // Convert date/datetime to milliseconds for linked attributes
347
+ const dataType = linkAttr.data_type?.toLowerCase();
348
+ if (dataType === 'date' || dataType === 'datetime') {
349
+ processedValue = this.convertToMilliseconds(processedValue);
350
+ }
351
+
352
+ flatJson[targetKey] = processedValue;
353
+ }
354
+ }
355
+
356
+ await this.loggerService.log(
357
+ 'info',
358
+ 'EntityJSONService',
359
+ 'updateEntityJSON',
360
+ `Saving flat JSON for entity: ${entityType}#${entityId}`,
361
+ );
362
+ let JsonData = {
363
+ entity_type: entityType,
364
+ entity_id: entityId,
365
+ json_data: flatJson,
366
+ created_by: loggedInUser.id,
367
+ };
368
+
369
+ await this.EntityJSONRepository.create(JsonData);
370
+
371
+ return flatJson;
372
+ }
373
+
374
+ private mergeEntityDataIntoFlatJson(
375
+ flatJson: Record<string, any>,
376
+ entityData: any | any[],
377
+ attrMap: Record<string, string>,
378
+ dataTypeMap: Record<string, string> = {},
379
+ ) {
380
+ const records = Array.isArray(entityData) ? entityData : [entityData];
381
+
382
+ for (const record of records) {
383
+ if (!record || typeof record !== 'object') continue;
384
+ for (const key of Object.keys(record)) {
385
+ const flatKey = attrMap[key] || key;
386
+ if (flatJson.hasOwnProperty(flatKey)) {
387
+ let value = record[key];
388
+
389
+ // Convert date/datetime to milliseconds
390
+ const dataType = dataTypeMap[flatKey]?.toLowerCase();
391
+ if (dataType === 'date' || dataType === 'datetime') {
392
+ value = this.convertToMilliseconds(value);
393
+ } else if (typeof value === 'string') {
394
+ // Convert string values to lowercase (only for non-date fields)
395
+ value = value.toLowerCase();
396
+ }
397
+
398
+ flatJson[flatKey] = value;
399
+ }
400
+ }
401
+ }
402
+ }
403
+
404
+ private async applyLinkedFilterUsingSavedFilter(
405
+ childEntityType: string,
406
+ savedFilterCode: string,
407
+ childFilterAttribute: string,
408
+ mappingValue: any,
409
+ targetAttribute: string,
410
+ loggedInUser,
411
+ entity_id,
412
+ ) {
413
+ if (
414
+ !savedFilterCode &&
415
+ (mappingValue === null || mappingValue === undefined)
416
+ )
417
+ return null;
418
+
419
+ const dto: any = {
420
+ entity_type: childEntityType,
421
+ savedFilterCode,
422
+ page: 1,
423
+ size: 1,
424
+ loggedInUser
425
+ };
426
+
427
+ if (
428
+ mappingValue !== null &&
429
+ mappingValue !== undefined &&
430
+ mappingValue !== ''
431
+ ) {
432
+ dto.quickFilter = [
433
+ {
434
+ filter_attribute: childFilterAttribute,
435
+ filter_operator: 'equal',
436
+ filter_value: mappingValue,
437
+ },
438
+ ];
439
+ }
440
+
441
+ dto.quickFilter = [
442
+ {
443
+ filter_attribute: 'parent_id',
444
+ filter_operator: 'equal',
445
+ filter_value: [entity_id],
446
+ },
447
+ ];
448
+
449
+ const result = await this.filterService.applyFilter(dto);
450
+ const rows = result?.data?.entity_list || [];
451
+ return rows.length ? (rows[0][childFilterAttribute] ?? null) : null;
452
+ }
453
+
454
+ /**
455
+ * Converts date/datetime values to milliseconds timestamp
456
+ * @param value - The value to convert (can be Date, string, number, or null/undefined)
457
+ * @returns milliseconds timestamp or null if invalid
458
+ */
459
+ private convertToMilliseconds(value: any): number | null {
460
+ if (value === null || value === undefined) {
461
+ return null;
462
+ }
463
+
464
+ // If already a number, assume it's already in milliseconds
465
+ if (typeof value === 'number') {
466
+ return value;
467
+ }
468
+
469
+ // If it's a Date object
470
+ if (value instanceof Date) {
471
+ return value.getTime();
472
+ }
473
+
474
+ // If it's a string, try to parse it
475
+ if (typeof value === 'string') {
476
+ const parsed = new Date(value);
477
+ if (!isNaN(parsed.getTime())) {
478
+ return parsed.getTime();
479
+ }
480
+ }
481
+
482
+ // If we can't convert, return null
483
+ return null;
484
+ }
485
+
486
+ }