rez_core 7.1.1 → 7.1.3
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.
- package/.claude/settings.local.json +26 -0
- package/.idea/250218_nodejs_core.iml +9 -0
- package/.idea/codeStyles/Project.xml +58 -58
- package/.idea/codeStyles/codeStyleConfig.xml +4 -4
- package/.idea/copilot.data.migration.agent.xml +6 -0
- package/.idea/copilot.data.migration.ask.xml +6 -0
- package/.idea/copilot.data.migration.ask2agent.xml +6 -0
- package/.idea/copilot.data.migration.edit.xml +6 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +7 -7
- package/.idea/prettier.xml +6 -0
- package/.idea/vcs.xml +5 -5
- package/.prettierrc +3 -3
- package/README.md +99 -99
- package/dist/module/filter/repository/saved-filter.repository.js +0 -2
- package/dist/module/filter/repository/saved-filter.repository.js.map +1 -1
- package/dist/module/filter/service/filter.service.js +28 -33
- package/dist/module/filter/service/filter.service.js.map +1 -1
- package/dist/module/integration/examples/usage.example.js +9 -9
- package/dist/module/integration/service/integration.service.d.ts +1 -6
- package/dist/module/integration/service/integration.service.js +2 -14
- package/dist/module/integration/service/integration.service.js.map +1 -1
- package/dist/module/integration/service/oauth.service.js +0 -2
- package/dist/module/integration/service/oauth.service.js.map +1 -1
- package/dist/module/integration/service/wrapper.service.js +0 -1
- package/dist/module/integration/service/wrapper.service.js.map +1 -1
- package/dist/module/integration/strategies/email/gmail-api.strategy.js +7 -23
- package/dist/module/integration/strategies/email/gmail-api.strategy.js.map +1 -1
- package/dist/module/integration/strategies/email/sendgrid-api.strategy.js +5 -8
- package/dist/module/integration/strategies/email/sendgrid-api.strategy.js.map +1 -1
- package/dist/module/listmaster/controller/list-master.controller.d.ts +21 -6
- package/dist/module/listmaster/controller/list-master.controller.js +17 -6
- package/dist/module/listmaster/controller/list-master.controller.js.map +1 -1
- package/dist/module/listmaster/service/list-master.service.d.ts +9 -4
- package/dist/module/listmaster/service/list-master.service.js +54 -45
- package/dist/module/listmaster/service/list-master.service.js.map +1 -1
- package/dist/module/meta/controller/media.controller.d.ts +0 -3
- package/dist/module/meta/controller/media.controller.js +0 -27
- package/dist/module/meta/controller/media.controller.js.map +1 -1
- package/dist/module/meta/entity/media-data.entity.d.ts +0 -1
- package/dist/module/meta/entity/media-data.entity.js +0 -4
- package/dist/module/meta/entity/media-data.entity.js.map +1 -1
- package/dist/module/meta/repository/attribute-master.repository.js +14 -14
- package/dist/module/meta/service/entity-dynamic.service.js +16 -16
- package/dist/module/meta/service/entity-dynamic.service.js.map +1 -1
- package/dist/module/meta/service/entity-master.service.js +20 -20
- package/dist/module/meta/service/media-data.service.d.ts +0 -2
- package/dist/module/meta/service/media-data.service.js +0 -8
- package/dist/module/meta/service/media-data.service.js.map +1 -1
- package/dist/module/meta/service/resolver.service.js +13 -23
- package/dist/module/meta/service/resolver.service.js.map +1 -1
- package/dist/module/notification/notification.module.js +0 -2
- package/dist/module/notification/notification.module.js.map +1 -1
- package/dist/module/notification/service/notification.service.d.ts +1 -3
- package/dist/module/notification/service/notification.service.js +40 -27
- package/dist/module/notification/service/notification.service.js.map +1 -1
- package/dist/module/workflow/controller/workflow.controller.js +1 -1
- package/dist/module/workflow/controller/workflow.controller.js.map +1 -1
- package/dist/module/workflow/repository/action-data.repository.js +3 -10
- package/dist/module/workflow/repository/action-data.repository.js.map +1 -1
- package/dist/module/workflow/repository/action.repository.js +2 -2
- package/dist/module/workflow/repository/stage.repository.js +8 -8
- package/dist/module/workflow/repository/task.repository.js +4 -4
- package/dist/module/workflow/repository/task.repository.js.map +1 -1
- package/dist/module/workflow/service/action-template-mapping.service.js +2 -2
- package/dist/module/workflow/service/action.service.js +5 -5
- package/dist/module/workflow/service/entity-modification.service.d.ts +1 -4
- package/dist/module/workflow/service/entity-modification.service.js +5 -9
- package/dist/module/workflow/service/entity-modification.service.js.map +1 -1
- package/dist/module/workflow/service/populate-workflow.service.d.ts +1 -1
- package/dist/module/workflow/service/populate-workflow.service.js +24 -24
- package/dist/module/workflow/service/populate-workflow.service.js.map +1 -1
- package/dist/module/workflow/service/task.service.js +9 -9
- package/dist/module/workflow/service/task.service.js.map +1 -1
- package/dist/module/workflow-automation/service/schedule-handler.service.js +9 -9
- package/dist/module/workflow-automation/service/workflow-automation.service.js +6 -8
- package/dist/module/workflow-automation/service/workflow-automation.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utils/service/reflection-helper.service.js +2 -2
- package/docs/modules/event-driven-integration-design.md +91 -91
- package/docs/modules/integration.md +250 -250
- package/eslint.config.mjs +34 -34
- package/nest-cli.json +14 -14
- package/package.json +128 -128
- package/server.log +850 -0
- package/src/app.controller.ts +12 -12
- package/src/app.module.ts +62 -62
- package/src/app.service.ts +8 -8
- package/src/config/bull.config.ts +72 -72
- package/src/config/config.module.ts +17 -17
- package/src/config/database.config.ts +48 -48
- package/src/config/redis.config.ts +55 -55
- package/src/constant/attribute.constant.ts +8 -8
- package/src/constant/db-data-type.constant.ts +160 -160
- package/src/constant/entity.constant.ts +3 -3
- package/src/constant/global.constant.ts +67 -67
- package/src/constant/status.constant.ts +3 -3
- package/src/core.module.ts +96 -96
- package/src/decorators/roles.decorator.ts +7 -7
- package/src/dtos/response.dto.ts +6 -6
- package/src/dtos/response.ts +5 -5
- package/src/index.ts +1 -1
- package/src/module/auth/auth.module.ts +65 -65
- package/src/module/auth/controller/auth.controller.ts +28 -28
- package/src/module/auth/dto/user.dto.ts +56 -56
- package/src/module/auth/guards/google-auth.guard.ts +9 -9
- package/src/module/auth/guards/jwt.guard.ts +22 -22
- package/src/module/auth/services/auth.service.ts +56 -56
- package/src/module/auth/services/jwt.service.ts +11 -11
- package/src/module/auth/strategies/google.strategy.ts +54 -54
- package/src/module/auth/strategies/jwt.strategy.ts +65 -65
- package/src/module/auth/strategies/local.strategy.ts +13 -13
- package/src/module/dashboard/controller/dashboard.controller.ts +38 -38
- package/src/module/dashboard/dashboard.module.ts +19 -19
- package/src/module/dashboard/entity/dashboard_page_data.entity.ts +23 -23
- package/src/module/dashboard/entity/widget_master.entity.ts +15 -15
- package/src/module/dashboard/repository/dashboard.repository.ts +49 -49
- package/src/module/dashboard/service/dashboard.service.ts +69 -69
- package/src/module/eav/EAV_USAGE_GUIDE.md +351 -351
- package/src/module/eav/controller/eav.controller.ts +119 -119
- package/src/module/eav/dto/eav-operation.dto.ts +62 -62
- package/src/module/eav/eav.module.ts +79 -79
- package/src/module/eav/entity/eav-boolean.entity.ts +25 -25
- package/src/module/eav/entity/eav-date.entity.ts +24 -24
- package/src/module/eav/entity/eav-decimal.entity.ts +24 -24
- package/src/module/eav/entity/eav-int.entity.ts +24 -24
- package/src/module/eav/entity/eav-json.entity.ts +24 -24
- package/src/module/eav/entity/eav-text.entity.ts +24 -24
- package/src/module/eav/entity/eav-time.entity.ts +24 -24
- package/src/module/eav/entity/eav-timestamp.entity.ts +24 -24
- package/src/module/eav/entity/eav-varchar.entity.ts +24 -24
- package/src/module/eav/interface/eav-strategy.interface.ts +32 -32
- package/src/module/eav/repository/eav-boolean.repository.ts +67 -67
- package/src/module/eav/repository/eav-date.repository.ts +67 -67
- package/src/module/eav/repository/eav-decimal.repository.ts +67 -67
- package/src/module/eav/repository/eav-int.repository.ts +67 -67
- package/src/module/eav/repository/eav-json.repository.ts +67 -67
- package/src/module/eav/repository/eav-text.repository.ts +67 -67
- package/src/module/eav/repository/eav-time.repository.ts +67 -67
- package/src/module/eav/repository/eav-timestamp.repository.ts +67 -67
- package/src/module/eav/repository/eav-varchar.repository.ts +67 -67
- package/src/module/eav/service/eav-boolean.service.ts +64 -64
- package/src/module/eav/service/eav-date.service.ts +64 -64
- package/src/module/eav/service/eav-decimal.service.ts +64 -64
- package/src/module/eav/service/eav-factory.service.ts +93 -93
- package/src/module/eav/service/eav-int.service.ts +64 -64
- package/src/module/eav/service/eav-json.service.ts +64 -64
- package/src/module/eav/service/eav-text.service.ts +64 -64
- package/src/module/eav/service/eav-time.service.ts +64 -64
- package/src/module/eav/service/eav-timestamp.service.ts +64 -64
- package/src/module/eav/service/eav-varchar.service.ts +65 -65
- package/src/module/eav/service/eav.service.ts +116 -116
- package/src/module/entity_json/controller/entity_json.controller.ts +75 -75
- package/src/module/entity_json/docs/FlatJson_Filterin_System.md +2803 -2803
- package/src/module/entity_json/entity/entityJson.entity.ts +42 -42
- package/src/module/entity_json/entity_json.module.ts +22 -22
- package/src/module/entity_json/service/entityJson.repository.ts +37 -37
- package/src/module/entity_json/service/entity_json.service.ts +492 -492
- package/src/module/export/controller/export.controller.ts +83 -83
- package/src/module/export/export.module.ts +14 -14
- package/src/module/export/service/export.service.ts +107 -107
- package/src/module/filter/controller/filter.controller.ts +214 -214
- package/src/module/filter/dto/filter-request.dto.ts +41 -41
- package/src/module/filter/entity/saved-filter-detail.entity.ts +37 -37
- package/src/module/filter/entity/saved-filter-master.entity.ts +30 -30
- package/src/module/filter/filter.module.ts +33 -33
- package/src/module/filter/repository/saved-filter.repository.ts +247 -249
- package/src/module/filter/repository/saved.filter-detail.repository.ts +19 -19
- package/src/module/filter/service/filter-evaluator.service.ts +82 -82
- package/src/module/filter/service/filter.service.ts +1722 -1752
- package/src/module/filter/service/saved-filter.service.ts +164 -164
- package/src/module/ics/controller/ics.controller.ts +21 -21
- package/src/module/ics/dto/ics.dto.ts +55 -55
- package/src/module/ics/ics.module.ts +13 -13
- package/src/module/ics/service/ics.service.ts +57 -57
- package/src/module/integration/controller/calender-event.controller.ts +31 -31
- package/src/module/integration/controller/integration.controller.ts +662 -662
- package/src/module/integration/controller/wrapper.controller.ts +37 -37
- package/src/module/integration/dto/create-config.dto.ts +526 -526
- package/src/module/integration/entity/integration-config.entity.ts +112 -112
- package/src/module/integration/entity/integration-entity-mapper.entity.ts +14 -14
- package/src/module/integration/entity/integration-source.entity.ts +17 -17
- package/src/module/integration/entity/user-integration.entity.ts +71 -71
- package/src/module/integration/examples/usage.example.ts +338 -338
- package/src/module/integration/factories/base.factory.ts +7 -7
- package/src/module/integration/factories/email.factory.ts +49 -49
- package/src/module/integration/factories/integration.factory.ts +121 -121
- package/src/module/integration/factories/sms.factory.ts +51 -51
- package/src/module/integration/factories/telephone.factory.ts +41 -41
- package/src/module/integration/factories/whatsapp.factory.ts +56 -56
- package/src/module/integration/integration.module.ts +110 -110
- package/src/module/integration/service/calendar-event.service.ts +118 -118
- package/src/module/integration/service/integration-entity-mapper.service.ts +17 -17
- package/src/module/integration/service/integration-queue.service.ts +229 -229
- package/src/module/integration/service/integration.service.ts +2632 -2651
- package/src/module/integration/service/oauth.service.ts +224 -226
- package/src/module/integration/service/wrapper.service.ts +753 -754
- package/src/module/integration/strategies/email/gmail-api.strategy.ts +281 -307
- package/src/module/integration/strategies/email/outlook-api.strategy.ts +44 -44
- package/src/module/integration/strategies/email/outlook.strategy.ts +64 -64
- package/src/module/integration/strategies/email/sendgrid-api.strategy.ts +260 -263
- package/src/module/integration/strategies/integration.strategy.ts +97 -97
- package/src/module/integration/strategies/sms/gupshup-sms.strategy.ts +146 -146
- package/src/module/integration/strategies/sms/msg91-sms.strategy.ts +164 -164
- package/src/module/integration/strategies/sms/tubelight-sms.strategy.ts +163 -163
- package/src/module/integration/strategies/telephone/ozonetel-voice.strategy.ts +238 -238
- package/src/module/integration/strategies/telephone/tubelight-voice.strategy.ts +210 -210
- package/src/module/integration/strategies/whatsapp/gupshup-whatsapp.strategy.ts +359 -359
- package/src/module/integration/strategies/whatsapp/tubelight-whatsapp.strategy.ts +372 -372
- package/src/module/integration/strategies/whatsapp/whatsapp-cloud.strategy.ts +403 -403
- package/src/module/integration/strategies/whatsapp/whatsapp.strategy.ts +57 -57
- package/src/module/layout/controller/layout.controller.ts +38 -38
- package/src/module/layout/entity/header-items.entity.ts +28 -28
- package/src/module/layout/entity/header-section.entity.ts +13 -13
- package/src/module/layout/layout.module.ts +20 -20
- package/src/module/layout/repository/header-items.repository.ts +18 -18
- package/src/module/layout/repository/header-section.repository.ts +16 -16
- package/src/module/layout/service/header-section.service.ts +25 -25
- package/src/module/layout_preference/controller/layout_preference.controller.ts +76 -76
- package/src/module/layout_preference/entity/layout_preference.entity.ts +28 -28
- package/src/module/layout_preference/layout_preference.module.ts +22 -22
- package/src/module/layout_preference/repository/layout_preference.repository.ts +65 -65
- package/src/module/layout_preference/service/layout_preference.service.ts +191 -191
- package/src/module/linked_attributes/controller/linked_attributes.controller.ts +137 -137
- package/src/module/linked_attributes/dto/create-linked-attribute-smart.dto.ts +54 -54
- package/src/module/linked_attributes/entity/linked_attribute.entity.ts +51 -51
- package/src/module/linked_attributes/linked_attributes.module.ts +23 -23
- package/src/module/linked_attributes/repository/linked_attribute.repository.ts +12 -12
- package/src/module/linked_attributes/service/linked_attributes.service.ts +650 -650
- package/src/module/linked_attributes/test/linked-attributes.service.spec.ts +244 -244
- package/src/module/listmaster/controller/list-master.controller.ts +226 -215
- package/src/module/listmaster/entity/list-master-items.entity.ts +30 -30
- package/src/module/listmaster/entity/list-master.entity.ts +25 -25
- package/src/module/listmaster/listmaster.module.ts +46 -46
- package/src/module/listmaster/repository/list-master-items.repository.ts +262 -262
- package/src/module/listmaster/repository/list-master.repository.ts +60 -60
- package/src/module/listmaster/service/list-master-engine.ts +19 -19
- package/src/module/listmaster/service/list-master-extension.interface.ts +4 -4
- package/src/module/listmaster/service/list-master-item.service.ts +382 -382
- package/src/module/listmaster/service/list-master-registry.ts +15 -15
- package/src/module/listmaster/service/list-master.service.ts +760 -774
- package/src/module/mapper/controller/field-mapper.controller.ts +76 -76
- package/src/module/mapper/controller/mapper.controller.ts +20 -20
- package/src/module/mapper/dto/field-mapper.dto.ts +14 -14
- package/src/module/mapper/entity/field-lovs.entity.ts +15 -15
- package/src/module/mapper/entity/field-mapper.entity.ts +49 -49
- package/src/module/mapper/entity/mapper.entity.ts +9 -9
- package/src/module/mapper/mapper.module.ts +35 -35
- package/src/module/mapper/repository/field-lovs.repository.ts +35 -35
- package/src/module/mapper/repository/field-mapper.repository.ts +42 -42
- package/src/module/mapper/repository/mapper.repository.ts +32 -32
- package/src/module/mapper/service/field-mapper.service.ts +268 -268
- package/src/module/mapper/service/mapper.service.ts +80 -80
- package/src/module/master/controller/master.controller.ts +71 -71
- package/src/module/master/service/master.service.ts +460 -460
- package/src/module/master/service/poupulate-meta.service.ts +210 -210
- package/src/module/meta/controller/attribute-master.controller.ts +83 -83
- package/src/module/meta/controller/entity-dynamic.controller.ts +123 -123
- package/src/module/meta/controller/entity-master.controller.ts +41 -41
- package/src/module/meta/controller/entity-relation.controller.ts +36 -36
- package/src/module/meta/controller/entity.controller.ts +301 -301
- package/src/module/meta/controller/entity.public.controller.ts +76 -76
- package/src/module/meta/controller/media.controller.ts +135 -162
- package/src/module/meta/controller/meta.controller.ts +80 -80
- package/src/module/meta/controller/view-master.controller.ts +79 -79
- package/src/module/meta/dto/entity-list-data.dto.ts +6 -6
- package/src/module/meta/dto/entity-tab.dto.ts +4 -4
- package/src/module/meta/dto/entity-table.dto.ts +12 -12
- package/src/module/meta/entity/attribute-master.entity.ts +62 -62
- package/src/module/meta/entity/base-entity.entity.ts +52 -52
- package/src/module/meta/entity/dynamic.entity.ts +5 -5
- package/src/module/meta/entity/entity-master.entity.ts +53 -53
- package/src/module/meta/entity/entity-relation-data.entity.ts +24 -24
- package/src/module/meta/entity/entity-relation.entity.ts +18 -18
- package/src/module/meta/entity/entity-table-column.entity.ts +56 -56
- package/src/module/meta/entity/entity-table.entity.ts +45 -45
- package/src/module/meta/entity/media-data.entity.ts +32 -35
- package/src/module/meta/entity/preference.entity.ts +57 -57
- package/src/module/meta/entity/view-master.entity.ts +36 -36
- package/src/module/meta/entity.module.ts +153 -153
- package/src/module/meta/repository/attribute-master.repository.ts +206 -206
- package/src/module/meta/repository/entity-attribute-update.repository.ts +48 -48
- package/src/module/meta/repository/entity-master.repository.ts +120 -120
- package/src/module/meta/repository/entity-relation.repository.ts +36 -36
- package/src/module/meta/repository/entity-table-column.repository.ts +39 -39
- package/src/module/meta/repository/entity-table.repository.ts +53 -53
- package/src/module/meta/repository/media-data.repository.ts +50 -50
- package/src/module/meta/repository/preference.repository.ts +20 -20
- package/src/module/meta/repository/user-app-mapping.repository.ts +28 -28
- package/src/module/meta/repository/view-master.repository.ts +42 -42
- package/src/module/meta/service/attribute-master.service.ts +329 -329
- package/src/module/meta/service/common.service.ts +9 -9
- package/src/module/meta/service/entity-attribute-update.service.ts +26 -26
- package/src/module/meta/service/entity-dynamic.service.ts +1037 -1038
- package/src/module/meta/service/entity-master.service.ts +288 -288
- package/src/module/meta/service/entity-realation-data.service.ts +9 -9
- package/src/module/meta/service/entity-relation.service.ts +85 -85
- package/src/module/meta/service/entity-service-impl.service.ts +390 -390
- package/src/module/meta/service/entity-table-column.service.ts +26 -26
- package/src/module/meta/service/entity-table.service.ts +144 -144
- package/src/module/meta/service/entity-validation.service.ts +187 -187
- package/src/module/meta/service/entity.service.ts +48 -48
- package/src/module/meta/service/field-group.service.ts +103 -103
- package/src/module/meta/service/media-data.service.ts +385 -397
- package/src/module/meta/service/preference.service.ts +16 -16
- package/src/module/meta/service/resolver.service.ts +260 -293
- package/src/module/meta/service/section-master.service.ts +104 -104
- package/src/module/meta/service/update-form-json.service.ts +22 -22
- package/src/module/meta/service/user-app-mapping.service.ts +17 -17
- package/src/module/meta/service/view-master.service.ts +127 -127
- package/src/module/microservice-client/microservice-clients.module.ts +13 -13
- package/src/module/microservice-client/service/microservice-client-factory.ts +37 -37
- package/src/module/microservice-client/service/microservice-clients.ts +4 -4
- package/src/module/notification/controller/notification.controller.ts +58 -58
- package/src/module/notification/entity/notification.entity.ts +76 -76
- package/src/module/notification/entity/otp.entity.ts +28 -28
- package/src/module/notification/firebase-admin.config.ts +22 -22
- package/src/module/notification/notification.module.ts +63 -65
- package/src/module/notification/repository/otp.repository.ts +27 -27
- package/src/module/notification/service/email.service.ts +142 -142
- package/src/module/notification/service/notification.service.ts +163 -145
- package/src/module/preference_master/entity/preference.entity.ts +25 -25
- package/src/module/preference_master/preference.service.ts +27 -27
- package/src/module/preference_master/repo/preference.repository.ts +36 -36
- package/src/module/third-party-module/entity/third-party-api-registry.entity.ts +52 -52
- package/src/module/third-party-module/repository/third-party-api-registry.repository.ts +20 -20
- package/src/module/third-party-module/service/api-registry.service.ts +13 -13
- package/src/module/third-party-module/third-party.module.ts +12 -12
- package/src/module/workflow/controller/action-category.controller.ts +54 -54
- package/src/module/workflow/controller/action-resource-mapping.controller.ts +23 -23
- package/src/module/workflow/controller/action-template-mapping.controller.ts +35 -35
- package/src/module/workflow/controller/action.controller.ts +111 -111
- package/src/module/workflow/controller/activity-log.controller.ts +55 -55
- package/src/module/workflow/controller/comm-template.controller.ts +43 -43
- package/src/module/workflow/controller/entity-modification.controller.ts +35 -35
- package/src/module/workflow/controller/form-master.controller.ts +43 -43
- package/src/module/workflow/controller/stage-group.controller.ts +49 -49
- package/src/module/workflow/controller/stage.controller.ts +51 -51
- package/src/module/workflow/controller/task.controller.ts +77 -77
- package/src/module/workflow/controller/workflow-list-master.controller.ts +44 -44
- package/src/module/workflow/controller/workflow-meta.controller.ts +80 -80
- package/src/module/workflow/controller/workflow.controller.ts +66 -66
- package/src/module/workflow/entity/action-category.entity.ts +33 -33
- package/src/module/workflow/entity/action-data.entity.ts +51 -51
- package/src/module/workflow/entity/action-resources-mapping.entity.ts +21 -21
- package/src/module/workflow/entity/action-template-mapping.entity.ts +12 -12
- package/src/module/workflow/entity/action.entity.ts +48 -48
- package/src/module/workflow/entity/activity-log.entity.ts +39 -39
- package/src/module/workflow/entity/comm-template.entity.ts +38 -38
- package/src/module/workflow/entity/entity-modification.entity.ts +33 -33
- package/src/module/workflow/entity/form.entity.ts +21 -21
- package/src/module/workflow/entity/stage-action-mapping.entity.ts +12 -12
- package/src/module/workflow/entity/stage-group.entity.ts +18 -18
- package/src/module/workflow/entity/stage-movement-data.entity.ts +33 -33
- package/src/module/workflow/entity/stage.entity.ts +15 -15
- package/src/module/workflow/entity/task-data.entity.ts +84 -84
- package/src/module/workflow/entity/template-attach-mapper.entity.ts +30 -30
- package/src/module/workflow/entity/workflow-data.entity.ts +6 -6
- package/src/module/workflow/entity/workflow-level-mapping.entity.ts +18 -18
- package/src/module/workflow/entity/workflow.entity.ts +15 -15
- package/src/module/workflow/repository/action-category.repository.ts +78 -78
- package/src/module/workflow/repository/action-data.repository.ts +345 -353
- package/src/module/workflow/repository/action.repository.ts +339 -339
- package/src/module/workflow/repository/activity-log.repository.ts +148 -148
- package/src/module/workflow/repository/comm-template.repository.ts +157 -157
- package/src/module/workflow/repository/form-master.repository.ts +50 -50
- package/src/module/workflow/repository/stage-group.repository.ts +186 -186
- package/src/module/workflow/repository/stage-movement.repository.ts +217 -217
- package/src/module/workflow/repository/stage.repository.ts +160 -160
- package/src/module/workflow/repository/task.repository.ts +154 -156
- package/src/module/workflow/repository/workflow.repository.ts +42 -42
- package/src/module/workflow/service/action-category.service.ts +32 -32
- package/src/module/workflow/service/action-data.service.ts +62 -62
- package/src/module/workflow/service/action-resources-mapping.service.ts +10 -10
- package/src/module/workflow/service/action-template-mapping.service.ts +137 -137
- package/src/module/workflow/service/action.service.ts +300 -300
- package/src/module/workflow/service/activity-log.service.ts +106 -106
- package/src/module/workflow/service/comm-template.service.ts +179 -179
- package/src/module/workflow/service/entity-modification.service.ts +55 -63
- package/src/module/workflow/service/form-master.service.ts +35 -35
- package/src/module/workflow/service/populate-workflow.service.ts +313 -313
- package/src/module/workflow/service/stage-action-mapping.service.ts +5 -5
- package/src/module/workflow/service/stage-group.service.ts +325 -325
- package/src/module/workflow/service/stage.service.ts +196 -196
- package/src/module/workflow/service/task.service.ts +547 -547
- package/src/module/workflow/service/workflow-list-master.service.ts +68 -68
- package/src/module/workflow/service/workflow-meta.service.ts +638 -638
- package/src/module/workflow/service/workflow.service.ts +212 -212
- package/src/module/workflow/workflow.module.ts +180 -180
- package/src/module/workflow-automation/SCHEDULING_GUIDE.md +145 -145
- package/src/module/workflow-automation/controller/workflow-automation.controller.ts +43 -43
- package/src/module/workflow-automation/entity/workflow-automation-action.entity.ts +26 -26
- package/src/module/workflow-automation/entity/workflow-automation.entity.ts +35 -35
- package/src/module/workflow-automation/interface/action.decorator.ts +7 -7
- package/src/module/workflow-automation/interface/action.interface.ts +5 -5
- package/src/module/workflow-automation/service/action-registery.service.ts +35 -35
- package/src/module/workflow-automation/service/schedule-handler.service.ts +167 -167
- package/src/module/workflow-automation/service/workflow-automation-engine.service.ts +219 -219
- package/src/module/workflow-automation/service/workflow-automation.service.ts +486 -486
- package/src/module/workflow-automation/workflow-automation.module.ts +55 -55
- package/src/module/workflow-schedule/INSTALLATION.md +244 -244
- package/src/module/workflow-schedule/MULTI_PROJECT_GUIDE.md +196 -196
- package/src/module/workflow-schedule/README.md +422 -422
- package/src/module/workflow-schedule/constants/schedule.constants.ts +48 -48
- package/src/module/workflow-schedule/controller/workflow-schedule.controller.ts +253 -253
- package/src/module/workflow-schedule/docs/CLAUDE_CODE_GUIDE.md +510 -510
- package/src/module/workflow-schedule/docs/CLAUDE_CODE_PROMPT.md +362 -362
- package/src/module/workflow-schedule/docs/RUN_CLAUDE_CODE.sh +68 -68
- package/src/module/workflow-schedule/dto/create-schedule.dto.ts +147 -147
- package/src/module/workflow-schedule/dto/get-execution-logs.dto.ts +119 -119
- package/src/module/workflow-schedule/dto/update-schedule.dto.ts +96 -96
- package/src/module/workflow-schedule/entities/scheduled-workflow.entity.ts +148 -148
- package/src/module/workflow-schedule/entities/workflow-execution-log.entity.ts +154 -154
- package/src/module/workflow-schedule/interfaces/schedule-job-data.interface.ts +51 -51
- package/src/module/workflow-schedule/interfaces/workflow-schedule-options.interface.ts +12 -12
- package/src/module/workflow-schedule/processors/schedule.processor.ts +616 -616
- package/src/module/workflow-schedule/service/workflow-schedule.service.ts +588 -588
- package/src/module/workflow-schedule/workflow-schedule.module.ts +67 -67
- package/src/resources/dev.properties.yaml +33 -33
- package/src/resources/local.properties.yaml +27 -27
- package/src/resources/properties.module.ts +12 -12
- package/src/resources/properties.yaml.ts +11 -11
- package/src/resources/uat.properties.yaml +31 -31
- package/src/table.config.ts +123 -123
- package/src/utils/dto/excel-data.dto.ts +14 -14
- package/src/utils/dto/excelsheet-data.dto.ts +5 -5
- package/src/utils/service/base64util.service.ts +18 -18
- package/src/utils/service/clockIDGenUtil.service.ts +21 -21
- package/src/utils/service/codeGenerator.service.ts +22 -22
- package/src/utils/service/dateUtil.service.ts +17 -17
- package/src/utils/service/encryptUtil.service.ts +97 -97
- package/src/utils/service/excel-helper.service.ts +72 -72
- package/src/utils/service/excelUtil.service.ts +15 -15
- package/src/utils/service/file-util.service.ts +11 -11
- package/src/utils/service/json-util.service.ts +23 -23
- package/src/utils/service/loggingUtil.service.ts +88 -88
- package/src/utils/service/reflection-helper.service.ts +62 -62
- package/src/utils/service/wbsCodeGen.service.ts +8 -8
- package/src/utils/utils.module.ts +27 -27
- package/tsconfig.build.json +4 -4
- package/tsconfig.json +24 -24
- package/.idea/250218_ether_core.iml +0 -12
- package/dist/module/notification/repository/notification.repository.d.ts +0 -7
- package/dist/module/notification/repository/notification.repository.js +0 -43
- package/dist/module/notification/repository/notification.repository.js.map +0 -1
- package/src/module/notification/repository/notification.repository.ts +0 -33
|
@@ -1,1038 +1,1037 @@
|
|
|
1
|
-
import { BadRequestException, Injectable } from '@nestjs/common';
|
|
2
|
-
import { STATUS_ACTIVE } from 'src/constant/global.constant';
|
|
3
|
-
import { EntityManager, In } from 'typeorm';
|
|
4
|
-
import { UserData } from 'src/module/auth/dto/user.dto';
|
|
5
|
-
import { MediaDataService } from './media-data.service';
|
|
6
|
-
import { EntityMasterRepository } from '../repository/entity-master.repository';
|
|
7
|
-
import { ConfigService } from '@nestjs/config';
|
|
8
|
-
import { EntityServiceImpl } from './entity-service-impl.service';
|
|
9
|
-
import { EAVService } from '../../eav/service/eav.service';
|
|
10
|
-
import { AttributeStorageType } from '../../../constant/attribute.constant';
|
|
11
|
-
import { StorageType } from '../../../constant/entity.constant';
|
|
12
|
-
|
|
13
|
-
@Injectable()
|
|
14
|
-
export class EntityDynamicService extends EntityServiceImpl {
|
|
15
|
-
constructor(
|
|
16
|
-
private readonly entityManager: EntityManager,
|
|
17
|
-
private readonly mediaDataService: MediaDataService,
|
|
18
|
-
private readonly entityMasterRepo: EntityMasterRepository,
|
|
19
|
-
private readonly configService: ConfigService,
|
|
20
|
-
private readonly eavService: EAVService,
|
|
21
|
-
) {
|
|
22
|
-
super();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
schema = this.configService.get('DB_SCHEMA');
|
|
26
|
-
|
|
27
|
-
// -----------------------------
|
|
28
|
-
async createEntityData(
|
|
29
|
-
entityType: string,
|
|
30
|
-
entityData: Record<string, any>,
|
|
31
|
-
loggedInUser: any,
|
|
32
|
-
mainID?: number,
|
|
33
|
-
): Promise<any> {
|
|
34
|
-
const enterprise_id = loggedInUser.enterprise_id;
|
|
35
|
-
const entityMaster =
|
|
36
|
-
await this.entityMasterRepo.getEntityByMappedEntityType(
|
|
37
|
-
entityType,
|
|
38
|
-
loggedInUser.enterprise_id,
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
if (!entityMaster) {
|
|
42
|
-
throw new BadRequestException(
|
|
43
|
-
`Entity With ${entityType} entity type not found`,
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
let tableName: string;
|
|
47
|
-
if (StorageType.SELF === entityMaster.storage_type) {
|
|
48
|
-
tableName = entityMaster.db_table_name;
|
|
49
|
-
} else {
|
|
50
|
-
tableName = 'frm_entity_dynamic';
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const validAttributes = await this.getAttributeCodes(
|
|
54
|
-
entityType,
|
|
55
|
-
enterprise_id,
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
// -------------------------------------------------------
|
|
59
|
-
// AUTO fields
|
|
60
|
-
// -------------------------------------------------------
|
|
61
|
-
entityData.created_date = new Date();
|
|
62
|
-
|
|
63
|
-
if (loggedInUser) {
|
|
64
|
-
entityData.created_by = loggedInUser.id;
|
|
65
|
-
|
|
66
|
-
if (!entityData.enterprise_id)
|
|
67
|
-
entityData.enterprise_id = loggedInUser.enterprise_id;
|
|
68
|
-
|
|
69
|
-
if (!entityData.level_type)
|
|
70
|
-
entityData.level_type = loggedInUser.level_type;
|
|
71
|
-
|
|
72
|
-
if (!entityData.level_id) entityData.level_id = loggedInUser.level_id;
|
|
73
|
-
|
|
74
|
-
if (!entityData.entity_type) entityData.entity_type = entityType;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// -------------------------------------------------------
|
|
78
|
-
// STATUS
|
|
79
|
-
// -------------------------------------------------------
|
|
80
|
-
const listMasterItemsRepo =
|
|
81
|
-
this.reflectionHelper.getRepoService('ListMasterItems');
|
|
82
|
-
const statusList = listMasterItemsRepo.find({
|
|
83
|
-
where: {
|
|
84
|
-
code: STATUS_ACTIVE,
|
|
85
|
-
enterprise_id: enterprise_id,
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
if (!entityData.status) entityData.status = statusList[0]?.id;
|
|
90
|
-
|
|
91
|
-
// -------------------------------------------------------
|
|
92
|
-
// AUTO-CODE GENERATION (POSTGRES SAFE)
|
|
93
|
-
// -------------------------------------------------------
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
maxSeq
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
//
|
|
106
|
-
//
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
//
|
|
113
|
-
//
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
'
|
|
117
|
-
'
|
|
118
|
-
'
|
|
119
|
-
'
|
|
120
|
-
'
|
|
121
|
-
'
|
|
122
|
-
'
|
|
123
|
-
'
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
//
|
|
140
|
-
//
|
|
141
|
-
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
const
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
const
|
|
381
|
-
const
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
);
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
const
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
//
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
let
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
item
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
relationType === '
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
const
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
const
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
'
|
|
537
|
-
'
|
|
538
|
-
'
|
|
539
|
-
'
|
|
540
|
-
'
|
|
541
|
-
'
|
|
542
|
-
'
|
|
543
|
-
'
|
|
544
|
-
'
|
|
545
|
-
'
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
.
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
//
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
)
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
attr.
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
attr.
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
//
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
);
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
//
|
|
754
|
-
//
|
|
755
|
-
//
|
|
756
|
-
//
|
|
757
|
-
//
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
)
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
attr.
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
attr.
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
.
|
|
861
|
-
.
|
|
862
|
-
.addSelect('MAX(fea.
|
|
863
|
-
.addSelect('MAX(fea.
|
|
864
|
-
.addSelect('
|
|
865
|
-
.
|
|
866
|
-
.
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
//
|
|
914
|
-
//
|
|
915
|
-
//
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
)
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
);
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
}
|
|
1
|
+
import { BadRequestException, Injectable } from '@nestjs/common';
|
|
2
|
+
import { STATUS_ACTIVE } from 'src/constant/global.constant';
|
|
3
|
+
import { EntityManager, In } from 'typeorm';
|
|
4
|
+
import { UserData } from 'src/module/auth/dto/user.dto';
|
|
5
|
+
import { MediaDataService } from './media-data.service';
|
|
6
|
+
import { EntityMasterRepository } from '../repository/entity-master.repository';
|
|
7
|
+
import { ConfigService } from '@nestjs/config';
|
|
8
|
+
import { EntityServiceImpl } from './entity-service-impl.service';
|
|
9
|
+
import { EAVService } from '../../eav/service/eav.service';
|
|
10
|
+
import { AttributeStorageType } from '../../../constant/attribute.constant';
|
|
11
|
+
import { StorageType } from '../../../constant/entity.constant';
|
|
12
|
+
|
|
13
|
+
@Injectable()
|
|
14
|
+
export class EntityDynamicService extends EntityServiceImpl {
|
|
15
|
+
constructor(
|
|
16
|
+
private readonly entityManager: EntityManager,
|
|
17
|
+
private readonly mediaDataService: MediaDataService,
|
|
18
|
+
private readonly entityMasterRepo: EntityMasterRepository,
|
|
19
|
+
private readonly configService: ConfigService,
|
|
20
|
+
private readonly eavService: EAVService,
|
|
21
|
+
) {
|
|
22
|
+
super();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
schema = this.configService.get('DB_SCHEMA');
|
|
26
|
+
|
|
27
|
+
// -----------------------------
|
|
28
|
+
async createEntityData(
|
|
29
|
+
entityType: string,
|
|
30
|
+
entityData: Record<string, any>,
|
|
31
|
+
loggedInUser: any,
|
|
32
|
+
mainID?: number,
|
|
33
|
+
): Promise<any> {
|
|
34
|
+
const enterprise_id = loggedInUser.enterprise_id;
|
|
35
|
+
const entityMaster =
|
|
36
|
+
await this.entityMasterRepo.getEntityByMappedEntityType(
|
|
37
|
+
entityType,
|
|
38
|
+
loggedInUser.enterprise_id,
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
if (!entityMaster) {
|
|
42
|
+
throw new BadRequestException(
|
|
43
|
+
`Entity With ${entityType} entity type not found`,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
let tableName: string;
|
|
47
|
+
if (StorageType.SELF === entityMaster.storage_type) {
|
|
48
|
+
tableName = entityMaster.db_table_name;
|
|
49
|
+
} else {
|
|
50
|
+
tableName = 'frm_entity_dynamic';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const validAttributes = await this.getAttributeCodes(
|
|
54
|
+
entityType,
|
|
55
|
+
enterprise_id,
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
// -------------------------------------------------------
|
|
59
|
+
// AUTO fields
|
|
60
|
+
// -------------------------------------------------------
|
|
61
|
+
entityData.created_date = new Date();
|
|
62
|
+
|
|
63
|
+
if (loggedInUser) {
|
|
64
|
+
entityData.created_by = loggedInUser.id;
|
|
65
|
+
|
|
66
|
+
if (!entityData.enterprise_id)
|
|
67
|
+
entityData.enterprise_id = loggedInUser.enterprise_id;
|
|
68
|
+
|
|
69
|
+
if (!entityData.level_type)
|
|
70
|
+
entityData.level_type = loggedInUser.level_type;
|
|
71
|
+
|
|
72
|
+
if (!entityData.level_id) entityData.level_id = loggedInUser.level_id;
|
|
73
|
+
|
|
74
|
+
if (!entityData.entity_type) entityData.entity_type = entityType;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// -------------------------------------------------------
|
|
78
|
+
// STATUS
|
|
79
|
+
// -------------------------------------------------------
|
|
80
|
+
const listMasterItemsRepo =
|
|
81
|
+
this.reflectionHelper.getRepoService('ListMasterItems');
|
|
82
|
+
const statusList = listMasterItemsRepo.find({
|
|
83
|
+
where: {
|
|
84
|
+
code: STATUS_ACTIVE,
|
|
85
|
+
enterprise_id: enterprise_id,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
if (!entityData.status) entityData.status = statusList[0]?.id;
|
|
90
|
+
|
|
91
|
+
// -------------------------------------------------------
|
|
92
|
+
// AUTO-CODE GENERATION (POSTGRES SAFE)
|
|
93
|
+
// -------------------------------------------------------
|
|
94
|
+
|
|
95
|
+
const maxSeqResult = this.entityManager.query(
|
|
96
|
+
`SELECT MAX(id) as seq_no
|
|
97
|
+
FROM ${this.schema}.${tableName}`,
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
let maxSeq = Number(maxSeqResult[0]?.seq_no) || 0;
|
|
101
|
+
maxSeq++;
|
|
102
|
+
entityData.code = `${entityData.entity_type}${maxSeq}`;
|
|
103
|
+
|
|
104
|
+
// -------------------------------------------------------
|
|
105
|
+
// Parent ID
|
|
106
|
+
// -------------------------------------------------------
|
|
107
|
+
if (mainID) {
|
|
108
|
+
entityData.parent_id = mainID;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// -------------------------------------------------------
|
|
112
|
+
// BYPASS COLUMNS
|
|
113
|
+
// -------------------------------------------------------
|
|
114
|
+
const bypassColumns = [
|
|
115
|
+
'created_date',
|
|
116
|
+
'created_by',
|
|
117
|
+
'enterprise_id',
|
|
118
|
+
'level_type',
|
|
119
|
+
'level_id',
|
|
120
|
+
'status',
|
|
121
|
+
'entity_type',
|
|
122
|
+
'code',
|
|
123
|
+
'parent_id',
|
|
124
|
+
];
|
|
125
|
+
|
|
126
|
+
for (const col of bypassColumns) {
|
|
127
|
+
if (!validAttributes.some((a) => a.attribute_key === col)) {
|
|
128
|
+
validAttributes.push({
|
|
129
|
+
attribute_key: col,
|
|
130
|
+
is_hidden: false,
|
|
131
|
+
db_datatype: 'text',
|
|
132
|
+
element_type: 'text',
|
|
133
|
+
storage_type: AttributeStorageType.DB_COL,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// -------------------------------------------------------
|
|
139
|
+
// BUILD INSERT QUERY (POSTGRES FORMAT)
|
|
140
|
+
// -------------------------------------------------------
|
|
141
|
+
const columns: string[] = [];
|
|
142
|
+
const values: any[] = [];
|
|
143
|
+
let idx = 1;
|
|
144
|
+
const placeholders: string[] = [];
|
|
145
|
+
const eavAttributes: any[] = [];
|
|
146
|
+
|
|
147
|
+
for (const attr of validAttributes) {
|
|
148
|
+
if (attr.attribute_key === 'id' && !entityData.id) continue;
|
|
149
|
+
|
|
150
|
+
if (
|
|
151
|
+
attr.storage_type.toLowerCase() ===
|
|
152
|
+
AttributeStorageType.EAV.toLowerCase()
|
|
153
|
+
) {
|
|
154
|
+
if (entityData[attr.attribute_key] !== undefined) {
|
|
155
|
+
eavAttributes.push({
|
|
156
|
+
key: attr.attribute_key,
|
|
157
|
+
value: entityData[attr.attribute_key],
|
|
158
|
+
data_type: attr.db_datatype,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
} else {
|
|
162
|
+
columns.push(attr.attribute_key);
|
|
163
|
+
values.push(entityData[attr.attribute_key] ?? null);
|
|
164
|
+
placeholders.push(`$${idx++}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const colList = columns.map((c) => `"${c}"`).join(', ');
|
|
169
|
+
const placeholderList = placeholders.join(', ');
|
|
170
|
+
|
|
171
|
+
const sql = `
|
|
172
|
+
INSERT INTO ${this.schema}.${tableName} (${colList})
|
|
173
|
+
VALUES (${placeholderList}) RETURNING *
|
|
174
|
+
`;
|
|
175
|
+
|
|
176
|
+
const result = await this.entityManager.query(sql, values);
|
|
177
|
+
const newId = result[0]?.id;
|
|
178
|
+
|
|
179
|
+
// Save EAV attributes
|
|
180
|
+
if (newId && eavAttributes.length > 0) {
|
|
181
|
+
for (const eavAttr of eavAttributes) {
|
|
182
|
+
if (this.eavService.isTypeSupported(eavAttr.data_type)) {
|
|
183
|
+
await this.eavService.create(
|
|
184
|
+
eavAttr.data_type,
|
|
185
|
+
{
|
|
186
|
+
entity_type: entityType,
|
|
187
|
+
entity_id: newId,
|
|
188
|
+
key: eavAttr.key,
|
|
189
|
+
value: eavAttr.value,
|
|
190
|
+
},
|
|
191
|
+
loggedInUser?.id,
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return result[0];
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// ----------------------------- get entity with relations
|
|
201
|
+
|
|
202
|
+
// ----------------------------- create entity with relations
|
|
203
|
+
async createEntity(
|
|
204
|
+
data: Record<string, any>,
|
|
205
|
+
loggedInUser: any,
|
|
206
|
+
): Promise<any> {
|
|
207
|
+
const entityType = data.entity_type;
|
|
208
|
+
const enterpriseId = loggedInUser.enterprise_id;
|
|
209
|
+
|
|
210
|
+
const repo = this.reflectionHelper.getRepoService('EntityRelation');
|
|
211
|
+
|
|
212
|
+
const getRelation = await repo.find({
|
|
213
|
+
where: {
|
|
214
|
+
enterprise_id: enterpriseId,
|
|
215
|
+
source_entity_type: entityType,
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
const { mappedEntities, ...mainData } = data;
|
|
220
|
+
|
|
221
|
+
// create main entity
|
|
222
|
+
const createdEntityData = await this.createEntityData(
|
|
223
|
+
entityType,
|
|
224
|
+
mainData,
|
|
225
|
+
loggedInUser,
|
|
226
|
+
);
|
|
227
|
+
const mainID = createdEntityData.insertId || createdEntityData.id;
|
|
228
|
+
|
|
229
|
+
if (mappedEntities && getRelation.length > 0) {
|
|
230
|
+
for (const relation of getRelation) {
|
|
231
|
+
const targetEntityType = relation.target_entity_type;
|
|
232
|
+
const relationType = relation.relation_type;
|
|
233
|
+
|
|
234
|
+
if (!mappedEntities[targetEntityType]) continue;
|
|
235
|
+
|
|
236
|
+
// normalize: always array
|
|
237
|
+
const entityDataArray = Array.isArray(mappedEntities[targetEntityType])
|
|
238
|
+
? mappedEntities[targetEntityType]
|
|
239
|
+
: [mappedEntities[targetEntityType]];
|
|
240
|
+
|
|
241
|
+
for (const item of entityDataArray) {
|
|
242
|
+
const itemWithRef = {
|
|
243
|
+
...item,
|
|
244
|
+
entity_type: targetEntityType,
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
const createdRelatedEntity = await this.createEntityData(
|
|
248
|
+
targetEntityType,
|
|
249
|
+
itemWithRef,
|
|
250
|
+
loggedInUser,
|
|
251
|
+
mainID, // this will pass for parent_id
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
const relationRepo =
|
|
255
|
+
this.reflectionHelper.getRepoService('EntityRelationData');
|
|
256
|
+
|
|
257
|
+
await relationRepo.save({
|
|
258
|
+
enterprise_id: enterpriseId,
|
|
259
|
+
source_entity_id: mainID,
|
|
260
|
+
source_entity_type: entityType,
|
|
261
|
+
target_entity_id: createdRelatedEntity.id,
|
|
262
|
+
target_entity_type: targetEntityType,
|
|
263
|
+
relation_type: relationType,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return {
|
|
270
|
+
mainEntity: {
|
|
271
|
+
id: mainID,
|
|
272
|
+
entityType,
|
|
273
|
+
data: createdEntityData,
|
|
274
|
+
},
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// ----------------------------- get entity with relations
|
|
279
|
+
async getEntityData(
|
|
280
|
+
entityType: string,
|
|
281
|
+
id: number | string,
|
|
282
|
+
loggedInUser: any,
|
|
283
|
+
resolved?: boolean,
|
|
284
|
+
): Promise<any> {
|
|
285
|
+
let mainEntity = await this.getEntityByDataSource(
|
|
286
|
+
entityType,
|
|
287
|
+
id,
|
|
288
|
+
loggedInUser,
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
if (resolved) {
|
|
292
|
+
mainEntity = await this.resolverService.getResolvedData(
|
|
293
|
+
loggedInUser,
|
|
294
|
+
mainEntity,
|
|
295
|
+
entityType,
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const relationRepo = this.reflectionHelper.getRepoService('EntityRelation');
|
|
300
|
+
const relatedEntityRepo =
|
|
301
|
+
this.reflectionHelper.getRepoService('EntityRelationData');
|
|
302
|
+
|
|
303
|
+
const relations = await relationRepo.find({
|
|
304
|
+
where: {
|
|
305
|
+
source_entity_type: entityType,
|
|
306
|
+
enterprise_id: loggedInUser.enterprise_id,
|
|
307
|
+
},
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
const targetTypes = relations.map((r) => r.target_entity_type);
|
|
311
|
+
|
|
312
|
+
if (targetTypes.length === 0) {
|
|
313
|
+
return {
|
|
314
|
+
entity_type: entityType,
|
|
315
|
+
...mainEntity,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const relatedEntities = await relatedEntityRepo.find({
|
|
320
|
+
where: {
|
|
321
|
+
source_entity_id: id,
|
|
322
|
+
target_entity_type: In(targetTypes),
|
|
323
|
+
},
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
// Format response to match create entity structure
|
|
327
|
+
const response: any = {
|
|
328
|
+
entity_type: entityType,
|
|
329
|
+
...mainEntity,
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
if (relatedEntities.length > 0) {
|
|
333
|
+
response.mappedEntities = await this.formatMappedEntities(
|
|
334
|
+
relatedEntities,
|
|
335
|
+
loggedInUser,
|
|
336
|
+
resolved,
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
return response;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// ----------------------------- formatMappedEntities
|
|
344
|
+
async formatMappedEntities(
|
|
345
|
+
relatedEntities: any[],
|
|
346
|
+
loggedInUser: any,
|
|
347
|
+
resolved?: boolean,
|
|
348
|
+
): Promise<any> {
|
|
349
|
+
const mappedEntities: any = {};
|
|
350
|
+
|
|
351
|
+
for (const relation of relatedEntities) {
|
|
352
|
+
const targetEntityType = relation.target_entity_type;
|
|
353
|
+
const targetEntityId = relation.target_entity_id;
|
|
354
|
+
|
|
355
|
+
const entityData = await this.getEntityData(
|
|
356
|
+
targetEntityType,
|
|
357
|
+
targetEntityId,
|
|
358
|
+
loggedInUser,
|
|
359
|
+
resolved,
|
|
360
|
+
);
|
|
361
|
+
|
|
362
|
+
if (!mappedEntities[targetEntityType]) {
|
|
363
|
+
mappedEntities[targetEntityType] = [];
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
mappedEntities[targetEntityType].push(entityData);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
return mappedEntities;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// ----------------------------- update with relations
|
|
373
|
+
|
|
374
|
+
// ----------------------------- update entity with relations
|
|
375
|
+
async updateEntity(
|
|
376
|
+
data: Record<string, any>,
|
|
377
|
+
loggedInUser: any,
|
|
378
|
+
): Promise<any> {
|
|
379
|
+
const entityType = data.entity_type;
|
|
380
|
+
const enterpriseId = loggedInUser.enterprise_id;
|
|
381
|
+
const { mappedEntities, ...mainData } = data;
|
|
382
|
+
|
|
383
|
+
// Update main entity
|
|
384
|
+
const updatedMainEntity = await this.updateEntityData(
|
|
385
|
+
entityType,
|
|
386
|
+
data.id,
|
|
387
|
+
mainData,
|
|
388
|
+
loggedInUser,
|
|
389
|
+
);
|
|
390
|
+
|
|
391
|
+
const updatedRelations: Record<string, any> = {};
|
|
392
|
+
|
|
393
|
+
if (mappedEntities) {
|
|
394
|
+
const entityRelationRepo =
|
|
395
|
+
this.reflectionHelper.getRepoService('EntityRelation');
|
|
396
|
+
const getRelationDefs = await entityRelationRepo.find({
|
|
397
|
+
where: {
|
|
398
|
+
enterprise_id: enterpriseId,
|
|
399
|
+
source_entity_type: entityType,
|
|
400
|
+
},
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
for (const [targetEntityType, rawEntityData] of Object.entries(
|
|
404
|
+
mappedEntities,
|
|
405
|
+
)) {
|
|
406
|
+
const relationDef = getRelationDefs.find(
|
|
407
|
+
(r) => r.target_entity_type === targetEntityType,
|
|
408
|
+
);
|
|
409
|
+
if (!relationDef) continue;
|
|
410
|
+
|
|
411
|
+
const relationType = relationDef.relation_type;
|
|
412
|
+
const entityArray = Array.isArray(rawEntityData)
|
|
413
|
+
? rawEntityData
|
|
414
|
+
: [rawEntityData];
|
|
415
|
+
|
|
416
|
+
// Delete previous relations and related entities
|
|
417
|
+
// Create/update new entities & relations
|
|
418
|
+
const updatedEntities: any[] = [];
|
|
419
|
+
|
|
420
|
+
for (const item of entityArray) {
|
|
421
|
+
let targetEntityId;
|
|
422
|
+
let entityData;
|
|
423
|
+
|
|
424
|
+
if (item.id) {
|
|
425
|
+
// Update existing entity
|
|
426
|
+
await this.updateEntityData(
|
|
427
|
+
targetEntityType,
|
|
428
|
+
item.id,
|
|
429
|
+
item,
|
|
430
|
+
loggedInUser,
|
|
431
|
+
Number(data.id), // pass main entity id as parent_id
|
|
432
|
+
);
|
|
433
|
+
targetEntityId = item.id;
|
|
434
|
+
entityData = await this.getEntity(
|
|
435
|
+
targetEntityType,
|
|
436
|
+
targetEntityId,
|
|
437
|
+
loggedInUser,
|
|
438
|
+
);
|
|
439
|
+
} else {
|
|
440
|
+
// Create new entity
|
|
441
|
+
const createdEntity = await this.createEntityData(
|
|
442
|
+
targetEntityType,
|
|
443
|
+
item,
|
|
444
|
+
loggedInUser,
|
|
445
|
+
Number(data.id), // pass main entity id as parent_id
|
|
446
|
+
);
|
|
447
|
+
targetEntityId = createdEntity.insertId || createdEntity.id;
|
|
448
|
+
entityData = await this.getEntity(
|
|
449
|
+
targetEntityType,
|
|
450
|
+
targetEntityId,
|
|
451
|
+
loggedInUser,
|
|
452
|
+
);
|
|
453
|
+
|
|
454
|
+
// Insert relation as per new entity created
|
|
455
|
+
const entityRelationDataRepo =
|
|
456
|
+
this.reflectionHelper.getRepoService('EntityRelationData');
|
|
457
|
+
await entityRelationDataRepo.save({
|
|
458
|
+
enterprise_id: enterpriseId,
|
|
459
|
+
source_entity_id: data.id,
|
|
460
|
+
source_entity_type: entityType,
|
|
461
|
+
target_entity_id: targetEntityId,
|
|
462
|
+
target_entity_type: targetEntityType,
|
|
463
|
+
relation_type: relationType,
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
if (relationType === 'ONE_TO_MANY') {
|
|
468
|
+
updatedEntities.push(entityData);
|
|
469
|
+
} else if (
|
|
470
|
+
relationType === 'ONE_TO_ONE' ||
|
|
471
|
+
relationType === 'MANY_TO_ONE'
|
|
472
|
+
) {
|
|
473
|
+
updatedEntities[0] = entityData; // single object
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
// Assign to response mappedEntities
|
|
478
|
+
updatedRelations[targetEntityType] =
|
|
479
|
+
relationType === 'ONE_TO_MANY' ? updatedEntities : updatedEntities[0];
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
return {
|
|
484
|
+
mainEntity: {
|
|
485
|
+
id: data.id,
|
|
486
|
+
entityType,
|
|
487
|
+
data: updatedMainEntity,
|
|
488
|
+
},
|
|
489
|
+
relatedEntities: updatedRelations,
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// -----------------------------
|
|
494
|
+
async updateEntityData(
|
|
495
|
+
entityType: string,
|
|
496
|
+
id: number | string,
|
|
497
|
+
entityData: Record<string, any>,
|
|
498
|
+
loggedInUser: any,
|
|
499
|
+
mainID?: number,
|
|
500
|
+
): Promise<any> {
|
|
501
|
+
const enterprise_id = loggedInUser.enterprise_id;
|
|
502
|
+
|
|
503
|
+
const tableName = await this.getTableName(entityType, enterprise_id);
|
|
504
|
+
const validAttributes = await this.getAttributeCodes(
|
|
505
|
+
entityType,
|
|
506
|
+
enterprise_id,
|
|
507
|
+
);
|
|
508
|
+
|
|
509
|
+
const updates: string[] = [];
|
|
510
|
+
const values: any[] = [];
|
|
511
|
+
let idx = 1;
|
|
512
|
+
|
|
513
|
+
// Auto fields
|
|
514
|
+
entityData.modified_date = new Date();
|
|
515
|
+
if (loggedInUser) {
|
|
516
|
+
entityData.modified_by = loggedInUser.id;
|
|
517
|
+
|
|
518
|
+
if (!entityData.enterprise_id)
|
|
519
|
+
entityData.enterprise_id = loggedInUser.enterprise_id;
|
|
520
|
+
|
|
521
|
+
if (!entityData.level_type)
|
|
522
|
+
entityData.level_type = loggedInUser.level_type;
|
|
523
|
+
|
|
524
|
+
if (!entityData.level_id) entityData.level_id = loggedInUser.level_id;
|
|
525
|
+
|
|
526
|
+
if (!entityData.entity_type) entityData.entity_type = entityType;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
if (mainID) {
|
|
530
|
+
entityData.parent_id = mainID;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
// Add bypass columns if needed
|
|
534
|
+
const bypassColumns = [
|
|
535
|
+
'created_date',
|
|
536
|
+
'created_by',
|
|
537
|
+
'modified_date',
|
|
538
|
+
'modified_by',
|
|
539
|
+
'enterprise_id',
|
|
540
|
+
'level_type',
|
|
541
|
+
'level_id',
|
|
542
|
+
'status',
|
|
543
|
+
'entity_type',
|
|
544
|
+
'code',
|
|
545
|
+
'parent_id',
|
|
546
|
+
];
|
|
547
|
+
|
|
548
|
+
for (const col of bypassColumns) {
|
|
549
|
+
if (!validAttributes.some((attr) => attr.attribute_key === col)) {
|
|
550
|
+
validAttributes.push({
|
|
551
|
+
attribute_key: col,
|
|
552
|
+
db_datatype: 'text',
|
|
553
|
+
element_type: 'text',
|
|
554
|
+
is_hidden: false,
|
|
555
|
+
storage_type: AttributeStorageType.DB_COL,
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
const eavAttributes: any[] = [];
|
|
561
|
+
|
|
562
|
+
// Build SET clause
|
|
563
|
+
for (const key of Object.keys(entityData)) {
|
|
564
|
+
const attr = validAttributes.find((attr) => attr.attribute_key === key);
|
|
565
|
+
if (attr) {
|
|
566
|
+
if (
|
|
567
|
+
attr.storage_type.toLowerCase() ===
|
|
568
|
+
AttributeStorageType.EAV.toLowerCase()
|
|
569
|
+
) {
|
|
570
|
+
eavAttributes.push({
|
|
571
|
+
key: attr.attribute_key,
|
|
572
|
+
value: entityData[key],
|
|
573
|
+
data_type: attr.db_datatype,
|
|
574
|
+
});
|
|
575
|
+
} else {
|
|
576
|
+
updates.push(`${key} = $${idx++}`);
|
|
577
|
+
values.push(entityData[key]);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
if (updates.length === 0 && eavAttributes.length === 0) {
|
|
583
|
+
throw new Error('No valid attributes to update.');
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
let result;
|
|
587
|
+
|
|
588
|
+
if (updates.length > 0) {
|
|
589
|
+
// WHERE clause placeholder
|
|
590
|
+
const idPlaceholder = `$${idx}`;
|
|
591
|
+
values.push(id);
|
|
592
|
+
|
|
593
|
+
const updateQuery = `
|
|
594
|
+
UPDATE ${this.schema}.${tableName}
|
|
595
|
+
SET ${updates.join(', ')}
|
|
596
|
+
WHERE id = ${idPlaceholder}
|
|
597
|
+
`;
|
|
598
|
+
|
|
599
|
+
result = await this.entityManager.query(updateQuery, values);
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
// Process EAV Updates
|
|
603
|
+
if (eavAttributes.length > 0) {
|
|
604
|
+
for (const eavAttr of eavAttributes) {
|
|
605
|
+
if (this.eavService.isTypeSupported(eavAttr.data_type)) {
|
|
606
|
+
await this.eavService.upsert(
|
|
607
|
+
eavAttr.data_type,
|
|
608
|
+
{
|
|
609
|
+
entity_type: entityType,
|
|
610
|
+
entity_id: id,
|
|
611
|
+
key: eavAttr.key,
|
|
612
|
+
value: eavAttr.value,
|
|
613
|
+
},
|
|
614
|
+
loggedInUser?.id,
|
|
615
|
+
);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
return result || { message: 'EAV updated' };
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
async getEntityByDataSource(
|
|
624
|
+
entityType: string,
|
|
625
|
+
id: number | string,
|
|
626
|
+
loggedInUser: any,
|
|
627
|
+
): Promise<any> {
|
|
628
|
+
const enterprise_id = loggedInUser.enterprise_id;
|
|
629
|
+
|
|
630
|
+
const entityMaster = await this.entityMasterService.getEntityData(
|
|
631
|
+
entityType,
|
|
632
|
+
loggedInUser,
|
|
633
|
+
);
|
|
634
|
+
|
|
635
|
+
let dataSource: string;
|
|
636
|
+
if (StorageType.SELF === entityMaster.storage_type) {
|
|
637
|
+
dataSource = entityMaster.db_table_name;
|
|
638
|
+
} else {
|
|
639
|
+
dataSource = 'frm_entity_dynamic';
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
const validAttributes = await this.getAttributeCodes(
|
|
643
|
+
entityType,
|
|
644
|
+
enterprise_id,
|
|
645
|
+
false,
|
|
646
|
+
);
|
|
647
|
+
|
|
648
|
+
// Filter out EAV attributes from SQL query
|
|
649
|
+
const dbColumns = validAttributes.filter(
|
|
650
|
+
(attr) => attr.storage_type !== AttributeStorageType.EAV,
|
|
651
|
+
);
|
|
652
|
+
const columns = dbColumns
|
|
653
|
+
.map((attr) => `"${attr.attribute_key}"`)
|
|
654
|
+
.join(', ');
|
|
655
|
+
|
|
656
|
+
// Add id if not present (required)
|
|
657
|
+
// Note: If columns is empty (only EAV attributes), we still need to select something.
|
|
658
|
+
let selectColumns = columns;
|
|
659
|
+
if (!columns) {
|
|
660
|
+
selectColumns = 'id';
|
|
661
|
+
} else if (!dbColumns.some((c) => c.attribute_key === 'id')) {
|
|
662
|
+
selectColumns += ', id';
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
const selectQuery = `SELECT ${selectColumns}
|
|
666
|
+
FROM ${this.schema}.${dataSource}
|
|
667
|
+
WHERE id = $1`;
|
|
668
|
+
|
|
669
|
+
const result = await this.entityManager.query(selectQuery, [id]);
|
|
670
|
+
if (!result.length) return null;
|
|
671
|
+
|
|
672
|
+
const row = result[0];
|
|
673
|
+
|
|
674
|
+
// Fetch EAV attributes
|
|
675
|
+
const eavAttributes = validAttributes.filter(
|
|
676
|
+
(attr) => attr.storage_type === AttributeStorageType.EAV,
|
|
677
|
+
);
|
|
678
|
+
if (eavAttributes.length > 0) {
|
|
679
|
+
for (const attr of eavAttributes) {
|
|
680
|
+
if (this.eavService.isTypeSupported(attr.db_datatype)) {
|
|
681
|
+
const eavData = await this.eavService.findOne(attr.db_datatype, {
|
|
682
|
+
entity_type: entityType,
|
|
683
|
+
entity_id: id,
|
|
684
|
+
key: attr.attribute_key,
|
|
685
|
+
});
|
|
686
|
+
|
|
687
|
+
if (eavData) {
|
|
688
|
+
row[attr.attribute_key] = eavData.value;
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
// Convert boolean columns (1/0) into true/false
|
|
695
|
+
for (const attr of validAttributes) {
|
|
696
|
+
if (
|
|
697
|
+
attr.db_datatype == 'boolean' &&
|
|
698
|
+
row[attr.attribute_key] !== undefined
|
|
699
|
+
) {
|
|
700
|
+
row[attr.attribute_key] = row[attr.attribute_key] == 1 ? true : false;
|
|
701
|
+
} else if (
|
|
702
|
+
attr.element_type == 'upload' &&
|
|
703
|
+
row[attr.attribute_key] !== undefined
|
|
704
|
+
) {
|
|
705
|
+
row[attr.attribute_key] =
|
|
706
|
+
row[attr.attribute_key] != null
|
|
707
|
+
? await this.mediaDataService.getMediaDownloadUrl(
|
|
708
|
+
Number(row[attr.attribute_key]),
|
|
709
|
+
loggedInUser,
|
|
710
|
+
)
|
|
711
|
+
: null;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
return row;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
// -----------------------------
|
|
719
|
+
//TODO : make it normal getEntity function make another function if for resolve data
|
|
720
|
+
async getEntity(
|
|
721
|
+
entityType: string,
|
|
722
|
+
id: number | string,
|
|
723
|
+
loggedInUser: any,
|
|
724
|
+
): Promise<any> {
|
|
725
|
+
const enterprise_id = loggedInUser.enterprise_id;
|
|
726
|
+
|
|
727
|
+
const entityMaster =
|
|
728
|
+
await this.entityMasterRepo.getEntityByMappedEntityType(
|
|
729
|
+
entityType,
|
|
730
|
+
enterprise_id,
|
|
731
|
+
);
|
|
732
|
+
if (!entityMaster) return null;
|
|
733
|
+
|
|
734
|
+
const validAttributes = await this.getAttributeCodes(
|
|
735
|
+
entityType,
|
|
736
|
+
enterprise_id,
|
|
737
|
+
);
|
|
738
|
+
|
|
739
|
+
// const entityRepo = this.reflectionHelper.getRepoService(entityMaster?.entity_data_class);
|
|
740
|
+
|
|
741
|
+
// Filter out EAV attributes from SQL query
|
|
742
|
+
const dbColumns = validAttributes.filter(
|
|
743
|
+
(attr) => attr.storage_type !== AttributeStorageType.EAV,
|
|
744
|
+
);
|
|
745
|
+
const columns = dbColumns.map((attr) => `t.${attr.attribute_key}`);
|
|
746
|
+
|
|
747
|
+
// Add id if not present (required)
|
|
748
|
+
if (!columns.some((c) => c.includes('.id'))) {
|
|
749
|
+
columns.push('t.id');
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
// const result = await entityRepo.find({
|
|
753
|
+
// where: {
|
|
754
|
+
// id: id
|
|
755
|
+
// },
|
|
756
|
+
// select: columns
|
|
757
|
+
// });
|
|
758
|
+
const selectQuery = `SELECT ${columns.join(', ')}
|
|
759
|
+
FROM ${this.schema}.${entityMaster.db_table_name} t
|
|
760
|
+
WHERE id = $1`;
|
|
761
|
+
|
|
762
|
+
const result = await this.entityManager.query(selectQuery, [id]);
|
|
763
|
+
if (!result.length) return null;
|
|
764
|
+
|
|
765
|
+
const row = result[0];
|
|
766
|
+
|
|
767
|
+
// Fetch EAV attributes
|
|
768
|
+
const eavAttributes = validAttributes.filter(
|
|
769
|
+
(attr) => attr.storage_type === AttributeStorageType.EAV,
|
|
770
|
+
);
|
|
771
|
+
if (eavAttributes.length > 0) {
|
|
772
|
+
for (const attr of eavAttributes) {
|
|
773
|
+
if (this.eavService.isTypeSupported(attr.db_datatype)) {
|
|
774
|
+
const eavData = await this.eavService.findOne(attr.db_datatype, {
|
|
775
|
+
entity_type: entityType,
|
|
776
|
+
entity_id: id,
|
|
777
|
+
key: attr.attribute_key,
|
|
778
|
+
});
|
|
779
|
+
|
|
780
|
+
if (eavData) {
|
|
781
|
+
row[attr.attribute_key] = eavData.value;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
// Convert boolean columns (1/0) into true/false
|
|
788
|
+
for (const attr of validAttributes) {
|
|
789
|
+
if (
|
|
790
|
+
attr.db_datatype == 'boolean' &&
|
|
791
|
+
row[attr.attribute_key] !== undefined
|
|
792
|
+
) {
|
|
793
|
+
row[attr.attribute_key] = row[attr.attribute_key] == 1 ? true : false;
|
|
794
|
+
} else if (
|
|
795
|
+
attr.element_type == 'upload' &&
|
|
796
|
+
row[attr.attribute_key] !== undefined
|
|
797
|
+
) {
|
|
798
|
+
row[attr.attribute_key] =
|
|
799
|
+
row[attr.attribute_key] != null
|
|
800
|
+
? await this.mediaDataService.getMediaDownloadUrl(
|
|
801
|
+
Number(row[attr.attribute_key]),
|
|
802
|
+
loggedInUser,
|
|
803
|
+
)
|
|
804
|
+
: null;
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
return row;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
private async getEntitySourceTableName(
|
|
812
|
+
entityType: string,
|
|
813
|
+
enterprise_id: string,
|
|
814
|
+
): Promise<string> {
|
|
815
|
+
const result = await this.entityMasterRepo.getEntityByMappedEntityType(
|
|
816
|
+
entityType,
|
|
817
|
+
enterprise_id,
|
|
818
|
+
);
|
|
819
|
+
|
|
820
|
+
if (!result) {
|
|
821
|
+
console.log(`Entity type '${entityType}' not found in frm_entity_master`);
|
|
822
|
+
throw new BadRequestException();
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
return result.data_source;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
// -----------------------------
|
|
829
|
+
private async getTableName(
|
|
830
|
+
entityType: string,
|
|
831
|
+
enterprise_id: string,
|
|
832
|
+
): Promise<string> {
|
|
833
|
+
let entityMaster = await this.entityMasterRepo.getEntityByMappedEntityType(
|
|
834
|
+
entityType,
|
|
835
|
+
enterprise_id,
|
|
836
|
+
);
|
|
837
|
+
|
|
838
|
+
if (!entityMaster) {
|
|
839
|
+
console.log(`Entity type '${entityType}' not found in frm_entity_master`);
|
|
840
|
+
throw new BadRequestException();
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
if (entityMaster.storage_type === StorageType.SELF) {
|
|
844
|
+
return entityMaster.db_table_name;
|
|
845
|
+
} else {
|
|
846
|
+
return 'frm_entity_dynamic';
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
private async getAttributeCodes(
|
|
851
|
+
entityType: string,
|
|
852
|
+
enterprise_id: string,
|
|
853
|
+
isHidden = true,
|
|
854
|
+
) {
|
|
855
|
+
const attributeMasterRepo =
|
|
856
|
+
this.reflectionHelper.getRepoService('AttributeMaster');
|
|
857
|
+
|
|
858
|
+
const qb = attributeMasterRepo
|
|
859
|
+
.createQueryBuilder('fea')
|
|
860
|
+
.select('fea.attribute_key', 'attribute_key')
|
|
861
|
+
.addSelect('MAX(fea.db_datatype)', 'db_datatype')
|
|
862
|
+
.addSelect('MAX(fea.element_type)', 'element_type')
|
|
863
|
+
.addSelect('MAX(fea.storage_type)', 'storage_type')
|
|
864
|
+
.addSelect('bool_or(fea.is_hidden)', 'is_hidden')
|
|
865
|
+
.where('fea.mapped_entity_type = :entityType', { entityType })
|
|
866
|
+
.andWhere('fea.enterprise_id = :enterprise_id', { enterprise_id });
|
|
867
|
+
|
|
868
|
+
if (isHidden) {
|
|
869
|
+
qb.andWhere('(fea.is_hidden IS NULL OR fea.is_hidden = false)');
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
qb.groupBy('fea.attribute_key');
|
|
873
|
+
|
|
874
|
+
const result = await qb.getRawMany();
|
|
875
|
+
|
|
876
|
+
return result.map((row: any) => ({
|
|
877
|
+
attribute_key: row.attribute_key,
|
|
878
|
+
db_datatype: row.db_datatype,
|
|
879
|
+
element_type: row.element_type,
|
|
880
|
+
storage_type: row.storage_type,
|
|
881
|
+
is_hidden: row.is_hidden != null ? row.is_hidden === true : undefined,
|
|
882
|
+
}));
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
async deleteEntity(
|
|
886
|
+
entityType: string,
|
|
887
|
+
id: number | string,
|
|
888
|
+
loggedInUser: any,
|
|
889
|
+
): Promise<any> {
|
|
890
|
+
const enterprise_id = loggedInUser.enterprise_id;
|
|
891
|
+
|
|
892
|
+
const tableName = await this.getTableName(entityType, enterprise_id);
|
|
893
|
+
|
|
894
|
+
// Delete EAV records first
|
|
895
|
+
const validAttributes = await this.getAttributeCodes(
|
|
896
|
+
entityType,
|
|
897
|
+
enterprise_id,
|
|
898
|
+
false,
|
|
899
|
+
);
|
|
900
|
+
const eavAttributes = validAttributes.filter(
|
|
901
|
+
(attr) => attr.storage_type === AttributeStorageType.EAV,
|
|
902
|
+
);
|
|
903
|
+
|
|
904
|
+
if (eavAttributes.length > 0) {
|
|
905
|
+
// Group by data type to minimize calls
|
|
906
|
+
const dataTypes = [
|
|
907
|
+
...new Set(eavAttributes.map((attr) => attr.db_datatype)),
|
|
908
|
+
];
|
|
909
|
+
|
|
910
|
+
for (const dataType of dataTypes) {
|
|
911
|
+
if (this.eavService.isTypeSupported(dataType)) {
|
|
912
|
+
// We need to delete all attributes for this entity_id and data source
|
|
913
|
+
// Since delete accepts key, we iterate over keys or finding a way to delete all for entity
|
|
914
|
+
// The current EAV service delete method requires a key.
|
|
915
|
+
// Ideally EAV service should support delete by entity_id alone, but sticking to interface:
|
|
916
|
+
const attrsOfType = eavAttributes.filter(
|
|
917
|
+
(attr) => attr.db_datatype === dataType,
|
|
918
|
+
);
|
|
919
|
+
for (const attr of attrsOfType) {
|
|
920
|
+
await this.eavService.delete(dataType, {
|
|
921
|
+
entity_type: entityType,
|
|
922
|
+
entity_id: id,
|
|
923
|
+
key: attr.attribute_key,
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
const deleteQuery = `DELETE
|
|
931
|
+
FROM ${this.schema}.${tableName}
|
|
932
|
+
WHERE id = $1`;
|
|
933
|
+
const result = await this.entityManager.query(deleteQuery, [id]);
|
|
934
|
+
return result;
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
// -----------------------------
|
|
938
|
+
|
|
939
|
+
async getEntitiesDropdownList(
|
|
940
|
+
loggedInUser: any,
|
|
941
|
+
appcode?: string,
|
|
942
|
+
): Promise<any> {
|
|
943
|
+
const entityMasters =
|
|
944
|
+
await this.entityMasterRepo.findByEnterpriseIdAndAppCode(
|
|
945
|
+
loggedInUser.enterprise_id,
|
|
946
|
+
appcode,
|
|
947
|
+
);
|
|
948
|
+
|
|
949
|
+
let dropdown = [] as any;
|
|
950
|
+
entityMasters.map((entityMaster) =>
|
|
951
|
+
dropdown.push({
|
|
952
|
+
label: entityMaster.name,
|
|
953
|
+
value: entityMaster.mapped_entity_type,
|
|
954
|
+
}),
|
|
955
|
+
);
|
|
956
|
+
|
|
957
|
+
return dropdown;
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
async getCode(entityType: string, loggedInUser: any): Promise<string> {
|
|
961
|
+
const enterprise_id = loggedInUser.enterprise_id;
|
|
962
|
+
|
|
963
|
+
// 1. Get db_table_name from entity master
|
|
964
|
+
|
|
965
|
+
const result = await this.entityMasterRepo.getEntityByMappedEntityType(
|
|
966
|
+
entityType,
|
|
967
|
+
enterprise_id,
|
|
968
|
+
);
|
|
969
|
+
|
|
970
|
+
if (!result) {
|
|
971
|
+
throw new Error(
|
|
972
|
+
`Entity type '${entityType}' not found in frm_entity_master for enterprise '${enterprise_id}'`,
|
|
973
|
+
);
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
const tableName = result.db_table_name;
|
|
977
|
+
|
|
978
|
+
// 2. Get current max sequence number from that table
|
|
979
|
+
const seqResult = await this.entityManager.query(
|
|
980
|
+
`SELECT MAX(id) AS max_seq_no
|
|
981
|
+
FROM ${this.schema}.${tableName}
|
|
982
|
+
WHERE entity_type = $1`,
|
|
983
|
+
[entityType],
|
|
984
|
+
);
|
|
985
|
+
|
|
986
|
+
let maxSeqNo = seqResult?.[0]?.max_seq_no
|
|
987
|
+
? Number(seqResult[0].max_seq_no)
|
|
988
|
+
: 0;
|
|
989
|
+
|
|
990
|
+
maxSeqNo += 1;
|
|
991
|
+
|
|
992
|
+
// 3. Return generated code
|
|
993
|
+
return `${entityType}${maxSeqNo}`;
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
async getResolvedEntity(
|
|
997
|
+
id: number,
|
|
998
|
+
entity: string,
|
|
999
|
+
loggedInUser: UserData,
|
|
1000
|
+
): Promise<any> {
|
|
1001
|
+
const leadData = await this.getEntityData(entity, id, loggedInUser);
|
|
1002
|
+
|
|
1003
|
+
const { mappedEntities, ...data } = leadData as any;
|
|
1004
|
+
|
|
1005
|
+
const resolvedData = await this.resolverService.getResolvedData(
|
|
1006
|
+
loggedInUser,
|
|
1007
|
+
data,
|
|
1008
|
+
entity,
|
|
1009
|
+
);
|
|
1010
|
+
|
|
1011
|
+
if (mappedEntities) {
|
|
1012
|
+
resolvedData.mappedEntities = {};
|
|
1013
|
+
for (const [entityType, entities] of Object.entries(mappedEntities)) {
|
|
1014
|
+
if (Array.isArray(entities)) {
|
|
1015
|
+
resolvedData.mappedEntities[entityType] = [];
|
|
1016
|
+
for (const item of entities) {
|
|
1017
|
+
const resolvedItem = await this.resolverService.getResolvedData(
|
|
1018
|
+
loggedInUser,
|
|
1019
|
+
item,
|
|
1020
|
+
entityType,
|
|
1021
|
+
);
|
|
1022
|
+
resolvedData.mappedEntities[entityType].push(resolvedItem);
|
|
1023
|
+
}
|
|
1024
|
+
} else {
|
|
1025
|
+
resolvedData.mappedEntities[entityType] =
|
|
1026
|
+
await this.resolverService.getResolvedData(
|
|
1027
|
+
loggedInUser,
|
|
1028
|
+
entities,
|
|
1029
|
+
entityType,
|
|
1030
|
+
);
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
return resolvedData;
|
|
1036
|
+
}
|
|
1037
|
+
}
|