@futdevpro/nts-dynamo 1.15.13 → 1.15.15
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/.c8rc.json +26 -26
- package/.copilot/patterns.json +7 -7
- package/.cursor/rules/__assistant_guide.mdc +30 -30
- package/.cursor/rules/_ag_backend-structure.mdc +85 -85
- package/.cursor/rules/_ag_backend.mdc +16 -16
- package/.cursor/rules/_ag_frontend-structure.mdc +86 -86
- package/.cursor/rules/_ag_frontend.mdc +39 -39
- package/.cursor/rules/_ag_import-rules.mdc +44 -44
- package/.cursor/rules/_ag_naming.mdc +115 -115
- package/.cursor/rules/_ag_should-be.mdc +6 -6
- package/.cursor/rules/ai_development_guide.md +60 -60
- package/.cursor/rules/cursor-rules.md +160 -160
- package/.cursor/rules/default-command.mdc +464 -464
- package/.cursor/rules/error_code_pattern.md +39 -39
- package/.cursor/rules/saved rule mcp server use.md +15 -15
- package/.vscode/settings.json +10 -10
- package/HOWTO.md +15 -15
- package/LICENSE +21 -21
- package/__documentations/nts-integration-tests-2026-03-17.md +26 -26
- package/_specifications/BACKLOG.md +50 -22
- package/_specifications/TODO.md +15 -15
- package/_specifications/agent.md +138 -138
- package/build/_collections/global-settings.const.d.ts.map +1 -1
- package/build/_collections/global-settings.const.js +4 -0
- package/build/_collections/global-settings.const.js.map +1 -1
- package/build/_models/interfaces/global-log-settings.interface.d.ts +11 -0
- package/build/_models/interfaces/global-log-settings.interface.d.ts.map +1 -1
- package/build/_modules/logs/get-logs-routing-module.util.d.ts +19 -0
- package/build/_modules/logs/get-logs-routing-module.util.d.ts.map +1 -0
- package/build/_modules/logs/get-logs-routing-module.util.js +32 -0
- package/build/_modules/logs/get-logs-routing-module.util.js.map +1 -0
- package/build/_modules/logs/index.d.ts +4 -0
- package/build/_modules/logs/index.d.ts.map +1 -0
- package/build/_modules/logs/index.js +10 -0
- package/build/_modules/logs/index.js.map +1 -0
- package/build/_modules/logs/log-buffer.service.d.ts +38 -0
- package/build/_modules/logs/log-buffer.service.d.ts.map +1 -0
- package/build/_modules/logs/log-buffer.service.js +97 -0
- package/build/_modules/logs/log-buffer.service.js.map +1 -0
- package/build/_modules/logs/logs.controller.d.ts +27 -0
- package/build/_modules/logs/logs.controller.d.ts.map +1 -0
- package/build/_modules/logs/logs.controller.js +90 -0
- package/build/_modules/logs/logs.controller.js.map +1 -0
- package/build/_modules/logs/logs.service.d.ts +40 -0
- package/build/_modules/logs/logs.service.d.ts.map +1 -0
- package/build/_modules/logs/logs.service.js +97 -0
- package/build/_modules/logs/logs.service.js.map +1 -0
- package/build/_modules/server/errors/errors.data-service.d.ts.map +1 -1
- package/build/_modules/server/errors/errors.data-service.js +2 -1
- package/build/_modules/server/errors/errors.data-service.js.map +1 -1
- package/eslint.config.js +3 -3
- package/nodemon.json +24 -24
- package/package.json +362 -353
- package/scripts/run-coverage-tests.js +28 -28
- package/spec/support/helpers/spec-reporter-loader.js +359 -359
- package/spec/support/helpers/ts-node-helper.js +93 -93
- package/spec/support/jasmine.coverage.json +24 -24
- package/spec/support/jasmine.json +24 -24
- package/src/_collections/archive.util.spec.ts +57 -57
- package/src/_collections/archive.util.ts +18 -18
- package/src/_collections/atlas-default-db-options.const.ts +9 -9
- package/src/_collections/default-fallback-cache-max-age.const.spec.ts +11 -11
- package/src/_collections/default-fallback-cache-max-age.const.ts +2 -2
- package/src/_collections/default-not-found-page.const.spec.ts +19 -19
- package/src/_collections/default-not-found-page.const.ts +22 -22
- package/src/_collections/default-socket-path.const.spec.ts +12 -12
- package/src/_collections/default-socket-path.const.ts +2 -2
- package/src/_collections/get-environment-settings.util.spec.ts +210 -210
- package/src/_collections/get-environment-settings.util.ts +48 -48
- package/src/_collections/global-settings.const.ts +5 -0
- package/src/_collections/sample.env +21 -21
- package/src/_collections/star.controller.spec.ts +224 -224
- package/src/_collections/star.controller.ts +129 -129
- package/src/_enums/data-model-type.enum.ts +14 -14
- package/src/_enums/data-service-function.enum.ts +24 -24
- package/src/_enums/predefined-data-types.enum.ts +16 -16
- package/src/_enums/route-security.enum.ts +12 -12
- package/src/_models/control-models/api-call-params.control-model.spec.ts +152 -152
- package/src/_models/control-models/api-call-params.control-model.ts +142 -142
- package/src/_models/control-models/app-ext-system-controls.control-model.spec.ts +52 -52
- package/src/_models/control-models/app-ext-system-controls.control-model.ts +9 -9
- package/src/_models/control-models/app-params.control-model.spec.ts +225 -225
- package/src/_models/control-models/app-params.control-model.ts +136 -136
- package/src/_models/control-models/app-system-controls.control-model.spec.ts +31 -31
- package/src/_models/control-models/app-system-controls.control-model.ts +9 -9
- package/src/_models/control-models/endpoint-params.control-model.spec.ts +578 -578
- package/src/_models/control-models/endpoint-params.control-model.ts +526 -526
- package/src/_models/control-models/http-settings.control-model.spec.ts +77 -77
- package/src/_models/control-models/http-settings.control-model.ts +37 -37
- package/src/_models/control-models/system-control.control-model.spec.ts +27 -27
- package/src/_models/control-models/system-control.control-model.ts +12 -12
- package/src/_models/interfaces/certification-settings.interface.ts +7 -7
- package/src/_models/interfaces/environment-settings.interface.ts +59 -59
- package/src/_models/interfaces/global-log-settings.interface.ts +108 -96
- package/src/_models/interfaces/global-service-settings.interface.ts +47 -47
- package/src/_models/interfaces/routing-module-settings.interface.ts +21 -21
- package/src/_models/interfaces/static-client-settings.interface.spec.ts +29 -29
- package/src/_models/interfaces/static-client-settings.interface.ts +28 -28
- package/src/_models/types/db-update.type.ts +100 -100
- package/src/_modules/ai/_models/ai-input-interfaces.ts +117 -117
- package/src/_modules/ai/_models/ai-test-generation-result.interface.ts +16 -16
- package/src/_modules/ai/_modules/anthropic/_services/aai-user-key.control-service.ts +138 -138
- package/src/_modules/ai/_modules/anthropic/index.ts +5 -5
- package/src/_modules/ai/_modules/document-ai/_collections/dai-chunking.util.spec.ts +242 -242
- package/src/_modules/ai/_modules/document-ai/_collections/dai-chunking.util.ts +639 -639
- package/src/_modules/ai/_modules/document-ai/_collections/dai-document.util.spec.ts +209 -209
- package/src/_modules/ai/_modules/document-ai/_collections/dai-document.util.ts +85 -85
- package/src/_modules/ai/_modules/document-ai/_enums/dai-compare-result-type.enum.ts +7 -7
- package/src/_modules/ai/_modules/document-ai/_models/data-models/dai-doc-chunk.data-model.ts +146 -146
- package/src/_modules/ai/_modules/document-ai/_models/data-models/dai-doc-page.data-model.ts +162 -162
- package/src/_modules/ai/_modules/document-ai/_models/data-models/dai-document.data-model.ts +99 -99
- package/src/_modules/ai/_modules/document-ai/_models/interfaces/dai-doc-chunk-compare-result.interface.ts +18 -18
- package/src/_modules/ai/_modules/document-ai/_models/interfaces/dai-doc-page-compare-result.interface.ts +19 -19
- package/src/_modules/ai/_modules/document-ai/_models/interfaces/dai-document-compare-result.interface.ts +25 -25
- package/src/_modules/ai/_modules/document-ai/index.ts +28 -28
- package/src/_modules/ai/_modules/fdp-ai/_services/fdpai-user-key.control-service.ts +189 -189
- package/src/_modules/ai/_modules/fdp-ai/index.ts +5 -5
- package/src/_modules/ai/_modules/open-ai/_collections/oai-global-settings.const.ts +9 -9
- package/src/_modules/ai/_modules/open-ai/_collections/oai-llm-predefined-requests-hu.conts.ts +82 -82
- package/src/_modules/ai/_modules/open-ai/_collections/oai-llm-predefined-requests.conts.ts +75 -75
- package/src/_modules/ai/_modules/open-ai/_enums/oai-gpt-message-role.enum.ts +45 -45
- package/src/_modules/ai/_modules/open-ai/_models/interfaces/oai-global-settings.interface.ts +7 -7
- package/src/_modules/ai/_modules/open-ai/_models/interfaces/oai-gpt-message.interface.ts +7 -7
- package/src/_modules/ai/_modules/open-ai/_models/interfaces/oai-llm-predefined-requests.interface.ts +57 -57
- package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-doc-chunk-data.service.ts +292 -292
- package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-document.data-service.spec.ts +342 -342
- package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-vector-data.service.spec.ts +550 -550
- package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-vector-data.service.ts +630 -630
- package/src/_modules/ai/_modules/open-ai/_services/oai-embedding.control-service.spec.ts +240 -240
- package/src/_modules/ai/_modules/open-ai/_services/oai-embedding.control-service.ts +98 -98
- package/src/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.spec.ts +462 -462
- package/src/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.ts +615 -615
- package/src/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.spec.ts +437 -437
- package/src/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.ts +833 -833
- package/src/_modules/ai/_modules/open-ai/_services/oai-user-key.control-service.ts +157 -157
- package/src/_modules/ai/_services/ai-embedding.service-base.spec.ts +98 -98
- package/src/_modules/ai/_services/ai-embedding.service-base.ts +48 -48
- package/src/_modules/ai/_services/ai-llm-chat.service-base.spec.ts +229 -229
- package/src/_modules/ai/_services/ai-llm-chat.service-base.ts +68 -68
- package/src/_modules/ai/_services/ai-llm.service-base.spec.ts +250 -250
- package/src/_modules/ai/_services/ai-llm.service-base.ts +332 -332
- package/src/_modules/ai/_services/ai-provider.service-base.spec.ts +79 -79
- package/src/_modules/ai/_services/ai-provider.service-base.ts +29 -29
- package/src/_modules/ai/_services/ai-user-key.service-base.ts +59 -59
- package/src/_modules/ai/index.ts +13 -13
- package/src/_modules/assistant/_collections/ass-global-settings.const.ts +13 -13
- package/src/_modules/assistant/_collections/ass.util.spec.ts +176 -176
- package/src/_modules/assistant/_collections/ass.util.ts +50 -50
- package/src/_modules/assistant/_models/ass-global-settings.interface.ts +15 -15
- package/src/_modules/assistant/_services/ass-io.control-service.spec.ts +140 -140
- package/src/_modules/assistant/_services/ass-main.control-service.spec.ts +192 -192
- package/src/_modules/assistant/_services/ass-main.control-service.ts +107 -107
- package/src/_modules/bot/_collections/bot-default-commands.const.ts +12 -12
- package/src/_modules/bot/_collections/bot-global-settings.const.ts +39 -39
- package/src/_modules/bot/_models/bot-channel-wrapper.interface.ts +62 -62
- package/src/_modules/bot/_models/bot-command.interface.ts +8 -8
- package/src/_modules/bot/_models/bot-global-settings.interface.ts +96 -96
- package/src/_modules/bot/_models/bot-last-mention-date.interface.ts +6 -6
- package/src/_modules/bot/_models/bot-last-message-date.interface.ts +5 -5
- package/src/_modules/bot/_models/bot-user-wrapper.interface.ts +41 -41
- package/src/_modules/bot/_modules/discord-bot/_models/dib-platform.types.ts +9 -9
- package/src/_modules/bot/_modules/discord-bot/_services/dib-messaging-provider.control-service.spec.ts +431 -431
- package/src/_modules/bot/_modules/dynamo-bot/_collections/dyb-operations.util.spec.ts +160 -160
- package/src/_modules/bot/_modules/dynamo-bot/_collections/dyb-operations.util.ts +55 -55
- package/src/_modules/bot/_modules/dynamo-bot/_models/dyb-platform.types.ts +15 -15
- package/src/_modules/bot/_modules/dynamo-bot/_services/dyb-messaging-provider.control-service.spec.ts +374 -374
- package/src/_modules/bot/_modules/dynamo-bot/_services/dyb-messaging-provider.control-service.ts +447 -447
- package/src/_modules/bot/_modules/dynamo-bot/index.ts +15 -15
- package/src/_modules/bot/_modules/slack-bot/_models/slb-platform.types.ts +9 -9
- package/src/_modules/bot/_modules/slack-bot/_services/slb-messaging-provider.control-service.spec.ts +344 -344
- package/src/_modules/bot/_modules/slack-bot/_services/slb-messaging-provider.control-service.ts +197 -197
- package/src/_modules/bot/_modules/teams-bot/_models/teb-platform.types.ts +9 -9
- package/src/_modules/bot/_modules/teams-bot/_services/teb-messaging-provider.control-service.spec.ts +345 -345
- package/src/_modules/bot/_modules/teams-bot/_services/teb-messaging-provider.control-service.ts +197 -197
- package/src/_modules/bot/_services/bot-commands.control-service.spec.ts +116 -116
- package/src/_modules/bot/_services/bot-io.control-service.spec.ts +285 -285
- package/src/_modules/bot/_services/bot-main.control-service.spec.ts +208 -208
- package/src/_modules/bot/_services/bot-messaging-provider.service-base.spec.ts +349 -349
- package/src/_modules/bot/_services/bot-routines.control-service.spec.ts +111 -111
- package/src/_modules/custom-data/custom-data.controller.spec.ts +49 -49
- package/src/_modules/custom-data/custom-data.controller.ts +67 -67
- package/src/_modules/custom-data/custom-data.data-service.spec.ts +54 -54
- package/src/_modules/custom-data/custom-data.data-service.ts +21 -21
- package/src/_modules/custom-data/get-custom-data-routing-module.util.spec.ts +28 -28
- package/src/_modules/custom-data/get-custom-data-routing-module.util.ts +24 -24
- package/src/_modules/custom-data/index.ts +9 -9
- package/src/_modules/defaults/_collections/default-endpoints.util.ts +487 -487
- package/src/_modules/defaults/_models/default-user.data-model.ts +72 -72
- package/src/_modules/defaults/_services/default-auth.service.spec.ts +269 -269
- package/src/_modules/defaults/_services/default-auth.service.ts +177 -177
- package/src/_modules/defaults/_services/default-socket-events.service.spec.ts +42 -42
- package/src/_modules/defaults/_services/default-socket-events.service.ts +61 -61
- package/src/_modules/defaults/_services/default-user.data-service.spec.ts +187 -187
- package/src/_modules/defaults/_services/default-user.data-service.ts +98 -98
- package/src/_modules/defaults/index.ts +17 -17
- package/src/_modules/discord-assistant/_collections/dias-global-settings.const.ts +19 -19
- package/src/_modules/discord-assistant/_collections/dias.util.spec.ts +366 -366
- package/src/_modules/discord-assistant/_collections/dias.util.ts +132 -132
- package/src/_modules/discord-assistant/_models/dias-global-settings.interface.ts +19 -19
- package/src/_modules/discord-assistant/_models/dias-knowledge.data-model.ts +52 -52
- package/src/_modules/discord-assistant/_services/dias-chunk.data-service.ts +177 -177
- package/src/_modules/discord-assistant/_services/dias-io.control-service.spec.ts +108 -108
- package/src/_modules/discord-assistant/_services/dias-io.control-service.ts +69 -69
- package/src/_modules/discord-assistant/_services/dias-main.control-service.spec.ts +22 -22
- package/src/_modules/discord-assistant/_services/dias-main.control-service.ts +27 -27
- package/src/_modules/discord-assistant/_services/dias.service-base.spec.ts +195 -195
- package/src/_modules/discord-assistant/_services/dias.service-base.ts +76 -76
- package/src/_modules/discord-assistant/index.ts +38 -38
- package/src/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.spec.ts +34 -34
- package/src/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.ts +11 -11
- package/src/_modules/discord-assistant-voiced/index.ts +36 -36
- package/src/_modules/discord-bot/_collections/dibo-default-commands.const.ts +16 -16
- package/src/_modules/discord-bot/_collections/dibo-global-settings.conts.ts +55 -55
- package/src/_modules/discord-bot/_collections/dibo-operations.util.spec.ts +214 -214
- package/src/_modules/discord-bot/_collections/dibo-operations.util.ts +387 -387
- package/src/_modules/discord-bot/_models/dibo-command.interface.ts +12 -12
- package/src/_modules/discord-bot/_models/dibo-global-settings.interface.ts +98 -98
- package/src/_modules/discord-bot/_models/dibo-last-mention-date.inteface.ts +7 -7
- package/src/_modules/discord-bot/_models/dibo-last-message-date.interface.ts +6 -6
- package/src/_modules/discord-bot/_services/dibo-commands.control-service.spec.ts +154 -154
- package/src/_modules/discord-bot/_services/dibo-commands.control-service.ts +153 -153
- package/src/_modules/discord-bot/_services/dibo-io.control-service.spec.ts +264 -264
- package/src/_modules/discord-bot/_services/dibo-io.control-service.ts +306 -306
- package/src/_modules/discord-bot/_services/dibo-main.control-service.spec.ts +408 -408
- package/src/_modules/discord-bot/_services/dibo-main.control-service.ts +487 -487
- package/src/_modules/discord-bot/_services/dibo-routines.control-service.spec.ts +105 -105
- package/src/_modules/discord-bot/index.ts +36 -36
- package/src/_modules/local-vector-search/_enums/lvs-search-mode.enum.ts +19 -19
- package/src/_modules/local-vector-search/_models/lvs-search-result.interface.ts +17 -17
- package/src/_modules/local-vector-search/_services/lvs-doc-chunk-data.service.spec.ts +418 -418
- package/src/_modules/local-vector-search/_services/lvs-doc-chunk-data.service.ts +276 -276
- package/src/_modules/local-vector-search/_services/lvs-local-vector-search.data-service.spec.ts +345 -345
- package/src/_modules/local-vector-search/_services/lvs-local-vector-search.data-service.ts +330 -330
- package/src/_modules/local-vector-search/_services/lvs-vector-pool.control-service.spec.ts +393 -393
- package/src/_modules/local-vector-search/_services/lvs-vector-pool.control-service.ts +220 -220
- package/src/_modules/local-vector-search/index.ts +11 -11
- package/src/_modules/logs/get-logs-routing-module.util.ts +36 -0
- package/src/_modules/logs/index.ts +3 -0
- package/src/_modules/logs/log-buffer.service.ts +101 -0
- package/src/_modules/logs/logs.controller.ts +109 -0
- package/src/_modules/logs/logs.service.ts +100 -0
- package/src/_modules/messaging/README.md +354 -354
- package/src/_modules/messaging/_collections/get-messaging-routing-module.util.ts +26 -26
- package/src/_modules/messaging/_collections/msg-global-settings.const.ts +22 -22
- package/src/_modules/messaging/_collections/msg.util.spec.ts +226 -226
- package/src/_modules/messaging/_models/msg-global-settings.interface.ts +37 -37
- package/src/_modules/messaging/_services/msg-conversation.data-service.ts +146 -146
- package/src/_modules/messaging/_services/msg-events.service.spec.ts +219 -219
- package/src/_modules/messaging/_services/msg-events.service.ts +267 -267
- package/src/_modules/messaging/_services/msg-integration.control-service.ts +179 -179
- package/src/_modules/messaging/_services/msg-main.control-service.spec.ts +147 -147
- package/src/_modules/messaging/_services/msg-main.control-service.ts +571 -571
- package/src/_modules/messaging/_services/msg-message.data-service.ts +129 -129
- package/src/_modules/messaging/_services/msg.controller.spec.ts +201 -201
- package/src/_modules/messaging/index.ts +30 -30
- package/src/_modules/mock/app-extended-server.mock.ts +201 -201
- package/src/_modules/mock/app-integration-test.mock.ts +51 -51
- package/src/_modules/mock/app-params.mock.spec.ts +21 -21
- package/src/_modules/mock/app-params.mock.ts +9 -9
- package/src/_modules/mock/app-server.mock.ts +188 -188
- package/src/_modules/mock/auth-service.mock.spec.ts +47 -47
- package/src/_modules/mock/auth-service.mock.ts +28 -28
- package/src/_modules/mock/controller.mock.spec.ts +26 -26
- package/src/_modules/mock/controller.mock.ts +16 -16
- package/src/_modules/mock/data-model.mock.spec.ts +111 -111
- package/src/_modules/mock/data-model.mock.ts +82 -82
- package/src/_modules/mock/email-service-collection.mock.spec.ts +24 -24
- package/src/_modules/mock/email-service-collection.mock.ts +15 -15
- package/src/_modules/mock/email-service.mock.spec.ts +17 -17
- package/src/_modules/mock/email-service.mock.ts +20 -20
- package/src/_modules/mock/email-template.mock.html +14 -14
- package/src/_modules/mock/endpoint.mock.ts +91 -91
- package/src/_modules/mock/socket-client.mock.spec.ts +40 -40
- package/src/_modules/mock/socket-client.mock.ts +45 -45
- package/src/_modules/mock/socket-server.mock.spec.ts +44 -44
- package/src/_modules/mock/socket-server.mock.ts +46 -46
- package/src/_modules/oauth2/_routes/oauth2.controller.spec.ts +107 -107
- package/src/_modules/oauth2/_routes/oauth2.controller.ts +98 -98
- package/src/_modules/oauth2/_services/oauth2.auth-service.spec.ts +254 -254
- package/src/_modules/oauth2/_services/oauth2.auth-service.ts +232 -232
- package/src/_modules/oauth2/_services/oauth2.control-service.spec.ts +585 -585
- package/src/_modules/oauth2/_services/oauth2.control-service.ts +653 -653
- package/src/_modules/oauth2/index.ts +17 -17
- package/src/_modules/server/errors/errors.control-service.spec.ts +230 -230
- package/src/_modules/server/errors/errors.control-service.ts +69 -69
- package/src/_modules/server/errors/errors.controller.spec.ts +165 -165
- package/src/_modules/server/errors/errors.controller.ts +270 -270
- package/src/_modules/server/errors/errors.data-service.spec.ts +355 -355
- package/src/_modules/server/errors/errors.data-service.ts +2 -1
- package/src/_modules/server/index.ts +30 -30
- package/src/_modules/server/server-status/server-status-snapshot.control-service.spec.ts +70 -70
- package/src/_modules/server/server-status/server-status-snapshot.control-service.ts +17 -17
- package/src/_modules/server/server-status/server-status-snapshot.data-service.spec.ts +77 -77
- package/src/_modules/server/server-status/server-status-snapshot.data-service.ts +37 -37
- package/src/_modules/server/server-status/server-status.control-service.spec.ts +516 -516
- package/src/_modules/server/server-status/server-status.control-service.ts +336 -336
- package/src/_modules/server/server-status/server-status.controller.spec.ts +156 -156
- package/src/_modules/server/server-status/server-status.controller.ts +131 -131
- package/src/_modules/socket/_enums/socket-security.enum.ts +11 -11
- package/src/_modules/socket/_models/socket-client-service-params.control-model.spec.ts +32 -32
- package/src/_modules/socket/_models/socket-client-service-params.control-model.ts +22 -22
- package/src/_modules/socket/_models/socket-presence.control-model.spec.ts +164 -164
- package/src/_modules/socket/_models/socket-presence.control-model.ts +210 -210
- package/src/_modules/socket/_models/socket-server-service-params.control-model.spec.ts +46 -46
- package/src/_modules/socket/_models/socket-server-service-params.control-model.ts +22 -22
- package/src/_modules/socket/_services/socket-client.service.spec.ts +15 -15
- package/src/_modules/socket/_services/socket-client.service.ts +260 -260
- package/src/_modules/socket/_services/socket-server.service.spec.ts +11 -11
- package/src/_modules/socket/app-extended.integration.spec.ts +85 -85
- package/src/_modules/socket/app-extended.server.ts +630 -630
- package/src/_modules/socket/index.ts +42 -42
- package/src/_modules/test/get-test-routing-module.util.spec.ts +28 -28
- package/src/_modules/test/get-test-routing-module.util.ts +23 -23
- package/src/_modules/test/index.ts +11 -11
- package/src/_modules/test/test.controller.spec.ts +72 -72
- package/src/_modules/test/test.controller.ts +115 -115
- package/src/_modules/usage/get-usage-routing-module.util.ts +22 -22
- package/src/_modules/usage/index.ts +15 -15
- package/src/_modules/usage/usage.controller.spec.ts +81 -81
- package/src/_modules/usage/usage.controller.ts +126 -126
- package/src/_modules/usage/usage.data-service.spec.ts +332 -332
- package/src/_modules/usage/usage.data-service.ts +185 -185
- package/src/_services/base/api.service-base.spec.ts +125 -125
- package/src/_services/base/api.service-base.ts +74 -74
- package/src/_services/base/archive-data.service.spec.ts +196 -196
- package/src/_services/base/archive-data.service.ts +216 -216
- package/src/_services/base/data.service.spec.ts +493 -493
- package/src/_services/base/data.service.ts +2525 -2525
- package/src/_services/base/db.service.spec.ts +73 -73
- package/src/_services/base/db.service.ts +1575 -1575
- package/src/_services/base/singleton.service-base.spec.ts +28 -28
- package/src/_services/base/singleton.service-base.ts +24 -24
- package/src/_services/base/singleton.service.spec.ts +114 -114
- package/src/_services/base/singleton.service.ts +38 -38
- package/src/_services/core/api.service.spec.ts +140 -140
- package/src/_services/core/auth.service.spec.ts +159 -159
- package/src/_services/core/auth.service.ts +174 -174
- package/src/_services/core/email.service.spec.ts +85 -85
- package/src/_services/core/email.service.ts +742 -742
- package/src/_services/core/global.service.spec.ts +275 -275
- package/src/_services/core/global.service.ts +461 -461
- package/src/_services/core/service-collection.service.spec.ts +46 -46
- package/src/_services/core/service-collection.service.ts +6 -6
- package/src/_services/route/controller.service.spec.ts +53 -53
- package/src/_services/route/controller.service.ts +148 -148
- package/src/_services/route/routing-module.service.spec.ts +98 -98
- package/src/_services/route/routing-module.service.ts +330 -330
- package/src/_services/shared.static-service.spec.ts +99 -99
- package/src/_services/shared.static-service.ts +78 -78
- package/src/index.ts +94 -94
- package/tsconfig.app.json +12 -12
- package/tsconfig.json +42 -42
|
@@ -1,1575 +1,1575 @@
|
|
|
1
|
-
|
|
2
|
-
import * as mongoose from 'mongoose';
|
|
3
|
-
import { Schema } from 'mongoose';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
DyFM_AnyError,
|
|
7
|
-
DyFM_BasicProperty_Type,
|
|
8
|
-
DyFM_DataModel_Params,
|
|
9
|
-
DyFM_DataProperties,
|
|
10
|
-
DyFM_DataProperty_Params,
|
|
11
|
-
DyFM_DBFilter, DyFM_DBFilterSimple, DyFM_DBSort,
|
|
12
|
-
DyFM_Error,
|
|
13
|
-
DyFM_Error_Settings, DyFM_ErrorLevel,
|
|
14
|
-
DyFM_Log,
|
|
15
|
-
DyFM_Metadata,
|
|
16
|
-
DyFM_Object
|
|
17
|
-
} from '@futdevpro/fsm-dynamo';
|
|
18
|
-
import { DyNTS_archiveSuffix } from '../../_collections/archive.util';
|
|
19
|
-
import { DyNTS_DBUpdate } from '../../_models/types/db-update.type';
|
|
20
|
-
import { DyNTS_global_settings } from '../../_collections/global-settings.const';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* DB Service for MongoDB
|
|
24
|
-
*/
|
|
25
|
-
export class DyNTS_DBService<T extends DyFM_Metadata> {
|
|
26
|
-
|
|
27
|
-
serviceName: string;
|
|
28
|
-
|
|
29
|
-
dataModel/* : mongoose.Model<T> */; // = mongoose.model(this.dataParams.dataName, this.getSchema());
|
|
30
|
-
|
|
31
|
-
/* private depDataName: string; */
|
|
32
|
-
private readonly depKeys: string[] = [];
|
|
33
|
-
|
|
34
|
-
defaultErrorUserMsg =
|
|
35
|
-
`We encountered an unhandled DB Error, ` +
|
|
36
|
-
`\nplease contact the responsible development team.`;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @param dataName name the model
|
|
40
|
-
* @param typeSample sample data for scheme creation (dont include DyFM_Metadata!)
|
|
41
|
-
* @param schemaSettings additional settings for specific parameters as unique, required, minlength or maxlength
|
|
42
|
-
* schemaSettings also MUST contain specific types that differs from the listed above (Array, Date)
|
|
43
|
-
*/
|
|
44
|
-
constructor(
|
|
45
|
-
public dataParams: DyFM_DataModel_Params<T>
|
|
46
|
-
){
|
|
47
|
-
try {
|
|
48
|
-
this.serviceName = this.constructor?.name;
|
|
49
|
-
|
|
50
|
-
if (!this.dataParams.dataName || typeof this.dataParams.dataName !== 'string') {
|
|
51
|
-
throw new Error(
|
|
52
|
-
`dbName not setted up for this db-service (${this.dataParams.dataName}) (NTS DB)`
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (!this.dataParams.constructed?.()) {
|
|
57
|
-
throw new DyFM_Error({
|
|
58
|
-
error: new Error(
|
|
59
|
-
`DataModelParams is not constructed properly! (${this.dataParams.dataName}) ` +
|
|
60
|
-
`Use the DyFM_DataModel_Params.constructor to construct it properly! (NTS DB)`
|
|
61
|
-
),
|
|
62
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-C01`,
|
|
63
|
-
additionalContent: { dataParams: this.dataParams },
|
|
64
|
-
__localStack: this.dataParams.stackLocation,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
try {
|
|
69
|
-
this.dataModel = mongoose.model(this.dataParams.dataName, this.getSchema());
|
|
70
|
-
} catch (error) {
|
|
71
|
-
if (mongoose.models[this.dataParams.dataName]) {
|
|
72
|
-
this.dataModel = mongoose.models[this.dataParams.dataName];
|
|
73
|
-
} else {
|
|
74
|
-
throw error;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
this.lookForDependencyDataSettings();
|
|
79
|
-
} catch (error) {
|
|
80
|
-
throw new DyFM_Error({
|
|
81
|
-
message:
|
|
82
|
-
`DyNTS_DBService construction failed! "${dataParams.dataName}" - "${this.serviceName}"`,
|
|
83
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-C00`,
|
|
84
|
-
level: DyFM_ErrorLevel.critical,
|
|
85
|
-
additionalContent: { dataParams: this.dataParams },
|
|
86
|
-
error,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* save new data
|
|
93
|
-
* @param data data
|
|
94
|
-
* @returns data
|
|
95
|
-
*/
|
|
96
|
-
async createData(data: T, issuer: string): Promise<T> {
|
|
97
|
-
data.__created = new Date();
|
|
98
|
-
data.__lastModified = new Date();
|
|
99
|
-
data.__createdBy = issuer;
|
|
100
|
-
data.__lastModifiedBy = issuer;
|
|
101
|
-
|
|
102
|
-
const dataModel = new this.dataModel(data);
|
|
103
|
-
const newData: T = await dataModel.save().then((res): T => {
|
|
104
|
-
if (res) {
|
|
105
|
-
return res?.toObject() as T;
|
|
106
|
-
|
|
107
|
-
} else {
|
|
108
|
-
throw new DyFM_Error({
|
|
109
|
-
...this._getDefaultErrorSettings(
|
|
110
|
-
'createData',
|
|
111
|
-
new Error(
|
|
112
|
-
`createData failed, save "${this.dataParams.dataName}" result not found! (NTS DB)`
|
|
113
|
-
),
|
|
114
|
-
issuer
|
|
115
|
-
),
|
|
116
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-CD1`,
|
|
117
|
-
additionalContent: { data },
|
|
118
|
-
issuer,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
}).catch((error): void => {
|
|
122
|
-
if (error?.flag?.includes('DYNAMO')) {
|
|
123
|
-
throw error;
|
|
124
|
-
|
|
125
|
-
} else {
|
|
126
|
-
throw new DyFM_Error({
|
|
127
|
-
...this._getDefaultErrorSettings('createData', error, issuer),
|
|
128
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-CD0`,
|
|
129
|
-
additionalContent: {
|
|
130
|
-
data: data,
|
|
131
|
-
dataModel: this.dataModel,
|
|
132
|
-
},
|
|
133
|
-
message:
|
|
134
|
-
`createData failed, Create new "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
135
|
-
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
136
|
-
issuer,
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
return this.stringifyDataId(newData, 'createData');
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Find data by _id and update
|
|
146
|
-
* @param data data
|
|
147
|
-
* @returns data
|
|
148
|
-
*/
|
|
149
|
-
async modifyData(data: T, issuer: string, dontUpdateModified?: boolean): Promise<T> {
|
|
150
|
-
if (this.dataParams.forbidModify) {
|
|
151
|
-
await this.modifyThrowMethod(data, issuer);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (!dontUpdateModified) {
|
|
155
|
-
data.__lastModified = new Date();
|
|
156
|
-
data.__lastModifiedBy = issuer;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* EZ A SZAR TELJESEN SZAR, nem friss, nem a db-be mentett adatokat ad vissza,
|
|
161
|
-
* átír random value-kat össze vissza, WTF
|
|
162
|
-
* */
|
|
163
|
-
/* let newData: T = */
|
|
164
|
-
await this.dataModel.findByIdAndUpdate(data._id, data)/* .then((res) => {
|
|
165
|
-
if (res) {
|
|
166
|
-
//return res?.toObject() as T;
|
|
167
|
-
} else {
|
|
168
|
-
throw new DyFM_Error({
|
|
169
|
-
...this._getDefaultErrorSettings(
|
|
170
|
-
'modifyData',
|
|
171
|
-
new Error(`modifyData failed, modify "${this.dataParams.dataName}" result not found! (NTS DB)`),
|
|
172
|
-
issuer,
|
|
173
|
-
),
|
|
174
|
-
|
|
175
|
-
status: 204,
|
|
176
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-FU1`,
|
|
177
|
-
additionalContent: { data },
|
|
178
|
-
issuer,
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
}) */.catch((error): void => {
|
|
182
|
-
throw new DyFM_Error({
|
|
183
|
-
...this._getDefaultErrorSettings('modifyData', error, issuer),
|
|
184
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-FU0`,
|
|
185
|
-
additionalContent: { data },
|
|
186
|
-
message:
|
|
187
|
-
`modifyData "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
188
|
-
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
189
|
-
issuer,
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
return this.stringifyDataId(data, 'modifyData');
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// TODO: Missing issuer
|
|
197
|
-
/**
|
|
198
|
-
* returns data by _id,
|
|
199
|
-
* @param id id
|
|
200
|
-
* @returns data
|
|
201
|
-
*/
|
|
202
|
-
async getDataById(id: string): Promise<T> {
|
|
203
|
-
if (!id) {
|
|
204
|
-
throw new DyFM_Error({
|
|
205
|
-
...this._getDefaultErrorSettings('getDataById', new Error(`No ID provided! (NTS DB)`)),
|
|
206
|
-
|
|
207
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-GI1`,
|
|
208
|
-
message: `get "${this.dataParams.dataName}" by ID was unsuccessful (NTS DB)`,
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
const data: T = await this.dataModel
|
|
213
|
-
.findById(id)
|
|
214
|
-
.then((res): T => res?.toObject() as T ?? null)
|
|
215
|
-
.catch((error): void => {
|
|
216
|
-
throw new DyFM_Error({
|
|
217
|
-
...this._getDefaultErrorSettings('getDataById', error),
|
|
218
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-GI0`,
|
|
219
|
-
additionalContent: { id },
|
|
220
|
-
message:
|
|
221
|
-
`get "${this.dataParams.dataName}" by ID was unsuccessful (NTS DB)` +
|
|
222
|
-
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
return this.stringifyDataId(data, 'getDataById');
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// TODO: Missing issuer
|
|
230
|
-
/**
|
|
231
|
-
* get data by dependency data id,
|
|
232
|
-
* !!!: throws error if not found (errorCode on not found: NTS-DBS-GD2)
|
|
233
|
-
*
|
|
234
|
-
* @param dependencyIdsFilter id
|
|
235
|
-
* @returns data
|
|
236
|
-
*/
|
|
237
|
-
async getDataByDependencyId(dependencyIdsFilter: { [key: string]: string }): Promise<T> {
|
|
238
|
-
if (!this.depKeys.length) {
|
|
239
|
-
throw new DyFM_Error({
|
|
240
|
-
...this._getDefaultErrorSettings(
|
|
241
|
-
'getDataByDependencyId',
|
|
242
|
-
new Error(
|
|
243
|
-
`dependencyDataIdKey not setted up for this db-service (${this.dataParams.dataName}) (NTS DB)`
|
|
244
|
-
)
|
|
245
|
-
),
|
|
246
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-GD0`,
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
const data: T = await this.dataModel
|
|
251
|
-
.findOne(dependencyIdsFilter)
|
|
252
|
-
.then((res): T => res?.toObject() as T ?? null)
|
|
253
|
-
.catch((error): void => {
|
|
254
|
-
throw new DyFM_Error({
|
|
255
|
-
...this._getDefaultErrorSettings('getDataByDependencyId', error),
|
|
256
|
-
|
|
257
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-GD1`,
|
|
258
|
-
additionalContent: { dependencyIdsFilter: dependencyIdsFilter },
|
|
259
|
-
message:
|
|
260
|
-
`get "${this.dataParams.dataName}" by ` +
|
|
261
|
-
`"${Object.keys(dependencyIdsFilter).join(', ')}" was unsuccessful (NTS DB)` +
|
|
262
|
-
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
263
|
-
});
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
return this.stringifyDataId(data, 'getDataByDependencyId');
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
// TODO: Missing issuer
|
|
270
|
-
async getDataListByIds(ids: string[], findDeleted?: boolean): Promise<T[]> {
|
|
271
|
-
const dataList: T[] = await this.dataModel
|
|
272
|
-
.find({ _id: { $in: ids } })
|
|
273
|
-
.then((res): T[] => res as T[] ?? [])
|
|
274
|
-
.catch((error): void => {
|
|
275
|
-
throw new DyFM_Error({
|
|
276
|
-
...this._getDefaultErrorSettings('getDataListByIds', error),
|
|
277
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-GDL0`,
|
|
278
|
-
additionalContent: { ids },
|
|
279
|
-
message:
|
|
280
|
-
`get "${this.dataParams.dataName}" by IDs was unsuccessful (NTS DB)` +
|
|
281
|
-
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
282
|
-
});
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
if (!findDeleted) {
|
|
286
|
-
return dataList.filter(
|
|
287
|
-
(data: T): boolean => !data._deleted
|
|
288
|
-
).map(
|
|
289
|
-
(data: T): T => this.stringifyDataId(data, 'getDataListByDependencyId')
|
|
290
|
-
);
|
|
291
|
-
} else {
|
|
292
|
-
return dataList.map(
|
|
293
|
-
(data: T): T => this.stringifyDataId(data, 'getDataListByDependencyId')
|
|
294
|
-
);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
// TODO: Missing issuer
|
|
299
|
-
/**
|
|
300
|
-
* get data by dependency data id,
|
|
301
|
-
* !!!: throws error if not found (errorCode on not found: NTS-DBS-GLD2)
|
|
302
|
-
*
|
|
303
|
-
* @param dependencyIdsFilter id
|
|
304
|
-
* @returns dataList
|
|
305
|
-
*/
|
|
306
|
-
async getDataListByDependencyId(dependencyIdsFilter: { [key: string]: string }, findDeleted?: boolean): Promise<T[]> {
|
|
307
|
-
if (!this.depKeys.length) {
|
|
308
|
-
throw new DyFM_Error({
|
|
309
|
-
...this._getDefaultErrorSettings(
|
|
310
|
-
'getDataListByDependencyId',
|
|
311
|
-
new Error(
|
|
312
|
-
`isDependencyHook not setted up for this dataModel (${this.dataParams.dataName}) (NTS DB)`
|
|
313
|
-
)
|
|
314
|
-
),
|
|
315
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-GLD0`,
|
|
316
|
-
additionalContent: {
|
|
317
|
-
dataModel: this.dataModel,
|
|
318
|
-
},
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
const dataList: T[] = await this.dataModel
|
|
323
|
-
.find(dependencyIdsFilter)
|
|
324
|
-
.then((res): T[] => res as T[] ?? [])
|
|
325
|
-
.catch((error): void => {
|
|
326
|
-
throw new DyFM_Error({
|
|
327
|
-
...this._getDefaultErrorSettings('getDataListByDependencyId', error),
|
|
328
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-GLD1`,
|
|
329
|
-
additionalContent: { dependencyIdsFilter: dependencyIdsFilter },
|
|
330
|
-
message:
|
|
331
|
-
`get "${this.dataParams.dataName}" by ` +
|
|
332
|
-
`"${Object.keys(dependencyIdsFilter).join(', ')}" was unsuccessful (NTS DB)` +
|
|
333
|
-
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
334
|
-
});
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
if (!findDeleted) {
|
|
338
|
-
return dataList.filter(
|
|
339
|
-
(data: T): boolean => !data._deleted
|
|
340
|
-
).map(
|
|
341
|
-
(data: T): T => this.stringifyDataId(data, 'getDataListByDependencyId')
|
|
342
|
-
);
|
|
343
|
-
} else {
|
|
344
|
-
return dataList.map(
|
|
345
|
-
(data: T): T => this.stringifyDataId(data, 'getDataListByDependencyId')
|
|
346
|
-
);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
// TODO: Missing issuer
|
|
351
|
-
/**
|
|
352
|
-
* get multiple data objects by a list of DependencyIDs,
|
|
353
|
-
* !!!: throws error if not found (errorCode on not found: NTS-DBS-GLDS2)
|
|
354
|
-
*
|
|
355
|
-
* @param ids ids
|
|
356
|
-
* @returns dataList
|
|
357
|
-
*/
|
|
358
|
-
async getDataListByDependencyIds(dependencyKey: string, dependencyIds: string[], findDeleted?: boolean): Promise<T[]> {
|
|
359
|
-
if (!this.depKeys.length) {
|
|
360
|
-
throw new DyFM_Error({
|
|
361
|
-
...this._getDefaultErrorSettings(
|
|
362
|
-
'getDataListByDependencyIds',
|
|
363
|
-
new Error(
|
|
364
|
-
`getDataListByDependencyIds not setted up for this db-service ` +
|
|
365
|
-
`(${this.dataParams.dataName}) (NTS DB)`
|
|
366
|
-
)
|
|
367
|
-
),
|
|
368
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-GLDS0`,
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
if (!dependencyIds?.length) {
|
|
373
|
-
return [];
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
if (!dependencyKey) {
|
|
377
|
-
throw new DyFM_Error({
|
|
378
|
-
...this._getDefaultErrorSettings(
|
|
379
|
-
'getDataListByDependencyIds',
|
|
380
|
-
new Error(`dependencyKey is missing! (${this.dataParams.dataName}) (NTS DB)`),
|
|
381
|
-
),
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
if (!this.depKeys.includes(dependencyKey)) {
|
|
386
|
-
throw new DyFM_Error({
|
|
387
|
-
...this._getDefaultErrorSettings(
|
|
388
|
-
'getDataListByDependencyIds',
|
|
389
|
-
new Error(`dependencyKey is not valid! (${dependencyKey}) (NTS DB)`),
|
|
390
|
-
),
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
const dataList: T[] = await this.dataModel
|
|
395
|
-
.find({
|
|
396
|
-
[dependencyKey]: { $in: dependencyIds },
|
|
397
|
-
})
|
|
398
|
-
.then((res): T[] => res as T[] ?? [])
|
|
399
|
-
.catch((error): void => {
|
|
400
|
-
throw new DyFM_Error({
|
|
401
|
-
...this._getDefaultErrorSettings('getDataListByDependencyIds', error),
|
|
402
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-GLDS1`,
|
|
403
|
-
additionalContent: { dependencyIds },
|
|
404
|
-
message:
|
|
405
|
-
`get "${this.dataParams.dataName}" by "${dependencyKey}" was unsuccessful (NTS DB)` +
|
|
406
|
-
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
407
|
-
});
|
|
408
|
-
});
|
|
409
|
-
|
|
410
|
-
if (!findDeleted) {
|
|
411
|
-
return dataList.filter(
|
|
412
|
-
(data: T): boolean => !data._deleted
|
|
413
|
-
).map(
|
|
414
|
-
(data: T): T => this.stringifyDataId(data, 'getDataListByDependencyIds')
|
|
415
|
-
);
|
|
416
|
-
} else {
|
|
417
|
-
return dataList.map(
|
|
418
|
-
(data: T): T => this.stringifyDataId(data, 'getDataListByDependencyIds')
|
|
419
|
-
);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
// TODO: Missing issuer
|
|
424
|
-
/**
|
|
425
|
-
* returns all data from database,
|
|
426
|
-
* !!!: throws error if not found (errorCode on not found: NTS-DBS-GA1)
|
|
427
|
-
*
|
|
428
|
-
* @returns dataList
|
|
429
|
-
*/
|
|
430
|
-
async getAll(findDeleted?: boolean): Promise<T[]> {
|
|
431
|
-
const dataList: T[] = await this.dataModel
|
|
432
|
-
.find()
|
|
433
|
-
.then((res): T[] => res as T[] ?? [])
|
|
434
|
-
.catch((error): void => {
|
|
435
|
-
throw new DyFM_Error({
|
|
436
|
-
...this._getDefaultErrorSettings('getAll', error),
|
|
437
|
-
|
|
438
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-GA0`,
|
|
439
|
-
message:
|
|
440
|
-
`get all "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
441
|
-
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
442
|
-
});
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
if (!findDeleted) {
|
|
446
|
-
return dataList.filter(
|
|
447
|
-
(data: T): boolean => !data._deleted
|
|
448
|
-
).map(
|
|
449
|
-
(data: T): T => this.stringifyDataId(data, 'getAll')
|
|
450
|
-
);
|
|
451
|
-
} else {
|
|
452
|
-
return dataList.map(
|
|
453
|
-
(data: T): T => this.stringifyDataId(data, 'getAll')
|
|
454
|
-
);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
async markDeletedById(id: string, issuer: string): Promise<void> {
|
|
459
|
-
if (this.dataParams.forbidDelete) {
|
|
460
|
-
await this.deleteThrowMethod(id, issuer);
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
await this.dataModel.findByIdAndUpdate(
|
|
464
|
-
id,
|
|
465
|
-
{
|
|
466
|
-
_deleted: new Date(),
|
|
467
|
-
_deletedBy: issuer,
|
|
468
|
-
},
|
|
469
|
-
/* issuer */
|
|
470
|
-
).catch(
|
|
471
|
-
(error): void => {
|
|
472
|
-
throw new DyFM_Error({
|
|
473
|
-
...this._getDefaultErrorSettings('markDeletedById', error, issuer),
|
|
474
|
-
|
|
475
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-MD0`,
|
|
476
|
-
additionalContent: { id },
|
|
477
|
-
message:
|
|
478
|
-
`mark deleted "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
479
|
-
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
480
|
-
issuer,
|
|
481
|
-
});
|
|
482
|
-
}
|
|
483
|
-
);
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
async markDeletedByDependencyId(dependencyIdsFilter: { [key: string]: string }, issuer: string): Promise<void> {
|
|
487
|
-
if (this.dataParams.forbidDelete) {
|
|
488
|
-
await this.deleteThrowMethod(dependencyIdsFilter, issuer);
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
await this.dataModel.updateMany(
|
|
492
|
-
dependencyIdsFilter,
|
|
493
|
-
{
|
|
494
|
-
_deleted: new Date(),
|
|
495
|
-
_deletedBy: issuer,
|
|
496
|
-
}
|
|
497
|
-
).catch((error): void => {
|
|
498
|
-
throw new DyFM_Error({
|
|
499
|
-
...this._getDefaultErrorSettings('markDeletedByDependencyId', error, issuer),
|
|
500
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-MDD0`,
|
|
501
|
-
additionalContent: { dependencyIdsFilter: dependencyIdsFilter },
|
|
502
|
-
message:
|
|
503
|
-
`markDeleted "${this.dataParams.dataName}" by ` +
|
|
504
|
-
`"${Object.keys(dependencyIdsFilter).join(', ')}" was unsuccessful (NTS DB)` +
|
|
505
|
-
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
506
|
-
issuer,
|
|
507
|
-
});
|
|
508
|
-
});
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
async restoreDeletedById(id: string, issuer: string): Promise<void> {
|
|
512
|
-
await this.dataModel.findByIdAndUpdate(
|
|
513
|
-
id,
|
|
514
|
-
{
|
|
515
|
-
_deleted: null,
|
|
516
|
-
__lastModified: new Date(),
|
|
517
|
-
__lastModifiedBy: issuer,
|
|
518
|
-
},
|
|
519
|
-
/* issuer */
|
|
520
|
-
).catch((error): void => {
|
|
521
|
-
throw new DyFM_Error({
|
|
522
|
-
...this._getDefaultErrorSettings('restoreDeletedById', error, issuer),
|
|
523
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-RD0`,
|
|
524
|
-
additionalContent: { id },
|
|
525
|
-
message:
|
|
526
|
-
`restoreDeleted "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
527
|
-
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
528
|
-
issuer,
|
|
529
|
-
});
|
|
530
|
-
});
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
async restoreDeletedByDependencyId(
|
|
534
|
-
dependencyIdsFilter: { [key: string]: string },
|
|
535
|
-
issuer: string
|
|
536
|
-
): Promise<void> {
|
|
537
|
-
await this.dataModel.updateMany(
|
|
538
|
-
dependencyIdsFilter,
|
|
539
|
-
{
|
|
540
|
-
_deleted: null,
|
|
541
|
-
__lastModified: new Date(),
|
|
542
|
-
__lastModifiedBy: issuer,
|
|
543
|
-
}
|
|
544
|
-
).catch((error): void => {
|
|
545
|
-
throw new DyFM_Error({
|
|
546
|
-
...this._getDefaultErrorSettings('restoreDeletedByDependencyId', error, issuer),
|
|
547
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-RDD0`,
|
|
548
|
-
additionalContent: { dependencyIdsFilter: dependencyIdsFilter },
|
|
549
|
-
message:
|
|
550
|
-
`restoreDeleted "${this.dataParams.dataName}" by ` +
|
|
551
|
-
`"${Object.keys(dependencyIdsFilter).join(', ')}" was unsuccessful (NTS DB)` +
|
|
552
|
-
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
553
|
-
issuer,
|
|
554
|
-
});
|
|
555
|
-
});
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
// TODO: Missing issuer
|
|
559
|
-
async getDeletedDataList(): Promise<T[]> {
|
|
560
|
-
const dataList: T[] = await this.dataModel
|
|
561
|
-
.getAll()
|
|
562
|
-
.then((res): T[] => res as T[] ?? [])
|
|
563
|
-
.catch((error): void => {
|
|
564
|
-
throw new DyFM_Error({
|
|
565
|
-
...this._getDefaultErrorSettings('getDeletedData', error),
|
|
566
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-GDD0`,
|
|
567
|
-
message:
|
|
568
|
-
`get deleted "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
569
|
-
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
570
|
-
});
|
|
571
|
-
});
|
|
572
|
-
|
|
573
|
-
return dataList.filter(
|
|
574
|
-
(data: T): boolean => Boolean(data._deleted)
|
|
575
|
-
).map((data: T): T => this.stringifyDataId(data, 'getDeletedData'));
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
// TODO: Missing issuer
|
|
579
|
-
/**
|
|
580
|
-
* deleted data by id
|
|
581
|
-
* @param id id
|
|
582
|
-
*/
|
|
583
|
-
async trueDeleteDataById(id: string): Promise<void> {
|
|
584
|
-
if (this.dataParams.forbidDelete) {
|
|
585
|
-
await this.deleteThrowMethod(id/* , issuer */);
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
await this.dataModel
|
|
589
|
-
.findByIdAndDelete(id)
|
|
590
|
-
.catch((error): void => {
|
|
591
|
-
throw new DyFM_Error({
|
|
592
|
-
...this._getDefaultErrorSettings('deleteDataById', error),
|
|
593
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-DD0`,
|
|
594
|
-
additionalContent: { id },
|
|
595
|
-
message:
|
|
596
|
-
`delete "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
597
|
-
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
598
|
-
});
|
|
599
|
-
});
|
|
600
|
-
}
|
|
601
|
-
readonly deleteDataById = this.trueDeleteDataById;
|
|
602
|
-
|
|
603
|
-
// TODO: Missing issuer
|
|
604
|
-
/**
|
|
605
|
-
* deleted data by id
|
|
606
|
-
* @param dependencyId id
|
|
607
|
-
*/
|
|
608
|
-
async trueDeleteDataByDependencyId(dependencyIdsFilter: { [key: string]: string }): Promise<void> {
|
|
609
|
-
if (this.dataParams.forbidDelete) {
|
|
610
|
-
await this.deleteThrowMethod(dependencyIdsFilter/* , issuer */);
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
if (!this.depKeys.length) {
|
|
614
|
-
throw new DyFM_Error({
|
|
615
|
-
...this._getDefaultErrorSettings(
|
|
616
|
-
'deleteDataByDependencyId',
|
|
617
|
-
new Error(
|
|
618
|
-
`dependencyDataIdKey not setted up for this db-service (${this.dataParams.dataName}) (NTS DB)`
|
|
619
|
-
)
|
|
620
|
-
),
|
|
621
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-DDD0`,
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
await this.dataModel
|
|
626
|
-
.deleteMany(dependencyIdsFilter)
|
|
627
|
-
.catch((error): void => {
|
|
628
|
-
throw new DyFM_Error({
|
|
629
|
-
...this._getDefaultErrorSettings('deleteDataByDependencyId', error),
|
|
630
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-DDD1`,
|
|
631
|
-
additionalContent: { dependencyIdsFilter: dependencyIdsFilter },
|
|
632
|
-
message:
|
|
633
|
-
`delete "${this.dataParams.dataName}" by ` +
|
|
634
|
-
`"${Object.keys(dependencyIdsFilter).join(', ')}" was unsuccessful (NTS DB)` +
|
|
635
|
-
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
636
|
-
});
|
|
637
|
-
});
|
|
638
|
-
}
|
|
639
|
-
readonly deleteDataByDependencyId = this.trueDeleteDataByDependencyId;
|
|
640
|
-
|
|
641
|
-
// TODO: Missing issuer
|
|
642
|
-
async trueDeleteAllData(): Promise<void> {
|
|
643
|
-
if (this.dataParams.forbidDelete) {
|
|
644
|
-
await this.deleteThrowMethod(null/* , issuer */);
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
await this.dataModel.deleteMany().catch((error): void => {
|
|
648
|
-
throw new DyFM_Error({
|
|
649
|
-
...this._getDefaultErrorSettings('deleteAllData', error),
|
|
650
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-DAD0`,
|
|
651
|
-
message:
|
|
652
|
-
`delete all "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
653
|
-
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
654
|
-
});
|
|
655
|
-
});
|
|
656
|
-
}
|
|
657
|
-
readonly deleteAllData = this.trueDeleteAllData;
|
|
658
|
-
|
|
659
|
-
// TODO: Missing issuer
|
|
660
|
-
/**
|
|
661
|
-
* returns search result for searchBy object params
|
|
662
|
-
* can use lists or xRange values for searchBy obj properties
|
|
663
|
-
*
|
|
664
|
-
* @param filterBy filter
|
|
665
|
-
* @param narrowByDependencyIds id
|
|
666
|
-
* @returns dataList
|
|
667
|
-
*/
|
|
668
|
-
async searchData(
|
|
669
|
-
filterBy: DyFM_DBFilter<T>,
|
|
670
|
-
narrowByDependencyIds?: string[],
|
|
671
|
-
narrowByDependencyKey?: string,
|
|
672
|
-
findDeleted?: boolean
|
|
673
|
-
): Promise<T[]> {
|
|
674
|
-
const filter = {};
|
|
675
|
-
|
|
676
|
-
if (0 < narrowByDependencyIds.length) {
|
|
677
|
-
if (!this.depKeys.length) {
|
|
678
|
-
throw new DyFM_Error({
|
|
679
|
-
...this._getDefaultErrorSettings(
|
|
680
|
-
'searchData',
|
|
681
|
-
new Error(
|
|
682
|
-
`dependencyDataIdKey not setted up for this db-service (${this.dataParams.dataName}) (NTS DB)`
|
|
683
|
-
)
|
|
684
|
-
),
|
|
685
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-SD0`,
|
|
686
|
-
});
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
if (!narrowByDependencyKey) {
|
|
690
|
-
if (this.depKeys.length === 1) {
|
|
691
|
-
narrowByDependencyKey = this.depKeys[0];
|
|
692
|
-
} else {
|
|
693
|
-
throw new DyFM_Error({
|
|
694
|
-
...this._getDefaultErrorSettings(
|
|
695
|
-
'searchData',
|
|
696
|
-
new Error(`dependencyKey is missing! (${this.dataParams.dataName}) (NTS DB)`),
|
|
697
|
-
),
|
|
698
|
-
});
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
filter[narrowByDependencyKey] = { $in: narrowByDependencyIds };
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
Object.values(this.dataParams.properties).forEach(
|
|
706
|
-
(modelParam: DyFM_DataProperty_Params<any, T>): void => {
|
|
707
|
-
if (
|
|
708
|
-
(filterBy[modelParam.key] !== null && filterBy[modelParam.key] !== undefined) ||
|
|
709
|
-
filterBy[modelParam.key + 'Range']
|
|
710
|
-
) {
|
|
711
|
-
if (modelParam.key.includes('Range') || modelParam.type.includes('[]')) {
|
|
712
|
-
// inverz search filter (for Range and Array functions)
|
|
713
|
-
if (modelParam.key.includes('Range')) {
|
|
714
|
-
const searchParamKeyWithoutRange = modelParam.key.split('Range')[0];
|
|
715
|
-
|
|
716
|
-
if (
|
|
717
|
-
filterBy[searchParamKeyWithoutRange] !== null &&
|
|
718
|
-
filterBy[searchParamKeyWithoutRange] !== undefined
|
|
719
|
-
) {
|
|
720
|
-
filter[modelParam.key] = {
|
|
721
|
-
from: { $lte: filterBy[searchParamKeyWithoutRange] },
|
|
722
|
-
to: { $gte: filterBy[searchParamKeyWithoutRange] },
|
|
723
|
-
};
|
|
724
|
-
}
|
|
725
|
-
} else {
|
|
726
|
-
if (
|
|
727
|
-
filterBy[modelParam.key] !== null &&
|
|
728
|
-
filterBy[modelParam.key] !== undefined
|
|
729
|
-
) {
|
|
730
|
-
filter[modelParam.key] = { $in: filterBy[modelParam.key] };
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
} else {
|
|
734
|
-
// basic search filter
|
|
735
|
-
if (filterBy[modelParam.key + 'Range']) {
|
|
736
|
-
if (
|
|
737
|
-
filterBy[modelParam.key + 'Range'].from ||
|
|
738
|
-
filterBy[modelParam.key + 'Range'].to
|
|
739
|
-
) {
|
|
740
|
-
filter[modelParam.key] = {};
|
|
741
|
-
|
|
742
|
-
if (filterBy[modelParam.key + 'Range'].from) {
|
|
743
|
-
filter[modelParam.key].$gte = filterBy[modelParam.key + 'Range'].from;
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
if (filterBy[modelParam.key + 'Range'].to) {
|
|
747
|
-
filter[modelParam.key].$lte = filterBy[modelParam.key + 'Range'].to;
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
} else if (
|
|
751
|
-
filterBy[modelParam.key] !== null &&
|
|
752
|
-
filterBy[modelParam.key] !== undefined
|
|
753
|
-
) {
|
|
754
|
-
if (filterBy[modelParam.key].lenght > 0) {
|
|
755
|
-
filter[modelParam.key] = { $in: filterBy[modelParam.key] };
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
);
|
|
762
|
-
|
|
763
|
-
let dataList: T[] = await this.dataModel
|
|
764
|
-
.find(filter)
|
|
765
|
-
.then((res): T[] => res as T[] ?? [])
|
|
766
|
-
.catch((error): void => {
|
|
767
|
-
throw new DyFM_Error({
|
|
768
|
-
...this._getDefaultErrorSettings('searchData', error),
|
|
769
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-SD1`,
|
|
770
|
-
additionalContent: { filterBy, narrowByDependencyIds },
|
|
771
|
-
message:
|
|
772
|
-
`search "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
773
|
-
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
774
|
-
});
|
|
775
|
-
});
|
|
776
|
-
|
|
777
|
-
if (!findDeleted && (filterBy as DyFM_DBFilterSimple<T>)._deleted === undefined) {
|
|
778
|
-
dataList = dataList.filter((data: T): boolean => !data._deleted);
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
return dataList.map((data: T): T => this.stringifyDataId(data, 'searchData'));
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
// ----------------------------------------------------------------------------------
|
|
785
|
-
// ----------------------------------------------------------------------------------
|
|
786
|
-
// ----------------------------------------------------------------------------------
|
|
787
|
-
// DIRECT Basic MONGOOSE FUNCTIONS (with error handlings)
|
|
788
|
-
|
|
789
|
-
/**
|
|
790
|
-
* Find the data first by any of its parameters,
|
|
791
|
-
* !!!: throws error if not found (errorCode on not found: NTS-DBS-FO1)
|
|
792
|
-
*
|
|
793
|
-
* @param filterBy if you can, use unique parameters for find!
|
|
794
|
-
*
|
|
795
|
-
* @example
|
|
796
|
-
* // by email:
|
|
797
|
-
* { email: email }
|
|
798
|
-
* //
|
|
799
|
-
* @example
|
|
800
|
-
* // or by id that is in list:
|
|
801
|
-
* { userIds: { $in: this.userId } }
|
|
802
|
-
* // or by userIds:
|
|
803
|
-
* { userId: { $in: userIds } }
|
|
804
|
-
* //
|
|
805
|
-
* @example
|
|
806
|
-
* // or by number or Date that is Greater Than AND Less Than:
|
|
807
|
-
* { points: { $gt: 2, $lt: 14 } }
|
|
808
|
-
* // further tools (syntax matches with $gt):
|
|
809
|
-
* $eq: // Matches values that are EQual to a specified value.
|
|
810
|
-
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
811
|
-
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
812
|
-
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
813
|
-
* $nin: // Matches None of the values specified IN an array.
|
|
814
|
-
* //
|
|
815
|
-
* @returns {T} data: T
|
|
816
|
-
*/
|
|
817
|
-
async findOne(filterBy: DyFM_DBFilter<T>): Promise<T> {
|
|
818
|
-
const data: T = await this.dataModel
|
|
819
|
-
.findOne(filterBy)
|
|
820
|
-
.then((res): T => res as T ?? null)
|
|
821
|
-
.catch((error): void => {
|
|
822
|
-
throw new DyFM_Error({
|
|
823
|
-
...this._getDefaultErrorSettings('findOne', error),
|
|
824
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-FO0`,
|
|
825
|
-
additionalContent: { filterBy },
|
|
826
|
-
message:
|
|
827
|
-
`findOne "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
828
|
-
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
829
|
-
});
|
|
830
|
-
});
|
|
831
|
-
|
|
832
|
-
return this.stringifyDataId(data, 'findOne');
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
/**
|
|
836
|
-
* #MONGOOSE FUNCTION
|
|
837
|
-
* Find the data first by any of its parameters,
|
|
838
|
-
* !!!: throws error if not found (errorCode on not found: NTS-DBS-F1)
|
|
839
|
-
*
|
|
840
|
-
* @param filterBy if you can, use unique parameters for find!
|
|
841
|
-
*
|
|
842
|
-
* @example
|
|
843
|
-
* // by email:
|
|
844
|
-
* { email: email }
|
|
845
|
-
* //
|
|
846
|
-
* @example
|
|
847
|
-
* // or by id that is in list:
|
|
848
|
-
* { userIds: { $in: this.userId } }
|
|
849
|
-
* // or by userIds:
|
|
850
|
-
* { userId: { $in: userIds } }
|
|
851
|
-
* //
|
|
852
|
-
* @example
|
|
853
|
-
* // or by number or Date that is Greater Than AND Less Than:
|
|
854
|
-
* { points: { $gt: 2, $lt: 14 } }
|
|
855
|
-
* // further tools (syntax matches with $gt):
|
|
856
|
-
* $eq: // Matches values that are EQual to a specified value.
|
|
857
|
-
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
858
|
-
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
859
|
-
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
860
|
-
* $nin: // Matches None of the values specified IN an array.
|
|
861
|
-
* //
|
|
862
|
-
* @returns {T[]} dataList: T[]
|
|
863
|
-
*/
|
|
864
|
-
async find(filterBy: DyFM_DBFilter<T>, findDeleted?: boolean): Promise<T[]> {
|
|
865
|
-
let dataList: T[] = await this.dataModel
|
|
866
|
-
.find(filterBy)
|
|
867
|
-
.then((res): T[] => res as T[] ?? [])
|
|
868
|
-
.catch((error): void => {
|
|
869
|
-
throw new DyFM_Error({
|
|
870
|
-
...this._getDefaultErrorSettings('find', error),
|
|
871
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-F0`,
|
|
872
|
-
additionalContent: { filterBy },
|
|
873
|
-
message:
|
|
874
|
-
`find "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
875
|
-
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
876
|
-
});
|
|
877
|
-
});
|
|
878
|
-
|
|
879
|
-
if (!findDeleted && (filterBy as DyFM_DBFilterSimple<T>)._deleted === undefined) {
|
|
880
|
-
dataList = dataList.filter((data: T): boolean => !data._deleted);
|
|
881
|
-
}
|
|
882
|
-
|
|
883
|
-
return dataList.map((data: T): T => this.stringifyDataId(data, 'find'));
|
|
884
|
-
}
|
|
885
|
-
|
|
886
|
-
/**
|
|
887
|
-
* #MONGOOSE FUNCTION
|
|
888
|
-
* Find the data first by any of its parameters
|
|
889
|
-
* WARNING: This function will not gives you back the total number of data in the database!
|
|
890
|
-
*
|
|
891
|
-
* @param filterBy if you can, use unique parameters for find!
|
|
892
|
-
*
|
|
893
|
-
* @example
|
|
894
|
-
* // by email:
|
|
895
|
-
* { email: email }
|
|
896
|
-
* //
|
|
897
|
-
* @example
|
|
898
|
-
* // or by id that is in list:
|
|
899
|
-
* { userIds: { $in: this.userId } }
|
|
900
|
-
* // or by userIds:
|
|
901
|
-
* { userId: { $in: userIds } }
|
|
902
|
-
* //
|
|
903
|
-
* @example
|
|
904
|
-
* // or by number or Date that is Greater Than AND Less Than:
|
|
905
|
-
* { points: { $gt: 2, $lt: 14 } }
|
|
906
|
-
* // further tools (syntax matches with $gt):
|
|
907
|
-
* $eq: // Matches values that are EQual to a specified value.
|
|
908
|
-
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
909
|
-
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
910
|
-
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
911
|
-
* $nin: // Matches None of the values specified IN an array.
|
|
912
|
-
* //
|
|
913
|
-
* @param page page
|
|
914
|
-
* @param pageSize pageSize
|
|
915
|
-
* @param sort
|
|
916
|
-
* @example
|
|
917
|
-
* // by dateTime (this uses the basic sort function):
|
|
918
|
-
* { dateTime: -1 }
|
|
919
|
-
* //
|
|
920
|
-
* @returns {T[]} dataList: T[]
|
|
921
|
-
*/
|
|
922
|
-
async findWithPaging(
|
|
923
|
-
filterBy: DyFM_DBFilter<T>,
|
|
924
|
-
page: number,
|
|
925
|
-
pageSize: number,
|
|
926
|
-
sort?: DyFM_DBSort<T>
|
|
927
|
-
): Promise<T[]> {
|
|
928
|
-
/* if (filterBy['_deleted'] === undefined) {
|
|
929
|
-
filterBy['_deleted'] = null;
|
|
930
|
-
} */
|
|
931
|
-
|
|
932
|
-
const dataList: T[] = await this.dataModel
|
|
933
|
-
.find(filterBy)
|
|
934
|
-
.sort(sort)
|
|
935
|
-
.skip(page * pageSize)
|
|
936
|
-
.limit(pageSize)
|
|
937
|
-
.then((res): T => res ?? [])
|
|
938
|
-
.catch((error): void => {
|
|
939
|
-
throw new DyFM_Error({
|
|
940
|
-
...this._getDefaultErrorSettings('findWithPaging', error),
|
|
941
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-WP0`,
|
|
942
|
-
additionalContent: { filterBy, page, pageSize, sort },
|
|
943
|
-
message:
|
|
944
|
-
`findWithPaging "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
945
|
-
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
946
|
-
});
|
|
947
|
-
});
|
|
948
|
-
|
|
949
|
-
/* if ((filterBy as DyFM_DBFilterSimple<T>)._deleted === undefined) {
|
|
950
|
-
dataList = dataList.filter((data: T): boolean => !data._deleted);
|
|
951
|
-
} */
|
|
952
|
-
|
|
953
|
-
return dataList.map((data: T): T => this.stringifyDataId(data, 'find'));
|
|
954
|
-
}
|
|
955
|
-
|
|
956
|
-
/**
|
|
957
|
-
* #MONGOOSE FUNCTION
|
|
958
|
-
* Find data by _id and update
|
|
959
|
-
*
|
|
960
|
-
* @param id id
|
|
961
|
-
* @param update update
|
|
962
|
-
* @returns data
|
|
963
|
-
*/
|
|
964
|
-
async findByIdAndUpdate(
|
|
965
|
-
id: string,
|
|
966
|
-
update: DyNTS_DBUpdate<T>,
|
|
967
|
-
issuer: string,
|
|
968
|
-
dontUpdateModified?: boolean
|
|
969
|
-
): Promise<T> {
|
|
970
|
-
if (this.dataParams.forbidModify) {
|
|
971
|
-
await this.modifyThrowMethod(update, issuer);
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
if (!dontUpdateModified) {
|
|
975
|
-
update.__lastModified = new Date();
|
|
976
|
-
update.__lastModifiedBy = issuer;
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
const data: T = await this.dataModel
|
|
980
|
-
.findByIdAndUpdate(id, update)
|
|
981
|
-
.then((res): T => res?.toObject() as T ?? null)
|
|
982
|
-
.catch((error): void => {
|
|
983
|
-
throw new DyFM_Error({
|
|
984
|
-
...this._getDefaultErrorSettings('findByIdAndUpdate', error, issuer),
|
|
985
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-FIU0`,
|
|
986
|
-
additionalContent: { id, update },
|
|
987
|
-
message:
|
|
988
|
-
`findByIdAndUpdate "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
989
|
-
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
990
|
-
issuer,
|
|
991
|
-
});
|
|
992
|
-
});
|
|
993
|
-
|
|
994
|
-
return this.stringifyDataId(data, 'findByIdAndUpdate');
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
/**
|
|
998
|
-
* #MONGOOSE FUNCTION
|
|
999
|
-
* Find the data first by any of its parameters
|
|
1000
|
-
*
|
|
1001
|
-
* @param filter This uses the basic Mongoose updateOne.
|
|
1002
|
-
* If you can, use unique parameters for find!
|
|
1003
|
-
* @example
|
|
1004
|
-
* // by email:
|
|
1005
|
-
* { email: email }
|
|
1006
|
-
* //
|
|
1007
|
-
* @example
|
|
1008
|
-
* // or by id that is in list:
|
|
1009
|
-
* { userIds: { $in: this.userId } }
|
|
1010
|
-
* // or by userIds:
|
|
1011
|
-
* { userId: { $in: userIds } }
|
|
1012
|
-
* //
|
|
1013
|
-
* @example
|
|
1014
|
-
* // or by number or Date that is Greater Than AND Less Than:
|
|
1015
|
-
* { points: { $gt: 2, $lt: 14 } }
|
|
1016
|
-
* // further tools (syntax matches with $gt):
|
|
1017
|
-
* $eq: // Matches values that are EQual to a specified value.
|
|
1018
|
-
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
1019
|
-
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
1020
|
-
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
1021
|
-
* $nin: // Matches None of the values specified IN an array.
|
|
1022
|
-
* //
|
|
1023
|
-
*
|
|
1024
|
-
* @param update this uses the basic Mongoose updateOne
|
|
1025
|
-
* @example
|
|
1026
|
-
* // increase a specific value (here by 15):
|
|
1027
|
-
* { $inc: { popularity: 15 } }
|
|
1028
|
-
* //
|
|
1029
|
-
* @example
|
|
1030
|
-
* // or add element to a list:
|
|
1031
|
-
* { $push: { reactions: this.newReaction }
|
|
1032
|
-
* // or add multiple elements to a list
|
|
1033
|
-
* { $push: { schedule: {$each: [ monday, tuesday, wednesday ] } } }
|
|
1034
|
-
* //
|
|
1035
|
-
* @example
|
|
1036
|
-
* // or all at once
|
|
1037
|
-
* {
|
|
1038
|
-
* $inc: { popularity: this.newVote.amount },
|
|
1039
|
-
* emailVerified: true,
|
|
1040
|
-
* $push: { reactions: this.newReaction }
|
|
1041
|
-
* }
|
|
1042
|
-
* // further tools (syntax matches with $inc):
|
|
1043
|
-
* $currentDate: // Sets the value of a field to current date, either as a Date or a Timestamp.
|
|
1044
|
-
* $min: // Only updates the field if the specified value is less than the existing field value.
|
|
1045
|
-
* $max: // Only updates the field if the specified value is greater than the existing field value.
|
|
1046
|
-
* $mul: // Multiplies the value of the field by the specified amount.
|
|
1047
|
-
* $rename: // Renames a field.
|
|
1048
|
-
* $unset: // Removes the specified field from a document. (set: "" to value)
|
|
1049
|
-
* //
|
|
1050
|
-
*/
|
|
1051
|
-
async updateOne(
|
|
1052
|
-
filterBy: DyFM_DBFilter<T>,
|
|
1053
|
-
update: DyNTS_DBUpdate<T>,
|
|
1054
|
-
issuer: string,
|
|
1055
|
-
dontUpdateModified?: boolean
|
|
1056
|
-
): Promise<void> {
|
|
1057
|
-
if (this.dataParams.forbidModify) {
|
|
1058
|
-
await this.modifyThrowMethod(update, issuer);
|
|
1059
|
-
}
|
|
1060
|
-
|
|
1061
|
-
if (!dontUpdateModified) {
|
|
1062
|
-
update.__lastModified = new Date();
|
|
1063
|
-
update.__lastModifiedBy = issuer;
|
|
1064
|
-
}
|
|
1065
|
-
|
|
1066
|
-
await this.dataModel
|
|
1067
|
-
.updateOne(filterBy, update)
|
|
1068
|
-
.catch((error): void => {
|
|
1069
|
-
throw new DyFM_Error({
|
|
1070
|
-
...this._getDefaultErrorSettings('updateOne', error, issuer),
|
|
1071
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-UO0`,
|
|
1072
|
-
additionalContent: { filterBy, update },
|
|
1073
|
-
message:
|
|
1074
|
-
`updateOne "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
1075
|
-
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
1076
|
-
issuer,
|
|
1077
|
-
});
|
|
1078
|
-
});
|
|
1079
|
-
}
|
|
1080
|
-
|
|
1081
|
-
/**
|
|
1082
|
-
* #MONGOOSE FUNCTION
|
|
1083
|
-
* update one parameter by a specific
|
|
1084
|
-
*
|
|
1085
|
-
* @param filter This uses the basic Mongoose updateMany.
|
|
1086
|
-
* @example
|
|
1087
|
-
* // by email:
|
|
1088
|
-
* { email: email }
|
|
1089
|
-
* //
|
|
1090
|
-
* @example
|
|
1091
|
-
* // or by id that is in list:
|
|
1092
|
-
* { userIds: { $in: this.userId } }
|
|
1093
|
-
* // or by userIds:
|
|
1094
|
-
* { userId: { $in: userIds } }
|
|
1095
|
-
* //
|
|
1096
|
-
* @example
|
|
1097
|
-
* // or by number or Date that is Greater Than AND Less Than:
|
|
1098
|
-
* { points: { $gt: 2, $lt: 14 } }
|
|
1099
|
-
* // further tools (syntax matches with $gt):
|
|
1100
|
-
* $eq: // Matches values that are EQual to a specified value.
|
|
1101
|
-
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
1102
|
-
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
1103
|
-
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
1104
|
-
* $nin: // Matches None of the values specified IN an array.
|
|
1105
|
-
* //
|
|
1106
|
-
*
|
|
1107
|
-
* @param update this uses the basic Mongoose updateOne
|
|
1108
|
-
* @example
|
|
1109
|
-
* // increase a specific value (here by 15):
|
|
1110
|
-
* { $inc: { popularity: 15 } }
|
|
1111
|
-
* //
|
|
1112
|
-
* @example
|
|
1113
|
-
* // or add element to a list:
|
|
1114
|
-
* { $push: { reactions: this.newReaction }
|
|
1115
|
-
* // or add multiple elements to a list
|
|
1116
|
-
* { $push: { schedule: {$each: [ monday, tuesday, wednesday ] } } }
|
|
1117
|
-
* //
|
|
1118
|
-
* @example
|
|
1119
|
-
* // or all at once
|
|
1120
|
-
* {
|
|
1121
|
-
* $inc: { popularity: this.newVote.amount },
|
|
1122
|
-
* emailVerified: true,
|
|
1123
|
-
* $push: { reactions: this.newReaction }
|
|
1124
|
-
* }
|
|
1125
|
-
* // further tools (syntax matches with $inc):
|
|
1126
|
-
* $currentDate: // Sets the value of a field to current date, either as a Date or a Timestamp.
|
|
1127
|
-
* $min: // Only updates the field if the specified value is less than the existing field value.
|
|
1128
|
-
* $max: // Only updates the field if the specified value is greater than the existing field value.
|
|
1129
|
-
* $mul: // Multiplies the value of the field by the specified amount.
|
|
1130
|
-
* $rename: // Renames a field.
|
|
1131
|
-
* $unset: // Removes the specified field from a document. (set: "" to value)
|
|
1132
|
-
* //
|
|
1133
|
-
*/
|
|
1134
|
-
async updateMany(
|
|
1135
|
-
filterBy: DyFM_DBFilter<T>,
|
|
1136
|
-
update: DyNTS_DBUpdate<T>,
|
|
1137
|
-
issuer: string,
|
|
1138
|
-
dontUpdateModified?: boolean
|
|
1139
|
-
): Promise<void> {
|
|
1140
|
-
if (this.dataParams.forbidModify) {
|
|
1141
|
-
await this.modifyThrowMethod(update, issuer);
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1144
|
-
if (!dontUpdateModified) {
|
|
1145
|
-
update.__lastModified = new Date();
|
|
1146
|
-
update.__lastModifiedBy = issuer;
|
|
1147
|
-
}
|
|
1148
|
-
|
|
1149
|
-
await this.dataModel
|
|
1150
|
-
.updateMany(filterBy, update)
|
|
1151
|
-
.catch((error): void => {
|
|
1152
|
-
throw new DyFM_Error({
|
|
1153
|
-
...this._getDefaultErrorSettings('updateMany', error, issuer),
|
|
1154
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-UM0`,
|
|
1155
|
-
additionalContent: { filterBy, update },
|
|
1156
|
-
message:
|
|
1157
|
-
`updateMany "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
1158
|
-
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
1159
|
-
issuer,
|
|
1160
|
-
});
|
|
1161
|
-
});
|
|
1162
|
-
}
|
|
1163
|
-
|
|
1164
|
-
/**
|
|
1165
|
-
* {
|
|
1166
|
-
"mappings": {
|
|
1167
|
-
"dynamic": true,
|
|
1168
|
-
"fields": {
|
|
1169
|
-
"embedding": {
|
|
1170
|
-
"type": "knnVector",
|
|
1171
|
-
"dimensions": 768
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
}
|
|
1176
|
-
*/
|
|
1177
|
-
/**
|
|
1178
|
-
*
|
|
1179
|
-
* @param set db.collection.aggregate([
|
|
1180
|
-
{
|
|
1181
|
-
$vectorSearch: {
|
|
1182
|
-
index: "index_neve",
|
|
1183
|
-
queryVector: [a keresett embedding],
|
|
1184
|
-
path: "title.embedding",
|
|
1185
|
-
numCandidates: 100,
|
|
1186
|
-
limit: 5
|
|
1187
|
-
}
|
|
1188
|
-
},
|
|
1189
|
-
{
|
|
1190
|
-
$vectorSearch: {
|
|
1191
|
-
index: "index_neve",
|
|
1192
|
-
queryVector: [a keresett embedding],
|
|
1193
|
-
path: "description.embedding",
|
|
1194
|
-
numCandidates: 100,
|
|
1195
|
-
limit: 5
|
|
1196
|
-
}
|
|
1197
|
-
}
|
|
1198
|
-
]);
|
|
1199
|
-
* @returns
|
|
1200
|
-
*/
|
|
1201
|
-
async aggregate(set: any) {
|
|
1202
|
-
return this.dataModel.aggregate(set);
|
|
1203
|
-
}
|
|
1204
|
-
|
|
1205
|
-
// ----------------------------------------------------------------------------------
|
|
1206
|
-
// ----------------------------------------------------------------------------------
|
|
1207
|
-
// ----------------------------------------------------------------------------------
|
|
1208
|
-
// PRIVATE FUNCTIONS
|
|
1209
|
-
|
|
1210
|
-
private stringifyDataId(data: T, fnName: string): T {
|
|
1211
|
-
if (data?._id && (typeof data._id !== 'string' || typeof data._id === 'object')) {
|
|
1212
|
-
data._id = `${data._id}`;
|
|
1213
|
-
|
|
1214
|
-
if (typeof data._id !== 'string' || typeof data._id === 'object') {
|
|
1215
|
-
data = JSON.parse(JSON.stringify(data));
|
|
1216
|
-
|
|
1217
|
-
if (typeof data._id !== 'string' || typeof data._id === 'object') {
|
|
1218
|
-
DyFM_Log.error(
|
|
1219
|
-
`data._id stringifying failed! Please notfiy the DynamoNTS developers! (${fnName})`,
|
|
1220
|
-
new Error()
|
|
1221
|
-
);
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
|
|
1226
|
-
return data;
|
|
1227
|
-
}
|
|
1228
|
-
|
|
1229
|
-
private _getDefaultErrorSettings(
|
|
1230
|
-
fnName: string,
|
|
1231
|
-
error: DyFM_AnyError,
|
|
1232
|
-
issuer?: string
|
|
1233
|
-
): DyFM_Error_Settings {
|
|
1234
|
-
return {
|
|
1235
|
-
status: (error as DyFM_Error)?.___status ?? 500,
|
|
1236
|
-
message: (error as Error)?.message ??
|
|
1237
|
-
(error as DyFM_Error)?._message ??
|
|
1238
|
-
`${fnName} was UNSUCCESSFUL (NTS-DB)`,
|
|
1239
|
-
addECToUserMsg: !(error as DyFM_Error)?.__userMessage,
|
|
1240
|
-
userMessage: (error as DyFM_Error)?.__userMessage ?? this.defaultErrorUserMsg,
|
|
1241
|
-
issuer: issuer,
|
|
1242
|
-
issuerService: this.serviceName,
|
|
1243
|
-
error: error,
|
|
1244
|
-
};
|
|
1245
|
-
}
|
|
1246
|
-
|
|
1247
|
-
// ----------------------------------------------------------------------------------
|
|
1248
|
-
// PRIVATE BUILD FUNCTIONS
|
|
1249
|
-
|
|
1250
|
-
/**
|
|
1251
|
-
* builds and returns mongoose schema
|
|
1252
|
-
* @returns schema
|
|
1253
|
-
*/
|
|
1254
|
-
private getSchema(): mongoose.Schema {
|
|
1255
|
-
this.dataParams.properties = this.addMetadataToProperties(this.dataParams.properties);
|
|
1256
|
-
|
|
1257
|
-
if (this.dataParams.dataName.includes(DyNTS_archiveSuffix)) {
|
|
1258
|
-
this.dataParams.properties = this.addArchiveMetadataToProperties(this.dataParams.properties);
|
|
1259
|
-
}
|
|
1260
|
-
|
|
1261
|
-
const schemaSettings: any = this.buildMongooseSchemaSettingsObjByModelParams(
|
|
1262
|
-
this.dataParams.properties
|
|
1263
|
-
);
|
|
1264
|
-
|
|
1265
|
-
/* schema = this.addMetadataToSchema(schema); */
|
|
1266
|
-
|
|
1267
|
-
/* if (this.dataParams.dataName.includes(DyNTS_archiveSuffix)) {
|
|
1268
|
-
schema = this.addArchiveMetadataToSchema(schema);
|
|
1269
|
-
} */
|
|
1270
|
-
|
|
1271
|
-
if (schemaSettings['_id']) {
|
|
1272
|
-
delete schemaSettings['_id'];
|
|
1273
|
-
}
|
|
1274
|
-
|
|
1275
|
-
return new Schema(schemaSettings);
|
|
1276
|
-
}
|
|
1277
|
-
|
|
1278
|
-
/**
|
|
1279
|
-
* builds mongoose schema building settings object by dynamoDataModelParamsList
|
|
1280
|
-
* @param properties DynamoNTSDataPropertyParams
|
|
1281
|
-
* @returns mongoose schema object
|
|
1282
|
-
*/
|
|
1283
|
-
private buildMongooseSchemaSettingsObjByModelParams(properties: DyFM_DataProperties<T>): any {
|
|
1284
|
-
const schemaSettingsObj = {};
|
|
1285
|
-
|
|
1286
|
-
/* if (!properties) {
|
|
1287
|
-
properties = this.dataParams.properties;
|
|
1288
|
-
} */
|
|
1289
|
-
|
|
1290
|
-
Object.values(properties).forEach((property: DyFM_DataProperty_Params<any, T>): void => {
|
|
1291
|
-
if (!property) {
|
|
1292
|
-
DyFM_Log.warn(`property is undefined on "${this.dataParams.dataName}" (NTS DB)`);
|
|
1293
|
-
|
|
1294
|
-
return;
|
|
1295
|
-
}
|
|
1296
|
-
|
|
1297
|
-
if (!property.key) {
|
|
1298
|
-
const missingKeys = Object.keys(properties).filter((key: string) => !properties[key].key);
|
|
1299
|
-
|
|
1300
|
-
throw new DyFM_Error({
|
|
1301
|
-
...this._getDefaultErrorSettings(
|
|
1302
|
-
'buildMongooseSchemaByModelParams',
|
|
1303
|
-
new Error(
|
|
1304
|
-
`property.key is undefined on "${this.dataParams.dataName}" (NTS DB) ` +
|
|
1305
|
-
`(keys: ${Object.keys(properties).join(', ')}) ` +
|
|
1306
|
-
`(missing keys: ${missingKeys.join(', ')})`
|
|
1307
|
-
)
|
|
1308
|
-
),
|
|
1309
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-BMSBP0`,
|
|
1310
|
-
additionalContent: {
|
|
1311
|
-
property: property,
|
|
1312
|
-
dataParams: this.dataParams,
|
|
1313
|
-
missingKeys: missingKeys,
|
|
1314
|
-
},
|
|
1315
|
-
});
|
|
1316
|
-
}
|
|
1317
|
-
|
|
1318
|
-
if (property.forbidden) {
|
|
1319
|
-
return;
|
|
1320
|
-
}
|
|
1321
|
-
|
|
1322
|
-
const beType = this.getBEType(property.type as DyFM_BasicProperty_Type);
|
|
1323
|
-
|
|
1324
|
-
/* TODO if (beType === Array && property.archiveable && !property.archiveListAfter) {
|
|
1325
|
-
property.archiveListAfter = DyNTS_global_settings.archiveListAfter;
|
|
1326
|
-
} */
|
|
1327
|
-
|
|
1328
|
-
if (
|
|
1329
|
-
beType !== Object ||
|
|
1330
|
-
!property?.subObjectParams ||
|
|
1331
|
-
(property?.subObjectParams &&
|
|
1332
|
-
Object.keys(property.subObjectParams).length == 0)
|
|
1333
|
-
) {
|
|
1334
|
-
schemaSettingsObj[property.key] = {
|
|
1335
|
-
type: beType,
|
|
1336
|
-
};
|
|
1337
|
-
|
|
1338
|
-
if (property.index) {
|
|
1339
|
-
schemaSettingsObj[property.key].index = true;
|
|
1340
|
-
}
|
|
1341
|
-
|
|
1342
|
-
if (property.unique) {
|
|
1343
|
-
schemaSettingsObj[property.key].unique = true;
|
|
1344
|
-
}
|
|
1345
|
-
|
|
1346
|
-
if (property.required) {
|
|
1347
|
-
schemaSettingsObj[property.key].required = true;
|
|
1348
|
-
}
|
|
1349
|
-
|
|
1350
|
-
if (property.minlength) {
|
|
1351
|
-
schemaSettingsObj[property.key].minlength = property.minlength;
|
|
1352
|
-
}
|
|
1353
|
-
|
|
1354
|
-
if (property.maxlength) {
|
|
1355
|
-
schemaSettingsObj[property.key].maxlength = property.maxlength;
|
|
1356
|
-
}
|
|
1357
|
-
} else {
|
|
1358
|
-
schemaSettingsObj[property.key] = this.buildMongooseSchemaSettingsObjByModelParams(
|
|
1359
|
-
property.subObjectParams
|
|
1360
|
-
);
|
|
1361
|
-
}
|
|
1362
|
-
});
|
|
1363
|
-
|
|
1364
|
-
return schemaSettingsObj;
|
|
1365
|
-
}
|
|
1366
|
-
|
|
1367
|
-
private getBEType(
|
|
1368
|
-
type: DyFM_BasicProperty_Type
|
|
1369
|
-
): string | number | boolean | object | Function | Array<any> | Date {
|
|
1370
|
-
switch (type) {
|
|
1371
|
-
case DyFM_BasicProperty_Type.string:
|
|
1372
|
-
return String;
|
|
1373
|
-
|
|
1374
|
-
case DyFM_BasicProperty_Type.number:
|
|
1375
|
-
return Number;
|
|
1376
|
-
|
|
1377
|
-
case DyFM_BasicProperty_Type.boolean:
|
|
1378
|
-
return Boolean;
|
|
1379
|
-
|
|
1380
|
-
case DyFM_BasicProperty_Type.date:
|
|
1381
|
-
return Date;
|
|
1382
|
-
|
|
1383
|
-
case DyFM_BasicProperty_Type.object:
|
|
1384
|
-
return Object;
|
|
1385
|
-
|
|
1386
|
-
case DyFM_BasicProperty_Type.array:
|
|
1387
|
-
return Array;
|
|
1388
|
-
|
|
1389
|
-
case DyFM_BasicProperty_Type.function:
|
|
1390
|
-
return Function;
|
|
1391
|
-
|
|
1392
|
-
default:
|
|
1393
|
-
DyFM_Log.H_info('wtf', DyFM_Object.cleanObject(this.dataParams));
|
|
1394
|
-
|
|
1395
|
-
throw new DyFM_Error({
|
|
1396
|
-
error: new Error(
|
|
1397
|
-
`Invalid property type: "${type}" (${this.dataParams.dataName})` +
|
|
1398
|
-
(this.dataParams.constructed?.() ? '' : ('\nThe dataParams is not constructed properly! \n' +
|
|
1399
|
-
'Use the DyFM_DataModel_Params.constructor to construct it properly!'))
|
|
1400
|
-
),
|
|
1401
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-GTP0`,
|
|
1402
|
-
additionalContent: { type: type, dataParams: this.dataParams },
|
|
1403
|
-
__localStack: this.dataParams.stackLocation,
|
|
1404
|
-
});
|
|
1405
|
-
}
|
|
1406
|
-
/* switch (type.toLocaleLowerCase()) {
|
|
1407
|
-
case DyFM_BasicProperty_Type.string:
|
|
1408
|
-
case 'string':
|
|
1409
|
-
return String;
|
|
1410
|
-
|
|
1411
|
-
case DyFM_BasicProperty_Type.number:
|
|
1412
|
-
case 'number':
|
|
1413
|
-
return Number;
|
|
1414
|
-
|
|
1415
|
-
case DyFM_BasicProperty_Type.boolean:
|
|
1416
|
-
case 'boolean':
|
|
1417
|
-
return Boolean;
|
|
1418
|
-
|
|
1419
|
-
case DyFM_BasicProperty_Type.date:
|
|
1420
|
-
case 'date':
|
|
1421
|
-
return Date;
|
|
1422
|
-
|
|
1423
|
-
case DyFM_BasicProperty_Type.object:
|
|
1424
|
-
case 'object':
|
|
1425
|
-
return Object;
|
|
1426
|
-
|
|
1427
|
-
case DyFM_BasicProperty_Type.array:
|
|
1428
|
-
case 'array':
|
|
1429
|
-
return Array;
|
|
1430
|
-
|
|
1431
|
-
default:
|
|
1432
|
-
if (type.includes('[]') || type.includes('array')) {
|
|
1433
|
-
return Array;
|
|
1434
|
-
} else if (type.includes('=>') || type.includes('function')) {
|
|
1435
|
-
return Function;
|
|
1436
|
-
} else {
|
|
1437
|
-
return Object;
|
|
1438
|
-
}
|
|
1439
|
-
} */
|
|
1440
|
-
}
|
|
1441
|
-
|
|
1442
|
-
/**
|
|
1443
|
-
* adds dynamo metadata settings to any mongoose schema building settings object
|
|
1444
|
-
* @param schema schema to update
|
|
1445
|
-
* @returns updated schema
|
|
1446
|
-
*/
|
|
1447
|
-
/* private addMetadataToSchema(schema: any): any {
|
|
1448
|
-
schema.__created = { type: Date };
|
|
1449
|
-
schema.__createdBy = { type: String };
|
|
1450
|
-
schema.__lastModified = { type: Date };
|
|
1451
|
-
schema.__lastModifiedBy = { type: String };
|
|
1452
|
-
|
|
1453
|
-
schema._deleted = { type: Date };
|
|
1454
|
-
schema._deletedBy = { type: String };
|
|
1455
|
-
|
|
1456
|
-
return schema;
|
|
1457
|
-
} */
|
|
1458
|
-
|
|
1459
|
-
/**
|
|
1460
|
-
* adds dynamo metadata settings to any mongoose schema building settings object
|
|
1461
|
-
* @param properties properties to update
|
|
1462
|
-
* @returns updated properties
|
|
1463
|
-
*/
|
|
1464
|
-
private addMetadataToProperties(properties: DyFM_DataProperties<T>): DyFM_DataProperties<T> {
|
|
1465
|
-
// TOD: ezek a kikommentelt "required: true"-k kellenek, csak félő, hogy gondokat okoznak a
|
|
1466
|
-
// jelenlegi rendszerekben, ezért akkor kell majd visszarakni, ha lesz tesztelői ÉS fejlesztői kapacitás rá
|
|
1467
|
-
if (!properties.__created) {
|
|
1468
|
-
properties.__created = {
|
|
1469
|
-
key: '__created', type: DyFM_BasicProperty_Type.date/* , required: true */,
|
|
1470
|
-
};
|
|
1471
|
-
}
|
|
1472
|
-
|
|
1473
|
-
if (!properties.__createdBy) {
|
|
1474
|
-
properties.__createdBy = {
|
|
1475
|
-
key: '__createdBy', type: DyFM_BasicProperty_Type.string/* , required: true */,
|
|
1476
|
-
};
|
|
1477
|
-
}
|
|
1478
|
-
|
|
1479
|
-
if (!properties.__lastModified) {
|
|
1480
|
-
properties.__lastModified = {
|
|
1481
|
-
key: '__lastModified', type: DyFM_BasicProperty_Type.date/* , required: true */,
|
|
1482
|
-
};
|
|
1483
|
-
}
|
|
1484
|
-
|
|
1485
|
-
if (!properties.__lastModifiedBy) {
|
|
1486
|
-
properties.__lastModifiedBy = {
|
|
1487
|
-
key: '__lastModifiedBy', type: DyFM_BasicProperty_Type.string/* , required: true */,
|
|
1488
|
-
};
|
|
1489
|
-
}
|
|
1490
|
-
|
|
1491
|
-
if (!properties._deleted) {
|
|
1492
|
-
properties._deleted = {
|
|
1493
|
-
key: '_deleted', type: DyFM_BasicProperty_Type.date,
|
|
1494
|
-
};
|
|
1495
|
-
}
|
|
1496
|
-
|
|
1497
|
-
if (!properties._deletedBy) {
|
|
1498
|
-
properties._deletedBy = {
|
|
1499
|
-
key: '_deletedBy', type: DyFM_BasicProperty_Type.string,
|
|
1500
|
-
};
|
|
1501
|
-
}
|
|
1502
|
-
|
|
1503
|
-
if (!properties._archived) {
|
|
1504
|
-
properties._archived = {
|
|
1505
|
-
key: '_archived', type: DyFM_BasicProperty_Type.date,
|
|
1506
|
-
};
|
|
1507
|
-
}
|
|
1508
|
-
|
|
1509
|
-
return properties;
|
|
1510
|
-
}
|
|
1511
|
-
|
|
1512
|
-
/* private addArchiveMetadataToSchema(schema: any): any {
|
|
1513
|
-
schema._originalId = { type: String, required: true, index: true, unique: true };
|
|
1514
|
-
schema._archived = { type: Date, required: true };
|
|
1515
|
-
|
|
1516
|
-
return schema;
|
|
1517
|
-
} */
|
|
1518
|
-
|
|
1519
|
-
private addArchiveMetadataToProperties(
|
|
1520
|
-
properties: DyFM_DataProperties<T>
|
|
1521
|
-
): DyFM_DataProperties<T> {
|
|
1522
|
-
if (!properties._originalId) {
|
|
1523
|
-
properties._originalId = {
|
|
1524
|
-
key: '_originalId', type: DyFM_BasicProperty_Type.string,
|
|
1525
|
-
required: true, index: true, unique: true,
|
|
1526
|
-
};
|
|
1527
|
-
}
|
|
1528
|
-
|
|
1529
|
-
if (!properties._archived) {
|
|
1530
|
-
properties._archived = {
|
|
1531
|
-
key: '_archived', type: DyFM_BasicProperty_Type.date,
|
|
1532
|
-
required: true,
|
|
1533
|
-
};
|
|
1534
|
-
} else if (properties._archived.required === undefined) {
|
|
1535
|
-
properties._archived.required = true;
|
|
1536
|
-
}
|
|
1537
|
-
|
|
1538
|
-
return properties;
|
|
1539
|
-
}
|
|
1540
|
-
|
|
1541
|
-
/**
|
|
1542
|
-
* sets depDataKey
|
|
1543
|
-
*/
|
|
1544
|
-
private lookForDependencyDataSettings(): void {
|
|
1545
|
-
const dependencyParams: DyFM_DataProperty_Params<any, T>[] =
|
|
1546
|
-
Object.values(this.dataParams.properties).filter(
|
|
1547
|
-
(modelParams: DyFM_DataProperty_Params<any, T>): boolean =>
|
|
1548
|
-
Boolean(modelParams.dependencyDataName)
|
|
1549
|
-
);
|
|
1550
|
-
|
|
1551
|
-
if (dependencyParams) {
|
|
1552
|
-
this.depKeys.push(...dependencyParams.map(
|
|
1553
|
-
(dependencyParam: DyFM_DataProperty_Params<any, T>): string => dependencyParam.key
|
|
1554
|
-
));
|
|
1555
|
-
}
|
|
1556
|
-
}
|
|
1557
|
-
|
|
1558
|
-
private async deleteThrowMethod(data: any, issuer?: string): Promise<void> {
|
|
1559
|
-
throw new DyFM_Error({
|
|
1560
|
-
error: new Error(`Forbidden to delete any data! (${this.dataParams.dataName})`),
|
|
1561
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-CDAD`,
|
|
1562
|
-
additionalContent: { dataParams: this.dataParams, data: data },
|
|
1563
|
-
issuer: issuer,
|
|
1564
|
-
});
|
|
1565
|
-
};
|
|
1566
|
-
|
|
1567
|
-
private async modifyThrowMethod(data: any, issuer?: string): Promise<void> {
|
|
1568
|
-
throw new DyFM_Error({
|
|
1569
|
-
error: new Error(`Forbidden to modify any data! (${this.dataParams.dataName})`),
|
|
1570
|
-
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-CDAD`,
|
|
1571
|
-
additionalContent: { dataParams: this.dataParams, data: data },
|
|
1572
|
-
issuer: issuer,
|
|
1573
|
-
});
|
|
1574
|
-
}
|
|
1575
|
-
}
|
|
1
|
+
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
import { Schema } from 'mongoose';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
DyFM_AnyError,
|
|
7
|
+
DyFM_BasicProperty_Type,
|
|
8
|
+
DyFM_DataModel_Params,
|
|
9
|
+
DyFM_DataProperties,
|
|
10
|
+
DyFM_DataProperty_Params,
|
|
11
|
+
DyFM_DBFilter, DyFM_DBFilterSimple, DyFM_DBSort,
|
|
12
|
+
DyFM_Error,
|
|
13
|
+
DyFM_Error_Settings, DyFM_ErrorLevel,
|
|
14
|
+
DyFM_Log,
|
|
15
|
+
DyFM_Metadata,
|
|
16
|
+
DyFM_Object
|
|
17
|
+
} from '@futdevpro/fsm-dynamo';
|
|
18
|
+
import { DyNTS_archiveSuffix } from '../../_collections/archive.util';
|
|
19
|
+
import { DyNTS_DBUpdate } from '../../_models/types/db-update.type';
|
|
20
|
+
import { DyNTS_global_settings } from '../../_collections/global-settings.const';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* DB Service for MongoDB
|
|
24
|
+
*/
|
|
25
|
+
export class DyNTS_DBService<T extends DyFM_Metadata> {
|
|
26
|
+
|
|
27
|
+
serviceName: string;
|
|
28
|
+
|
|
29
|
+
dataModel/* : mongoose.Model<T> */; // = mongoose.model(this.dataParams.dataName, this.getSchema());
|
|
30
|
+
|
|
31
|
+
/* private depDataName: string; */
|
|
32
|
+
private readonly depKeys: string[] = [];
|
|
33
|
+
|
|
34
|
+
defaultErrorUserMsg =
|
|
35
|
+
`We encountered an unhandled DB Error, ` +
|
|
36
|
+
`\nplease contact the responsible development team.`;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param dataName name the model
|
|
40
|
+
* @param typeSample sample data for scheme creation (dont include DyFM_Metadata!)
|
|
41
|
+
* @param schemaSettings additional settings for specific parameters as unique, required, minlength or maxlength
|
|
42
|
+
* schemaSettings also MUST contain specific types that differs from the listed above (Array, Date)
|
|
43
|
+
*/
|
|
44
|
+
constructor(
|
|
45
|
+
public dataParams: DyFM_DataModel_Params<T>
|
|
46
|
+
){
|
|
47
|
+
try {
|
|
48
|
+
this.serviceName = this.constructor?.name;
|
|
49
|
+
|
|
50
|
+
if (!this.dataParams.dataName || typeof this.dataParams.dataName !== 'string') {
|
|
51
|
+
throw new Error(
|
|
52
|
+
`dbName not setted up for this db-service (${this.dataParams.dataName}) (NTS DB)`
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!this.dataParams.constructed?.()) {
|
|
57
|
+
throw new DyFM_Error({
|
|
58
|
+
error: new Error(
|
|
59
|
+
`DataModelParams is not constructed properly! (${this.dataParams.dataName}) ` +
|
|
60
|
+
`Use the DyFM_DataModel_Params.constructor to construct it properly! (NTS DB)`
|
|
61
|
+
),
|
|
62
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-C01`,
|
|
63
|
+
additionalContent: { dataParams: this.dataParams },
|
|
64
|
+
__localStack: this.dataParams.stackLocation,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
this.dataModel = mongoose.model(this.dataParams.dataName, this.getSchema());
|
|
70
|
+
} catch (error) {
|
|
71
|
+
if (mongoose.models[this.dataParams.dataName]) {
|
|
72
|
+
this.dataModel = mongoose.models[this.dataParams.dataName];
|
|
73
|
+
} else {
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
this.lookForDependencyDataSettings();
|
|
79
|
+
} catch (error) {
|
|
80
|
+
throw new DyFM_Error({
|
|
81
|
+
message:
|
|
82
|
+
`DyNTS_DBService construction failed! "${dataParams.dataName}" - "${this.serviceName}"`,
|
|
83
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-C00`,
|
|
84
|
+
level: DyFM_ErrorLevel.critical,
|
|
85
|
+
additionalContent: { dataParams: this.dataParams },
|
|
86
|
+
error,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* save new data
|
|
93
|
+
* @param data data
|
|
94
|
+
* @returns data
|
|
95
|
+
*/
|
|
96
|
+
async createData(data: T, issuer: string): Promise<T> {
|
|
97
|
+
data.__created = new Date();
|
|
98
|
+
data.__lastModified = new Date();
|
|
99
|
+
data.__createdBy = issuer;
|
|
100
|
+
data.__lastModifiedBy = issuer;
|
|
101
|
+
|
|
102
|
+
const dataModel = new this.dataModel(data);
|
|
103
|
+
const newData: T = await dataModel.save().then((res): T => {
|
|
104
|
+
if (res) {
|
|
105
|
+
return res?.toObject() as T;
|
|
106
|
+
|
|
107
|
+
} else {
|
|
108
|
+
throw new DyFM_Error({
|
|
109
|
+
...this._getDefaultErrorSettings(
|
|
110
|
+
'createData',
|
|
111
|
+
new Error(
|
|
112
|
+
`createData failed, save "${this.dataParams.dataName}" result not found! (NTS DB)`
|
|
113
|
+
),
|
|
114
|
+
issuer
|
|
115
|
+
),
|
|
116
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-CD1`,
|
|
117
|
+
additionalContent: { data },
|
|
118
|
+
issuer,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}).catch((error): void => {
|
|
122
|
+
if (error?.flag?.includes('DYNAMO')) {
|
|
123
|
+
throw error;
|
|
124
|
+
|
|
125
|
+
} else {
|
|
126
|
+
throw new DyFM_Error({
|
|
127
|
+
...this._getDefaultErrorSettings('createData', error, issuer),
|
|
128
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-CD0`,
|
|
129
|
+
additionalContent: {
|
|
130
|
+
data: data,
|
|
131
|
+
dataModel: this.dataModel,
|
|
132
|
+
},
|
|
133
|
+
message:
|
|
134
|
+
`createData failed, Create new "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
135
|
+
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
136
|
+
issuer,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
return this.stringifyDataId(newData, 'createData');
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Find data by _id and update
|
|
146
|
+
* @param data data
|
|
147
|
+
* @returns data
|
|
148
|
+
*/
|
|
149
|
+
async modifyData(data: T, issuer: string, dontUpdateModified?: boolean): Promise<T> {
|
|
150
|
+
if (this.dataParams.forbidModify) {
|
|
151
|
+
await this.modifyThrowMethod(data, issuer);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (!dontUpdateModified) {
|
|
155
|
+
data.__lastModified = new Date();
|
|
156
|
+
data.__lastModifiedBy = issuer;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* EZ A SZAR TELJESEN SZAR, nem friss, nem a db-be mentett adatokat ad vissza,
|
|
161
|
+
* átír random value-kat össze vissza, WTF
|
|
162
|
+
* */
|
|
163
|
+
/* let newData: T = */
|
|
164
|
+
await this.dataModel.findByIdAndUpdate(data._id, data)/* .then((res) => {
|
|
165
|
+
if (res) {
|
|
166
|
+
//return res?.toObject() as T;
|
|
167
|
+
} else {
|
|
168
|
+
throw new DyFM_Error({
|
|
169
|
+
...this._getDefaultErrorSettings(
|
|
170
|
+
'modifyData',
|
|
171
|
+
new Error(`modifyData failed, modify "${this.dataParams.dataName}" result not found! (NTS DB)`),
|
|
172
|
+
issuer,
|
|
173
|
+
),
|
|
174
|
+
|
|
175
|
+
status: 204,
|
|
176
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-FU1`,
|
|
177
|
+
additionalContent: { data },
|
|
178
|
+
issuer,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}) */.catch((error): void => {
|
|
182
|
+
throw new DyFM_Error({
|
|
183
|
+
...this._getDefaultErrorSettings('modifyData', error, issuer),
|
|
184
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-FU0`,
|
|
185
|
+
additionalContent: { data },
|
|
186
|
+
message:
|
|
187
|
+
`modifyData "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
188
|
+
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
189
|
+
issuer,
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
return this.stringifyDataId(data, 'modifyData');
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// TODO: Missing issuer
|
|
197
|
+
/**
|
|
198
|
+
* returns data by _id,
|
|
199
|
+
* @param id id
|
|
200
|
+
* @returns data
|
|
201
|
+
*/
|
|
202
|
+
async getDataById(id: string): Promise<T> {
|
|
203
|
+
if (!id) {
|
|
204
|
+
throw new DyFM_Error({
|
|
205
|
+
...this._getDefaultErrorSettings('getDataById', new Error(`No ID provided! (NTS DB)`)),
|
|
206
|
+
|
|
207
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-GI1`,
|
|
208
|
+
message: `get "${this.dataParams.dataName}" by ID was unsuccessful (NTS DB)`,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const data: T = await this.dataModel
|
|
213
|
+
.findById(id)
|
|
214
|
+
.then((res): T => res?.toObject() as T ?? null)
|
|
215
|
+
.catch((error): void => {
|
|
216
|
+
throw new DyFM_Error({
|
|
217
|
+
...this._getDefaultErrorSettings('getDataById', error),
|
|
218
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-GI0`,
|
|
219
|
+
additionalContent: { id },
|
|
220
|
+
message:
|
|
221
|
+
`get "${this.dataParams.dataName}" by ID was unsuccessful (NTS DB)` +
|
|
222
|
+
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
return this.stringifyDataId(data, 'getDataById');
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// TODO: Missing issuer
|
|
230
|
+
/**
|
|
231
|
+
* get data by dependency data id,
|
|
232
|
+
* !!!: throws error if not found (errorCode on not found: NTS-DBS-GD2)
|
|
233
|
+
*
|
|
234
|
+
* @param dependencyIdsFilter id
|
|
235
|
+
* @returns data
|
|
236
|
+
*/
|
|
237
|
+
async getDataByDependencyId(dependencyIdsFilter: { [key: string]: string }): Promise<T> {
|
|
238
|
+
if (!this.depKeys.length) {
|
|
239
|
+
throw new DyFM_Error({
|
|
240
|
+
...this._getDefaultErrorSettings(
|
|
241
|
+
'getDataByDependencyId',
|
|
242
|
+
new Error(
|
|
243
|
+
`dependencyDataIdKey not setted up for this db-service (${this.dataParams.dataName}) (NTS DB)`
|
|
244
|
+
)
|
|
245
|
+
),
|
|
246
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-GD0`,
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const data: T = await this.dataModel
|
|
251
|
+
.findOne(dependencyIdsFilter)
|
|
252
|
+
.then((res): T => res?.toObject() as T ?? null)
|
|
253
|
+
.catch((error): void => {
|
|
254
|
+
throw new DyFM_Error({
|
|
255
|
+
...this._getDefaultErrorSettings('getDataByDependencyId', error),
|
|
256
|
+
|
|
257
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-GD1`,
|
|
258
|
+
additionalContent: { dependencyIdsFilter: dependencyIdsFilter },
|
|
259
|
+
message:
|
|
260
|
+
`get "${this.dataParams.dataName}" by ` +
|
|
261
|
+
`"${Object.keys(dependencyIdsFilter).join(', ')}" was unsuccessful (NTS DB)` +
|
|
262
|
+
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
return this.stringifyDataId(data, 'getDataByDependencyId');
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// TODO: Missing issuer
|
|
270
|
+
async getDataListByIds(ids: string[], findDeleted?: boolean): Promise<T[]> {
|
|
271
|
+
const dataList: T[] = await this.dataModel
|
|
272
|
+
.find({ _id: { $in: ids } })
|
|
273
|
+
.then((res): T[] => res as T[] ?? [])
|
|
274
|
+
.catch((error): void => {
|
|
275
|
+
throw new DyFM_Error({
|
|
276
|
+
...this._getDefaultErrorSettings('getDataListByIds', error),
|
|
277
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-GDL0`,
|
|
278
|
+
additionalContent: { ids },
|
|
279
|
+
message:
|
|
280
|
+
`get "${this.dataParams.dataName}" by IDs was unsuccessful (NTS DB)` +
|
|
281
|
+
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
if (!findDeleted) {
|
|
286
|
+
return dataList.filter(
|
|
287
|
+
(data: T): boolean => !data._deleted
|
|
288
|
+
).map(
|
|
289
|
+
(data: T): T => this.stringifyDataId(data, 'getDataListByDependencyId')
|
|
290
|
+
);
|
|
291
|
+
} else {
|
|
292
|
+
return dataList.map(
|
|
293
|
+
(data: T): T => this.stringifyDataId(data, 'getDataListByDependencyId')
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// TODO: Missing issuer
|
|
299
|
+
/**
|
|
300
|
+
* get data by dependency data id,
|
|
301
|
+
* !!!: throws error if not found (errorCode on not found: NTS-DBS-GLD2)
|
|
302
|
+
*
|
|
303
|
+
* @param dependencyIdsFilter id
|
|
304
|
+
* @returns dataList
|
|
305
|
+
*/
|
|
306
|
+
async getDataListByDependencyId(dependencyIdsFilter: { [key: string]: string }, findDeleted?: boolean): Promise<T[]> {
|
|
307
|
+
if (!this.depKeys.length) {
|
|
308
|
+
throw new DyFM_Error({
|
|
309
|
+
...this._getDefaultErrorSettings(
|
|
310
|
+
'getDataListByDependencyId',
|
|
311
|
+
new Error(
|
|
312
|
+
`isDependencyHook not setted up for this dataModel (${this.dataParams.dataName}) (NTS DB)`
|
|
313
|
+
)
|
|
314
|
+
),
|
|
315
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-GLD0`,
|
|
316
|
+
additionalContent: {
|
|
317
|
+
dataModel: this.dataModel,
|
|
318
|
+
},
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const dataList: T[] = await this.dataModel
|
|
323
|
+
.find(dependencyIdsFilter)
|
|
324
|
+
.then((res): T[] => res as T[] ?? [])
|
|
325
|
+
.catch((error): void => {
|
|
326
|
+
throw new DyFM_Error({
|
|
327
|
+
...this._getDefaultErrorSettings('getDataListByDependencyId', error),
|
|
328
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-GLD1`,
|
|
329
|
+
additionalContent: { dependencyIdsFilter: dependencyIdsFilter },
|
|
330
|
+
message:
|
|
331
|
+
`get "${this.dataParams.dataName}" by ` +
|
|
332
|
+
`"${Object.keys(dependencyIdsFilter).join(', ')}" was unsuccessful (NTS DB)` +
|
|
333
|
+
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
if (!findDeleted) {
|
|
338
|
+
return dataList.filter(
|
|
339
|
+
(data: T): boolean => !data._deleted
|
|
340
|
+
).map(
|
|
341
|
+
(data: T): T => this.stringifyDataId(data, 'getDataListByDependencyId')
|
|
342
|
+
);
|
|
343
|
+
} else {
|
|
344
|
+
return dataList.map(
|
|
345
|
+
(data: T): T => this.stringifyDataId(data, 'getDataListByDependencyId')
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// TODO: Missing issuer
|
|
351
|
+
/**
|
|
352
|
+
* get multiple data objects by a list of DependencyIDs,
|
|
353
|
+
* !!!: throws error if not found (errorCode on not found: NTS-DBS-GLDS2)
|
|
354
|
+
*
|
|
355
|
+
* @param ids ids
|
|
356
|
+
* @returns dataList
|
|
357
|
+
*/
|
|
358
|
+
async getDataListByDependencyIds(dependencyKey: string, dependencyIds: string[], findDeleted?: boolean): Promise<T[]> {
|
|
359
|
+
if (!this.depKeys.length) {
|
|
360
|
+
throw new DyFM_Error({
|
|
361
|
+
...this._getDefaultErrorSettings(
|
|
362
|
+
'getDataListByDependencyIds',
|
|
363
|
+
new Error(
|
|
364
|
+
`getDataListByDependencyIds not setted up for this db-service ` +
|
|
365
|
+
`(${this.dataParams.dataName}) (NTS DB)`
|
|
366
|
+
)
|
|
367
|
+
),
|
|
368
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-GLDS0`,
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
if (!dependencyIds?.length) {
|
|
373
|
+
return [];
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
if (!dependencyKey) {
|
|
377
|
+
throw new DyFM_Error({
|
|
378
|
+
...this._getDefaultErrorSettings(
|
|
379
|
+
'getDataListByDependencyIds',
|
|
380
|
+
new Error(`dependencyKey is missing! (${this.dataParams.dataName}) (NTS DB)`),
|
|
381
|
+
),
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
if (!this.depKeys.includes(dependencyKey)) {
|
|
386
|
+
throw new DyFM_Error({
|
|
387
|
+
...this._getDefaultErrorSettings(
|
|
388
|
+
'getDataListByDependencyIds',
|
|
389
|
+
new Error(`dependencyKey is not valid! (${dependencyKey}) (NTS DB)`),
|
|
390
|
+
),
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const dataList: T[] = await this.dataModel
|
|
395
|
+
.find({
|
|
396
|
+
[dependencyKey]: { $in: dependencyIds },
|
|
397
|
+
})
|
|
398
|
+
.then((res): T[] => res as T[] ?? [])
|
|
399
|
+
.catch((error): void => {
|
|
400
|
+
throw new DyFM_Error({
|
|
401
|
+
...this._getDefaultErrorSettings('getDataListByDependencyIds', error),
|
|
402
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-GLDS1`,
|
|
403
|
+
additionalContent: { dependencyIds },
|
|
404
|
+
message:
|
|
405
|
+
`get "${this.dataParams.dataName}" by "${dependencyKey}" was unsuccessful (NTS DB)` +
|
|
406
|
+
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
407
|
+
});
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
if (!findDeleted) {
|
|
411
|
+
return dataList.filter(
|
|
412
|
+
(data: T): boolean => !data._deleted
|
|
413
|
+
).map(
|
|
414
|
+
(data: T): T => this.stringifyDataId(data, 'getDataListByDependencyIds')
|
|
415
|
+
);
|
|
416
|
+
} else {
|
|
417
|
+
return dataList.map(
|
|
418
|
+
(data: T): T => this.stringifyDataId(data, 'getDataListByDependencyIds')
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// TODO: Missing issuer
|
|
424
|
+
/**
|
|
425
|
+
* returns all data from database,
|
|
426
|
+
* !!!: throws error if not found (errorCode on not found: NTS-DBS-GA1)
|
|
427
|
+
*
|
|
428
|
+
* @returns dataList
|
|
429
|
+
*/
|
|
430
|
+
async getAll(findDeleted?: boolean): Promise<T[]> {
|
|
431
|
+
const dataList: T[] = await this.dataModel
|
|
432
|
+
.find()
|
|
433
|
+
.then((res): T[] => res as T[] ?? [])
|
|
434
|
+
.catch((error): void => {
|
|
435
|
+
throw new DyFM_Error({
|
|
436
|
+
...this._getDefaultErrorSettings('getAll', error),
|
|
437
|
+
|
|
438
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-GA0`,
|
|
439
|
+
message:
|
|
440
|
+
`get all "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
441
|
+
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
if (!findDeleted) {
|
|
446
|
+
return dataList.filter(
|
|
447
|
+
(data: T): boolean => !data._deleted
|
|
448
|
+
).map(
|
|
449
|
+
(data: T): T => this.stringifyDataId(data, 'getAll')
|
|
450
|
+
);
|
|
451
|
+
} else {
|
|
452
|
+
return dataList.map(
|
|
453
|
+
(data: T): T => this.stringifyDataId(data, 'getAll')
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
async markDeletedById(id: string, issuer: string): Promise<void> {
|
|
459
|
+
if (this.dataParams.forbidDelete) {
|
|
460
|
+
await this.deleteThrowMethod(id, issuer);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
await this.dataModel.findByIdAndUpdate(
|
|
464
|
+
id,
|
|
465
|
+
{
|
|
466
|
+
_deleted: new Date(),
|
|
467
|
+
_deletedBy: issuer,
|
|
468
|
+
},
|
|
469
|
+
/* issuer */
|
|
470
|
+
).catch(
|
|
471
|
+
(error): void => {
|
|
472
|
+
throw new DyFM_Error({
|
|
473
|
+
...this._getDefaultErrorSettings('markDeletedById', error, issuer),
|
|
474
|
+
|
|
475
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-MD0`,
|
|
476
|
+
additionalContent: { id },
|
|
477
|
+
message:
|
|
478
|
+
`mark deleted "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
479
|
+
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
480
|
+
issuer,
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
async markDeletedByDependencyId(dependencyIdsFilter: { [key: string]: string }, issuer: string): Promise<void> {
|
|
487
|
+
if (this.dataParams.forbidDelete) {
|
|
488
|
+
await this.deleteThrowMethod(dependencyIdsFilter, issuer);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
await this.dataModel.updateMany(
|
|
492
|
+
dependencyIdsFilter,
|
|
493
|
+
{
|
|
494
|
+
_deleted: new Date(),
|
|
495
|
+
_deletedBy: issuer,
|
|
496
|
+
}
|
|
497
|
+
).catch((error): void => {
|
|
498
|
+
throw new DyFM_Error({
|
|
499
|
+
...this._getDefaultErrorSettings('markDeletedByDependencyId', error, issuer),
|
|
500
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-MDD0`,
|
|
501
|
+
additionalContent: { dependencyIdsFilter: dependencyIdsFilter },
|
|
502
|
+
message:
|
|
503
|
+
`markDeleted "${this.dataParams.dataName}" by ` +
|
|
504
|
+
`"${Object.keys(dependencyIdsFilter).join(', ')}" was unsuccessful (NTS DB)` +
|
|
505
|
+
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
506
|
+
issuer,
|
|
507
|
+
});
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
async restoreDeletedById(id: string, issuer: string): Promise<void> {
|
|
512
|
+
await this.dataModel.findByIdAndUpdate(
|
|
513
|
+
id,
|
|
514
|
+
{
|
|
515
|
+
_deleted: null,
|
|
516
|
+
__lastModified: new Date(),
|
|
517
|
+
__lastModifiedBy: issuer,
|
|
518
|
+
},
|
|
519
|
+
/* issuer */
|
|
520
|
+
).catch((error): void => {
|
|
521
|
+
throw new DyFM_Error({
|
|
522
|
+
...this._getDefaultErrorSettings('restoreDeletedById', error, issuer),
|
|
523
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-RD0`,
|
|
524
|
+
additionalContent: { id },
|
|
525
|
+
message:
|
|
526
|
+
`restoreDeleted "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
527
|
+
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
528
|
+
issuer,
|
|
529
|
+
});
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
async restoreDeletedByDependencyId(
|
|
534
|
+
dependencyIdsFilter: { [key: string]: string },
|
|
535
|
+
issuer: string
|
|
536
|
+
): Promise<void> {
|
|
537
|
+
await this.dataModel.updateMany(
|
|
538
|
+
dependencyIdsFilter,
|
|
539
|
+
{
|
|
540
|
+
_deleted: null,
|
|
541
|
+
__lastModified: new Date(),
|
|
542
|
+
__lastModifiedBy: issuer,
|
|
543
|
+
}
|
|
544
|
+
).catch((error): void => {
|
|
545
|
+
throw new DyFM_Error({
|
|
546
|
+
...this._getDefaultErrorSettings('restoreDeletedByDependencyId', error, issuer),
|
|
547
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-RDD0`,
|
|
548
|
+
additionalContent: { dependencyIdsFilter: dependencyIdsFilter },
|
|
549
|
+
message:
|
|
550
|
+
`restoreDeleted "${this.dataParams.dataName}" by ` +
|
|
551
|
+
`"${Object.keys(dependencyIdsFilter).join(', ')}" was unsuccessful (NTS DB)` +
|
|
552
|
+
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
553
|
+
issuer,
|
|
554
|
+
});
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// TODO: Missing issuer
|
|
559
|
+
async getDeletedDataList(): Promise<T[]> {
|
|
560
|
+
const dataList: T[] = await this.dataModel
|
|
561
|
+
.getAll()
|
|
562
|
+
.then((res): T[] => res as T[] ?? [])
|
|
563
|
+
.catch((error): void => {
|
|
564
|
+
throw new DyFM_Error({
|
|
565
|
+
...this._getDefaultErrorSettings('getDeletedData', error),
|
|
566
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-GDD0`,
|
|
567
|
+
message:
|
|
568
|
+
`get deleted "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
569
|
+
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
570
|
+
});
|
|
571
|
+
});
|
|
572
|
+
|
|
573
|
+
return dataList.filter(
|
|
574
|
+
(data: T): boolean => Boolean(data._deleted)
|
|
575
|
+
).map((data: T): T => this.stringifyDataId(data, 'getDeletedData'));
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
// TODO: Missing issuer
|
|
579
|
+
/**
|
|
580
|
+
* deleted data by id
|
|
581
|
+
* @param id id
|
|
582
|
+
*/
|
|
583
|
+
async trueDeleteDataById(id: string): Promise<void> {
|
|
584
|
+
if (this.dataParams.forbidDelete) {
|
|
585
|
+
await this.deleteThrowMethod(id/* , issuer */);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
await this.dataModel
|
|
589
|
+
.findByIdAndDelete(id)
|
|
590
|
+
.catch((error): void => {
|
|
591
|
+
throw new DyFM_Error({
|
|
592
|
+
...this._getDefaultErrorSettings('deleteDataById', error),
|
|
593
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-DD0`,
|
|
594
|
+
additionalContent: { id },
|
|
595
|
+
message:
|
|
596
|
+
`delete "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
597
|
+
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
598
|
+
});
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
readonly deleteDataById = this.trueDeleteDataById;
|
|
602
|
+
|
|
603
|
+
// TODO: Missing issuer
|
|
604
|
+
/**
|
|
605
|
+
* deleted data by id
|
|
606
|
+
* @param dependencyId id
|
|
607
|
+
*/
|
|
608
|
+
async trueDeleteDataByDependencyId(dependencyIdsFilter: { [key: string]: string }): Promise<void> {
|
|
609
|
+
if (this.dataParams.forbidDelete) {
|
|
610
|
+
await this.deleteThrowMethod(dependencyIdsFilter/* , issuer */);
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
if (!this.depKeys.length) {
|
|
614
|
+
throw new DyFM_Error({
|
|
615
|
+
...this._getDefaultErrorSettings(
|
|
616
|
+
'deleteDataByDependencyId',
|
|
617
|
+
new Error(
|
|
618
|
+
`dependencyDataIdKey not setted up for this db-service (${this.dataParams.dataName}) (NTS DB)`
|
|
619
|
+
)
|
|
620
|
+
),
|
|
621
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-DDD0`,
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
await this.dataModel
|
|
626
|
+
.deleteMany(dependencyIdsFilter)
|
|
627
|
+
.catch((error): void => {
|
|
628
|
+
throw new DyFM_Error({
|
|
629
|
+
...this._getDefaultErrorSettings('deleteDataByDependencyId', error),
|
|
630
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-DDD1`,
|
|
631
|
+
additionalContent: { dependencyIdsFilter: dependencyIdsFilter },
|
|
632
|
+
message:
|
|
633
|
+
`delete "${this.dataParams.dataName}" by ` +
|
|
634
|
+
`"${Object.keys(dependencyIdsFilter).join(', ')}" was unsuccessful (NTS DB)` +
|
|
635
|
+
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
636
|
+
});
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
readonly deleteDataByDependencyId = this.trueDeleteDataByDependencyId;
|
|
640
|
+
|
|
641
|
+
// TODO: Missing issuer
|
|
642
|
+
async trueDeleteAllData(): Promise<void> {
|
|
643
|
+
if (this.dataParams.forbidDelete) {
|
|
644
|
+
await this.deleteThrowMethod(null/* , issuer */);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
await this.dataModel.deleteMany().catch((error): void => {
|
|
648
|
+
throw new DyFM_Error({
|
|
649
|
+
...this._getDefaultErrorSettings('deleteAllData', error),
|
|
650
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-DAD0`,
|
|
651
|
+
message:
|
|
652
|
+
`delete all "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
653
|
+
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
654
|
+
});
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
readonly deleteAllData = this.trueDeleteAllData;
|
|
658
|
+
|
|
659
|
+
// TODO: Missing issuer
|
|
660
|
+
/**
|
|
661
|
+
* returns search result for searchBy object params
|
|
662
|
+
* can use lists or xRange values for searchBy obj properties
|
|
663
|
+
*
|
|
664
|
+
* @param filterBy filter
|
|
665
|
+
* @param narrowByDependencyIds id
|
|
666
|
+
* @returns dataList
|
|
667
|
+
*/
|
|
668
|
+
async searchData(
|
|
669
|
+
filterBy: DyFM_DBFilter<T>,
|
|
670
|
+
narrowByDependencyIds?: string[],
|
|
671
|
+
narrowByDependencyKey?: string,
|
|
672
|
+
findDeleted?: boolean
|
|
673
|
+
): Promise<T[]> {
|
|
674
|
+
const filter = {};
|
|
675
|
+
|
|
676
|
+
if (0 < narrowByDependencyIds.length) {
|
|
677
|
+
if (!this.depKeys.length) {
|
|
678
|
+
throw new DyFM_Error({
|
|
679
|
+
...this._getDefaultErrorSettings(
|
|
680
|
+
'searchData',
|
|
681
|
+
new Error(
|
|
682
|
+
`dependencyDataIdKey not setted up for this db-service (${this.dataParams.dataName}) (NTS DB)`
|
|
683
|
+
)
|
|
684
|
+
),
|
|
685
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-SD0`,
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
if (!narrowByDependencyKey) {
|
|
690
|
+
if (this.depKeys.length === 1) {
|
|
691
|
+
narrowByDependencyKey = this.depKeys[0];
|
|
692
|
+
} else {
|
|
693
|
+
throw new DyFM_Error({
|
|
694
|
+
...this._getDefaultErrorSettings(
|
|
695
|
+
'searchData',
|
|
696
|
+
new Error(`dependencyKey is missing! (${this.dataParams.dataName}) (NTS DB)`),
|
|
697
|
+
),
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
filter[narrowByDependencyKey] = { $in: narrowByDependencyIds };
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
Object.values(this.dataParams.properties).forEach(
|
|
706
|
+
(modelParam: DyFM_DataProperty_Params<any, T>): void => {
|
|
707
|
+
if (
|
|
708
|
+
(filterBy[modelParam.key] !== null && filterBy[modelParam.key] !== undefined) ||
|
|
709
|
+
filterBy[modelParam.key + 'Range']
|
|
710
|
+
) {
|
|
711
|
+
if (modelParam.key.includes('Range') || modelParam.type.includes('[]')) {
|
|
712
|
+
// inverz search filter (for Range and Array functions)
|
|
713
|
+
if (modelParam.key.includes('Range')) {
|
|
714
|
+
const searchParamKeyWithoutRange = modelParam.key.split('Range')[0];
|
|
715
|
+
|
|
716
|
+
if (
|
|
717
|
+
filterBy[searchParamKeyWithoutRange] !== null &&
|
|
718
|
+
filterBy[searchParamKeyWithoutRange] !== undefined
|
|
719
|
+
) {
|
|
720
|
+
filter[modelParam.key] = {
|
|
721
|
+
from: { $lte: filterBy[searchParamKeyWithoutRange] },
|
|
722
|
+
to: { $gte: filterBy[searchParamKeyWithoutRange] },
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
} else {
|
|
726
|
+
if (
|
|
727
|
+
filterBy[modelParam.key] !== null &&
|
|
728
|
+
filterBy[modelParam.key] !== undefined
|
|
729
|
+
) {
|
|
730
|
+
filter[modelParam.key] = { $in: filterBy[modelParam.key] };
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
} else {
|
|
734
|
+
// basic search filter
|
|
735
|
+
if (filterBy[modelParam.key + 'Range']) {
|
|
736
|
+
if (
|
|
737
|
+
filterBy[modelParam.key + 'Range'].from ||
|
|
738
|
+
filterBy[modelParam.key + 'Range'].to
|
|
739
|
+
) {
|
|
740
|
+
filter[modelParam.key] = {};
|
|
741
|
+
|
|
742
|
+
if (filterBy[modelParam.key + 'Range'].from) {
|
|
743
|
+
filter[modelParam.key].$gte = filterBy[modelParam.key + 'Range'].from;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
if (filterBy[modelParam.key + 'Range'].to) {
|
|
747
|
+
filter[modelParam.key].$lte = filterBy[modelParam.key + 'Range'].to;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
} else if (
|
|
751
|
+
filterBy[modelParam.key] !== null &&
|
|
752
|
+
filterBy[modelParam.key] !== undefined
|
|
753
|
+
) {
|
|
754
|
+
if (filterBy[modelParam.key].lenght > 0) {
|
|
755
|
+
filter[modelParam.key] = { $in: filterBy[modelParam.key] };
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
);
|
|
762
|
+
|
|
763
|
+
let dataList: T[] = await this.dataModel
|
|
764
|
+
.find(filter)
|
|
765
|
+
.then((res): T[] => res as T[] ?? [])
|
|
766
|
+
.catch((error): void => {
|
|
767
|
+
throw new DyFM_Error({
|
|
768
|
+
...this._getDefaultErrorSettings('searchData', error),
|
|
769
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-SD1`,
|
|
770
|
+
additionalContent: { filterBy, narrowByDependencyIds },
|
|
771
|
+
message:
|
|
772
|
+
`search "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
773
|
+
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
774
|
+
});
|
|
775
|
+
});
|
|
776
|
+
|
|
777
|
+
if (!findDeleted && (filterBy as DyFM_DBFilterSimple<T>)._deleted === undefined) {
|
|
778
|
+
dataList = dataList.filter((data: T): boolean => !data._deleted);
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
return dataList.map((data: T): T => this.stringifyDataId(data, 'searchData'));
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
// ----------------------------------------------------------------------------------
|
|
785
|
+
// ----------------------------------------------------------------------------------
|
|
786
|
+
// ----------------------------------------------------------------------------------
|
|
787
|
+
// DIRECT Basic MONGOOSE FUNCTIONS (with error handlings)
|
|
788
|
+
|
|
789
|
+
/**
|
|
790
|
+
* Find the data first by any of its parameters,
|
|
791
|
+
* !!!: throws error if not found (errorCode on not found: NTS-DBS-FO1)
|
|
792
|
+
*
|
|
793
|
+
* @param filterBy if you can, use unique parameters for find!
|
|
794
|
+
*
|
|
795
|
+
* @example
|
|
796
|
+
* // by email:
|
|
797
|
+
* { email: email }
|
|
798
|
+
* //
|
|
799
|
+
* @example
|
|
800
|
+
* // or by id that is in list:
|
|
801
|
+
* { userIds: { $in: this.userId } }
|
|
802
|
+
* // or by userIds:
|
|
803
|
+
* { userId: { $in: userIds } }
|
|
804
|
+
* //
|
|
805
|
+
* @example
|
|
806
|
+
* // or by number or Date that is Greater Than AND Less Than:
|
|
807
|
+
* { points: { $gt: 2, $lt: 14 } }
|
|
808
|
+
* // further tools (syntax matches with $gt):
|
|
809
|
+
* $eq: // Matches values that are EQual to a specified value.
|
|
810
|
+
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
811
|
+
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
812
|
+
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
813
|
+
* $nin: // Matches None of the values specified IN an array.
|
|
814
|
+
* //
|
|
815
|
+
* @returns {T} data: T
|
|
816
|
+
*/
|
|
817
|
+
async findOne(filterBy: DyFM_DBFilter<T>): Promise<T> {
|
|
818
|
+
const data: T = await this.dataModel
|
|
819
|
+
.findOne(filterBy)
|
|
820
|
+
.then((res): T => res as T ?? null)
|
|
821
|
+
.catch((error): void => {
|
|
822
|
+
throw new DyFM_Error({
|
|
823
|
+
...this._getDefaultErrorSettings('findOne', error),
|
|
824
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-FO0`,
|
|
825
|
+
additionalContent: { filterBy },
|
|
826
|
+
message:
|
|
827
|
+
`findOne "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
828
|
+
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
829
|
+
});
|
|
830
|
+
});
|
|
831
|
+
|
|
832
|
+
return this.stringifyDataId(data, 'findOne');
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
/**
|
|
836
|
+
* #MONGOOSE FUNCTION
|
|
837
|
+
* Find the data first by any of its parameters,
|
|
838
|
+
* !!!: throws error if not found (errorCode on not found: NTS-DBS-F1)
|
|
839
|
+
*
|
|
840
|
+
* @param filterBy if you can, use unique parameters for find!
|
|
841
|
+
*
|
|
842
|
+
* @example
|
|
843
|
+
* // by email:
|
|
844
|
+
* { email: email }
|
|
845
|
+
* //
|
|
846
|
+
* @example
|
|
847
|
+
* // or by id that is in list:
|
|
848
|
+
* { userIds: { $in: this.userId } }
|
|
849
|
+
* // or by userIds:
|
|
850
|
+
* { userId: { $in: userIds } }
|
|
851
|
+
* //
|
|
852
|
+
* @example
|
|
853
|
+
* // or by number or Date that is Greater Than AND Less Than:
|
|
854
|
+
* { points: { $gt: 2, $lt: 14 } }
|
|
855
|
+
* // further tools (syntax matches with $gt):
|
|
856
|
+
* $eq: // Matches values that are EQual to a specified value.
|
|
857
|
+
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
858
|
+
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
859
|
+
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
860
|
+
* $nin: // Matches None of the values specified IN an array.
|
|
861
|
+
* //
|
|
862
|
+
* @returns {T[]} dataList: T[]
|
|
863
|
+
*/
|
|
864
|
+
async find(filterBy: DyFM_DBFilter<T>, findDeleted?: boolean): Promise<T[]> {
|
|
865
|
+
let dataList: T[] = await this.dataModel
|
|
866
|
+
.find(filterBy)
|
|
867
|
+
.then((res): T[] => res as T[] ?? [])
|
|
868
|
+
.catch((error): void => {
|
|
869
|
+
throw new DyFM_Error({
|
|
870
|
+
...this._getDefaultErrorSettings('find', error),
|
|
871
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-F0`,
|
|
872
|
+
additionalContent: { filterBy },
|
|
873
|
+
message:
|
|
874
|
+
`find "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
875
|
+
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
876
|
+
});
|
|
877
|
+
});
|
|
878
|
+
|
|
879
|
+
if (!findDeleted && (filterBy as DyFM_DBFilterSimple<T>)._deleted === undefined) {
|
|
880
|
+
dataList = dataList.filter((data: T): boolean => !data._deleted);
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
return dataList.map((data: T): T => this.stringifyDataId(data, 'find'));
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
/**
|
|
887
|
+
* #MONGOOSE FUNCTION
|
|
888
|
+
* Find the data first by any of its parameters
|
|
889
|
+
* WARNING: This function will not gives you back the total number of data in the database!
|
|
890
|
+
*
|
|
891
|
+
* @param filterBy if you can, use unique parameters for find!
|
|
892
|
+
*
|
|
893
|
+
* @example
|
|
894
|
+
* // by email:
|
|
895
|
+
* { email: email }
|
|
896
|
+
* //
|
|
897
|
+
* @example
|
|
898
|
+
* // or by id that is in list:
|
|
899
|
+
* { userIds: { $in: this.userId } }
|
|
900
|
+
* // or by userIds:
|
|
901
|
+
* { userId: { $in: userIds } }
|
|
902
|
+
* //
|
|
903
|
+
* @example
|
|
904
|
+
* // or by number or Date that is Greater Than AND Less Than:
|
|
905
|
+
* { points: { $gt: 2, $lt: 14 } }
|
|
906
|
+
* // further tools (syntax matches with $gt):
|
|
907
|
+
* $eq: // Matches values that are EQual to a specified value.
|
|
908
|
+
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
909
|
+
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
910
|
+
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
911
|
+
* $nin: // Matches None of the values specified IN an array.
|
|
912
|
+
* //
|
|
913
|
+
* @param page page
|
|
914
|
+
* @param pageSize pageSize
|
|
915
|
+
* @param sort
|
|
916
|
+
* @example
|
|
917
|
+
* // by dateTime (this uses the basic sort function):
|
|
918
|
+
* { dateTime: -1 }
|
|
919
|
+
* //
|
|
920
|
+
* @returns {T[]} dataList: T[]
|
|
921
|
+
*/
|
|
922
|
+
async findWithPaging(
|
|
923
|
+
filterBy: DyFM_DBFilter<T>,
|
|
924
|
+
page: number,
|
|
925
|
+
pageSize: number,
|
|
926
|
+
sort?: DyFM_DBSort<T>
|
|
927
|
+
): Promise<T[]> {
|
|
928
|
+
/* if (filterBy['_deleted'] === undefined) {
|
|
929
|
+
filterBy['_deleted'] = null;
|
|
930
|
+
} */
|
|
931
|
+
|
|
932
|
+
const dataList: T[] = await this.dataModel
|
|
933
|
+
.find(filterBy)
|
|
934
|
+
.sort(sort)
|
|
935
|
+
.skip(page * pageSize)
|
|
936
|
+
.limit(pageSize)
|
|
937
|
+
.then((res): T => res ?? [])
|
|
938
|
+
.catch((error): void => {
|
|
939
|
+
throw new DyFM_Error({
|
|
940
|
+
...this._getDefaultErrorSettings('findWithPaging', error),
|
|
941
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-WP0`,
|
|
942
|
+
additionalContent: { filterBy, page, pageSize, sort },
|
|
943
|
+
message:
|
|
944
|
+
`findWithPaging "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
945
|
+
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
946
|
+
});
|
|
947
|
+
});
|
|
948
|
+
|
|
949
|
+
/* if ((filterBy as DyFM_DBFilterSimple<T>)._deleted === undefined) {
|
|
950
|
+
dataList = dataList.filter((data: T): boolean => !data._deleted);
|
|
951
|
+
} */
|
|
952
|
+
|
|
953
|
+
return dataList.map((data: T): T => this.stringifyDataId(data, 'find'));
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
/**
|
|
957
|
+
* #MONGOOSE FUNCTION
|
|
958
|
+
* Find data by _id and update
|
|
959
|
+
*
|
|
960
|
+
* @param id id
|
|
961
|
+
* @param update update
|
|
962
|
+
* @returns data
|
|
963
|
+
*/
|
|
964
|
+
async findByIdAndUpdate(
|
|
965
|
+
id: string,
|
|
966
|
+
update: DyNTS_DBUpdate<T>,
|
|
967
|
+
issuer: string,
|
|
968
|
+
dontUpdateModified?: boolean
|
|
969
|
+
): Promise<T> {
|
|
970
|
+
if (this.dataParams.forbidModify) {
|
|
971
|
+
await this.modifyThrowMethod(update, issuer);
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
if (!dontUpdateModified) {
|
|
975
|
+
update.__lastModified = new Date();
|
|
976
|
+
update.__lastModifiedBy = issuer;
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
const data: T = await this.dataModel
|
|
980
|
+
.findByIdAndUpdate(id, update)
|
|
981
|
+
.then((res): T => res?.toObject() as T ?? null)
|
|
982
|
+
.catch((error): void => {
|
|
983
|
+
throw new DyFM_Error({
|
|
984
|
+
...this._getDefaultErrorSettings('findByIdAndUpdate', error, issuer),
|
|
985
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-FIU0`,
|
|
986
|
+
additionalContent: { id, update },
|
|
987
|
+
message:
|
|
988
|
+
`findByIdAndUpdate "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
989
|
+
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
990
|
+
issuer,
|
|
991
|
+
});
|
|
992
|
+
});
|
|
993
|
+
|
|
994
|
+
return this.stringifyDataId(data, 'findByIdAndUpdate');
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
/**
|
|
998
|
+
* #MONGOOSE FUNCTION
|
|
999
|
+
* Find the data first by any of its parameters
|
|
1000
|
+
*
|
|
1001
|
+
* @param filter This uses the basic Mongoose updateOne.
|
|
1002
|
+
* If you can, use unique parameters for find!
|
|
1003
|
+
* @example
|
|
1004
|
+
* // by email:
|
|
1005
|
+
* { email: email }
|
|
1006
|
+
* //
|
|
1007
|
+
* @example
|
|
1008
|
+
* // or by id that is in list:
|
|
1009
|
+
* { userIds: { $in: this.userId } }
|
|
1010
|
+
* // or by userIds:
|
|
1011
|
+
* { userId: { $in: userIds } }
|
|
1012
|
+
* //
|
|
1013
|
+
* @example
|
|
1014
|
+
* // or by number or Date that is Greater Than AND Less Than:
|
|
1015
|
+
* { points: { $gt: 2, $lt: 14 } }
|
|
1016
|
+
* // further tools (syntax matches with $gt):
|
|
1017
|
+
* $eq: // Matches values that are EQual to a specified value.
|
|
1018
|
+
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
1019
|
+
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
1020
|
+
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
1021
|
+
* $nin: // Matches None of the values specified IN an array.
|
|
1022
|
+
* //
|
|
1023
|
+
*
|
|
1024
|
+
* @param update this uses the basic Mongoose updateOne
|
|
1025
|
+
* @example
|
|
1026
|
+
* // increase a specific value (here by 15):
|
|
1027
|
+
* { $inc: { popularity: 15 } }
|
|
1028
|
+
* //
|
|
1029
|
+
* @example
|
|
1030
|
+
* // or add element to a list:
|
|
1031
|
+
* { $push: { reactions: this.newReaction }
|
|
1032
|
+
* // or add multiple elements to a list
|
|
1033
|
+
* { $push: { schedule: {$each: [ monday, tuesday, wednesday ] } } }
|
|
1034
|
+
* //
|
|
1035
|
+
* @example
|
|
1036
|
+
* // or all at once
|
|
1037
|
+
* {
|
|
1038
|
+
* $inc: { popularity: this.newVote.amount },
|
|
1039
|
+
* emailVerified: true,
|
|
1040
|
+
* $push: { reactions: this.newReaction }
|
|
1041
|
+
* }
|
|
1042
|
+
* // further tools (syntax matches with $inc):
|
|
1043
|
+
* $currentDate: // Sets the value of a field to current date, either as a Date or a Timestamp.
|
|
1044
|
+
* $min: // Only updates the field if the specified value is less than the existing field value.
|
|
1045
|
+
* $max: // Only updates the field if the specified value is greater than the existing field value.
|
|
1046
|
+
* $mul: // Multiplies the value of the field by the specified amount.
|
|
1047
|
+
* $rename: // Renames a field.
|
|
1048
|
+
* $unset: // Removes the specified field from a document. (set: "" to value)
|
|
1049
|
+
* //
|
|
1050
|
+
*/
|
|
1051
|
+
async updateOne(
|
|
1052
|
+
filterBy: DyFM_DBFilter<T>,
|
|
1053
|
+
update: DyNTS_DBUpdate<T>,
|
|
1054
|
+
issuer: string,
|
|
1055
|
+
dontUpdateModified?: boolean
|
|
1056
|
+
): Promise<void> {
|
|
1057
|
+
if (this.dataParams.forbidModify) {
|
|
1058
|
+
await this.modifyThrowMethod(update, issuer);
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
if (!dontUpdateModified) {
|
|
1062
|
+
update.__lastModified = new Date();
|
|
1063
|
+
update.__lastModifiedBy = issuer;
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
await this.dataModel
|
|
1067
|
+
.updateOne(filterBy, update)
|
|
1068
|
+
.catch((error): void => {
|
|
1069
|
+
throw new DyFM_Error({
|
|
1070
|
+
...this._getDefaultErrorSettings('updateOne', error, issuer),
|
|
1071
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-UO0`,
|
|
1072
|
+
additionalContent: { filterBy, update },
|
|
1073
|
+
message:
|
|
1074
|
+
`updateOne "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
1075
|
+
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
1076
|
+
issuer,
|
|
1077
|
+
});
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
/**
|
|
1082
|
+
* #MONGOOSE FUNCTION
|
|
1083
|
+
* update one parameter by a specific
|
|
1084
|
+
*
|
|
1085
|
+
* @param filter This uses the basic Mongoose updateMany.
|
|
1086
|
+
* @example
|
|
1087
|
+
* // by email:
|
|
1088
|
+
* { email: email }
|
|
1089
|
+
* //
|
|
1090
|
+
* @example
|
|
1091
|
+
* // or by id that is in list:
|
|
1092
|
+
* { userIds: { $in: this.userId } }
|
|
1093
|
+
* // or by userIds:
|
|
1094
|
+
* { userId: { $in: userIds } }
|
|
1095
|
+
* //
|
|
1096
|
+
* @example
|
|
1097
|
+
* // or by number or Date that is Greater Than AND Less Than:
|
|
1098
|
+
* { points: { $gt: 2, $lt: 14 } }
|
|
1099
|
+
* // further tools (syntax matches with $gt):
|
|
1100
|
+
* $eq: // Matches values that are EQual to a specified value.
|
|
1101
|
+
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
1102
|
+
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
1103
|
+
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
1104
|
+
* $nin: // Matches None of the values specified IN an array.
|
|
1105
|
+
* //
|
|
1106
|
+
*
|
|
1107
|
+
* @param update this uses the basic Mongoose updateOne
|
|
1108
|
+
* @example
|
|
1109
|
+
* // increase a specific value (here by 15):
|
|
1110
|
+
* { $inc: { popularity: 15 } }
|
|
1111
|
+
* //
|
|
1112
|
+
* @example
|
|
1113
|
+
* // or add element to a list:
|
|
1114
|
+
* { $push: { reactions: this.newReaction }
|
|
1115
|
+
* // or add multiple elements to a list
|
|
1116
|
+
* { $push: { schedule: {$each: [ monday, tuesday, wednesday ] } } }
|
|
1117
|
+
* //
|
|
1118
|
+
* @example
|
|
1119
|
+
* // or all at once
|
|
1120
|
+
* {
|
|
1121
|
+
* $inc: { popularity: this.newVote.amount },
|
|
1122
|
+
* emailVerified: true,
|
|
1123
|
+
* $push: { reactions: this.newReaction }
|
|
1124
|
+
* }
|
|
1125
|
+
* // further tools (syntax matches with $inc):
|
|
1126
|
+
* $currentDate: // Sets the value of a field to current date, either as a Date or a Timestamp.
|
|
1127
|
+
* $min: // Only updates the field if the specified value is less than the existing field value.
|
|
1128
|
+
* $max: // Only updates the field if the specified value is greater than the existing field value.
|
|
1129
|
+
* $mul: // Multiplies the value of the field by the specified amount.
|
|
1130
|
+
* $rename: // Renames a field.
|
|
1131
|
+
* $unset: // Removes the specified field from a document. (set: "" to value)
|
|
1132
|
+
* //
|
|
1133
|
+
*/
|
|
1134
|
+
async updateMany(
|
|
1135
|
+
filterBy: DyFM_DBFilter<T>,
|
|
1136
|
+
update: DyNTS_DBUpdate<T>,
|
|
1137
|
+
issuer: string,
|
|
1138
|
+
dontUpdateModified?: boolean
|
|
1139
|
+
): Promise<void> {
|
|
1140
|
+
if (this.dataParams.forbidModify) {
|
|
1141
|
+
await this.modifyThrowMethod(update, issuer);
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
if (!dontUpdateModified) {
|
|
1145
|
+
update.__lastModified = new Date();
|
|
1146
|
+
update.__lastModifiedBy = issuer;
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
await this.dataModel
|
|
1150
|
+
.updateMany(filterBy, update)
|
|
1151
|
+
.catch((error): void => {
|
|
1152
|
+
throw new DyFM_Error({
|
|
1153
|
+
...this._getDefaultErrorSettings('updateMany', error, issuer),
|
|
1154
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-UM0`,
|
|
1155
|
+
additionalContent: { filterBy, update },
|
|
1156
|
+
message:
|
|
1157
|
+
`updateMany "${this.dataParams.dataName}" was unsuccessful (NTS DB)` +
|
|
1158
|
+
`\n error: ${DyFM_Error.getErrorMessage(error)}`,
|
|
1159
|
+
issuer,
|
|
1160
|
+
});
|
|
1161
|
+
});
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
/**
|
|
1165
|
+
* {
|
|
1166
|
+
"mappings": {
|
|
1167
|
+
"dynamic": true,
|
|
1168
|
+
"fields": {
|
|
1169
|
+
"embedding": {
|
|
1170
|
+
"type": "knnVector",
|
|
1171
|
+
"dimensions": 768
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
*/
|
|
1177
|
+
/**
|
|
1178
|
+
*
|
|
1179
|
+
* @param set db.collection.aggregate([
|
|
1180
|
+
{
|
|
1181
|
+
$vectorSearch: {
|
|
1182
|
+
index: "index_neve",
|
|
1183
|
+
queryVector: [a keresett embedding],
|
|
1184
|
+
path: "title.embedding",
|
|
1185
|
+
numCandidates: 100,
|
|
1186
|
+
limit: 5
|
|
1187
|
+
}
|
|
1188
|
+
},
|
|
1189
|
+
{
|
|
1190
|
+
$vectorSearch: {
|
|
1191
|
+
index: "index_neve",
|
|
1192
|
+
queryVector: [a keresett embedding],
|
|
1193
|
+
path: "description.embedding",
|
|
1194
|
+
numCandidates: 100,
|
|
1195
|
+
limit: 5
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
]);
|
|
1199
|
+
* @returns
|
|
1200
|
+
*/
|
|
1201
|
+
async aggregate(set: any) {
|
|
1202
|
+
return this.dataModel.aggregate(set);
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
// ----------------------------------------------------------------------------------
|
|
1206
|
+
// ----------------------------------------------------------------------------------
|
|
1207
|
+
// ----------------------------------------------------------------------------------
|
|
1208
|
+
// PRIVATE FUNCTIONS
|
|
1209
|
+
|
|
1210
|
+
private stringifyDataId(data: T, fnName: string): T {
|
|
1211
|
+
if (data?._id && (typeof data._id !== 'string' || typeof data._id === 'object')) {
|
|
1212
|
+
data._id = `${data._id}`;
|
|
1213
|
+
|
|
1214
|
+
if (typeof data._id !== 'string' || typeof data._id === 'object') {
|
|
1215
|
+
data = JSON.parse(JSON.stringify(data));
|
|
1216
|
+
|
|
1217
|
+
if (typeof data._id !== 'string' || typeof data._id === 'object') {
|
|
1218
|
+
DyFM_Log.error(
|
|
1219
|
+
`data._id stringifying failed! Please notfiy the DynamoNTS developers! (${fnName})`,
|
|
1220
|
+
new Error()
|
|
1221
|
+
);
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
return data;
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
private _getDefaultErrorSettings(
|
|
1230
|
+
fnName: string,
|
|
1231
|
+
error: DyFM_AnyError,
|
|
1232
|
+
issuer?: string
|
|
1233
|
+
): DyFM_Error_Settings {
|
|
1234
|
+
return {
|
|
1235
|
+
status: (error as DyFM_Error)?.___status ?? 500,
|
|
1236
|
+
message: (error as Error)?.message ??
|
|
1237
|
+
(error as DyFM_Error)?._message ??
|
|
1238
|
+
`${fnName} was UNSUCCESSFUL (NTS-DB)`,
|
|
1239
|
+
addECToUserMsg: !(error as DyFM_Error)?.__userMessage,
|
|
1240
|
+
userMessage: (error as DyFM_Error)?.__userMessage ?? this.defaultErrorUserMsg,
|
|
1241
|
+
issuer: issuer,
|
|
1242
|
+
issuerService: this.serviceName,
|
|
1243
|
+
error: error,
|
|
1244
|
+
};
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
// ----------------------------------------------------------------------------------
|
|
1248
|
+
// PRIVATE BUILD FUNCTIONS
|
|
1249
|
+
|
|
1250
|
+
/**
|
|
1251
|
+
* builds and returns mongoose schema
|
|
1252
|
+
* @returns schema
|
|
1253
|
+
*/
|
|
1254
|
+
private getSchema(): mongoose.Schema {
|
|
1255
|
+
this.dataParams.properties = this.addMetadataToProperties(this.dataParams.properties);
|
|
1256
|
+
|
|
1257
|
+
if (this.dataParams.dataName.includes(DyNTS_archiveSuffix)) {
|
|
1258
|
+
this.dataParams.properties = this.addArchiveMetadataToProperties(this.dataParams.properties);
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
const schemaSettings: any = this.buildMongooseSchemaSettingsObjByModelParams(
|
|
1262
|
+
this.dataParams.properties
|
|
1263
|
+
);
|
|
1264
|
+
|
|
1265
|
+
/* schema = this.addMetadataToSchema(schema); */
|
|
1266
|
+
|
|
1267
|
+
/* if (this.dataParams.dataName.includes(DyNTS_archiveSuffix)) {
|
|
1268
|
+
schema = this.addArchiveMetadataToSchema(schema);
|
|
1269
|
+
} */
|
|
1270
|
+
|
|
1271
|
+
if (schemaSettings['_id']) {
|
|
1272
|
+
delete schemaSettings['_id'];
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
return new Schema(schemaSettings);
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
/**
|
|
1279
|
+
* builds mongoose schema building settings object by dynamoDataModelParamsList
|
|
1280
|
+
* @param properties DynamoNTSDataPropertyParams
|
|
1281
|
+
* @returns mongoose schema object
|
|
1282
|
+
*/
|
|
1283
|
+
private buildMongooseSchemaSettingsObjByModelParams(properties: DyFM_DataProperties<T>): any {
|
|
1284
|
+
const schemaSettingsObj = {};
|
|
1285
|
+
|
|
1286
|
+
/* if (!properties) {
|
|
1287
|
+
properties = this.dataParams.properties;
|
|
1288
|
+
} */
|
|
1289
|
+
|
|
1290
|
+
Object.values(properties).forEach((property: DyFM_DataProperty_Params<any, T>): void => {
|
|
1291
|
+
if (!property) {
|
|
1292
|
+
DyFM_Log.warn(`property is undefined on "${this.dataParams.dataName}" (NTS DB)`);
|
|
1293
|
+
|
|
1294
|
+
return;
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
if (!property.key) {
|
|
1298
|
+
const missingKeys = Object.keys(properties).filter((key: string) => !properties[key].key);
|
|
1299
|
+
|
|
1300
|
+
throw new DyFM_Error({
|
|
1301
|
+
...this._getDefaultErrorSettings(
|
|
1302
|
+
'buildMongooseSchemaByModelParams',
|
|
1303
|
+
new Error(
|
|
1304
|
+
`property.key is undefined on "${this.dataParams.dataName}" (NTS DB) ` +
|
|
1305
|
+
`(keys: ${Object.keys(properties).join(', ')}) ` +
|
|
1306
|
+
`(missing keys: ${missingKeys.join(', ')})`
|
|
1307
|
+
)
|
|
1308
|
+
),
|
|
1309
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-BMSBP0`,
|
|
1310
|
+
additionalContent: {
|
|
1311
|
+
property: property,
|
|
1312
|
+
dataParams: this.dataParams,
|
|
1313
|
+
missingKeys: missingKeys,
|
|
1314
|
+
},
|
|
1315
|
+
});
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
if (property.forbidden) {
|
|
1319
|
+
return;
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
const beType = this.getBEType(property.type as DyFM_BasicProperty_Type);
|
|
1323
|
+
|
|
1324
|
+
/* TODO if (beType === Array && property.archiveable && !property.archiveListAfter) {
|
|
1325
|
+
property.archiveListAfter = DyNTS_global_settings.archiveListAfter;
|
|
1326
|
+
} */
|
|
1327
|
+
|
|
1328
|
+
if (
|
|
1329
|
+
beType !== Object ||
|
|
1330
|
+
!property?.subObjectParams ||
|
|
1331
|
+
(property?.subObjectParams &&
|
|
1332
|
+
Object.keys(property.subObjectParams).length == 0)
|
|
1333
|
+
) {
|
|
1334
|
+
schemaSettingsObj[property.key] = {
|
|
1335
|
+
type: beType,
|
|
1336
|
+
};
|
|
1337
|
+
|
|
1338
|
+
if (property.index) {
|
|
1339
|
+
schemaSettingsObj[property.key].index = true;
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
if (property.unique) {
|
|
1343
|
+
schemaSettingsObj[property.key].unique = true;
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
if (property.required) {
|
|
1347
|
+
schemaSettingsObj[property.key].required = true;
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
if (property.minlength) {
|
|
1351
|
+
schemaSettingsObj[property.key].minlength = property.minlength;
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
if (property.maxlength) {
|
|
1355
|
+
schemaSettingsObj[property.key].maxlength = property.maxlength;
|
|
1356
|
+
}
|
|
1357
|
+
} else {
|
|
1358
|
+
schemaSettingsObj[property.key] = this.buildMongooseSchemaSettingsObjByModelParams(
|
|
1359
|
+
property.subObjectParams
|
|
1360
|
+
);
|
|
1361
|
+
}
|
|
1362
|
+
});
|
|
1363
|
+
|
|
1364
|
+
return schemaSettingsObj;
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
private getBEType(
|
|
1368
|
+
type: DyFM_BasicProperty_Type
|
|
1369
|
+
): string | number | boolean | object | Function | Array<any> | Date {
|
|
1370
|
+
switch (type) {
|
|
1371
|
+
case DyFM_BasicProperty_Type.string:
|
|
1372
|
+
return String;
|
|
1373
|
+
|
|
1374
|
+
case DyFM_BasicProperty_Type.number:
|
|
1375
|
+
return Number;
|
|
1376
|
+
|
|
1377
|
+
case DyFM_BasicProperty_Type.boolean:
|
|
1378
|
+
return Boolean;
|
|
1379
|
+
|
|
1380
|
+
case DyFM_BasicProperty_Type.date:
|
|
1381
|
+
return Date;
|
|
1382
|
+
|
|
1383
|
+
case DyFM_BasicProperty_Type.object:
|
|
1384
|
+
return Object;
|
|
1385
|
+
|
|
1386
|
+
case DyFM_BasicProperty_Type.array:
|
|
1387
|
+
return Array;
|
|
1388
|
+
|
|
1389
|
+
case DyFM_BasicProperty_Type.function:
|
|
1390
|
+
return Function;
|
|
1391
|
+
|
|
1392
|
+
default:
|
|
1393
|
+
DyFM_Log.H_info('wtf', DyFM_Object.cleanObject(this.dataParams));
|
|
1394
|
+
|
|
1395
|
+
throw new DyFM_Error({
|
|
1396
|
+
error: new Error(
|
|
1397
|
+
`Invalid property type: "${type}" (${this.dataParams.dataName})` +
|
|
1398
|
+
(this.dataParams.constructed?.() ? '' : ('\nThe dataParams is not constructed properly! \n' +
|
|
1399
|
+
'Use the DyFM_DataModel_Params.constructor to construct it properly!'))
|
|
1400
|
+
),
|
|
1401
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-GTP0`,
|
|
1402
|
+
additionalContent: { type: type, dataParams: this.dataParams },
|
|
1403
|
+
__localStack: this.dataParams.stackLocation,
|
|
1404
|
+
});
|
|
1405
|
+
}
|
|
1406
|
+
/* switch (type.toLocaleLowerCase()) {
|
|
1407
|
+
case DyFM_BasicProperty_Type.string:
|
|
1408
|
+
case 'string':
|
|
1409
|
+
return String;
|
|
1410
|
+
|
|
1411
|
+
case DyFM_BasicProperty_Type.number:
|
|
1412
|
+
case 'number':
|
|
1413
|
+
return Number;
|
|
1414
|
+
|
|
1415
|
+
case DyFM_BasicProperty_Type.boolean:
|
|
1416
|
+
case 'boolean':
|
|
1417
|
+
return Boolean;
|
|
1418
|
+
|
|
1419
|
+
case DyFM_BasicProperty_Type.date:
|
|
1420
|
+
case 'date':
|
|
1421
|
+
return Date;
|
|
1422
|
+
|
|
1423
|
+
case DyFM_BasicProperty_Type.object:
|
|
1424
|
+
case 'object':
|
|
1425
|
+
return Object;
|
|
1426
|
+
|
|
1427
|
+
case DyFM_BasicProperty_Type.array:
|
|
1428
|
+
case 'array':
|
|
1429
|
+
return Array;
|
|
1430
|
+
|
|
1431
|
+
default:
|
|
1432
|
+
if (type.includes('[]') || type.includes('array')) {
|
|
1433
|
+
return Array;
|
|
1434
|
+
} else if (type.includes('=>') || type.includes('function')) {
|
|
1435
|
+
return Function;
|
|
1436
|
+
} else {
|
|
1437
|
+
return Object;
|
|
1438
|
+
}
|
|
1439
|
+
} */
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
/**
|
|
1443
|
+
* adds dynamo metadata settings to any mongoose schema building settings object
|
|
1444
|
+
* @param schema schema to update
|
|
1445
|
+
* @returns updated schema
|
|
1446
|
+
*/
|
|
1447
|
+
/* private addMetadataToSchema(schema: any): any {
|
|
1448
|
+
schema.__created = { type: Date };
|
|
1449
|
+
schema.__createdBy = { type: String };
|
|
1450
|
+
schema.__lastModified = { type: Date };
|
|
1451
|
+
schema.__lastModifiedBy = { type: String };
|
|
1452
|
+
|
|
1453
|
+
schema._deleted = { type: Date };
|
|
1454
|
+
schema._deletedBy = { type: String };
|
|
1455
|
+
|
|
1456
|
+
return schema;
|
|
1457
|
+
} */
|
|
1458
|
+
|
|
1459
|
+
/**
|
|
1460
|
+
* adds dynamo metadata settings to any mongoose schema building settings object
|
|
1461
|
+
* @param properties properties to update
|
|
1462
|
+
* @returns updated properties
|
|
1463
|
+
*/
|
|
1464
|
+
private addMetadataToProperties(properties: DyFM_DataProperties<T>): DyFM_DataProperties<T> {
|
|
1465
|
+
// TOD: ezek a kikommentelt "required: true"-k kellenek, csak félő, hogy gondokat okoznak a
|
|
1466
|
+
// jelenlegi rendszerekben, ezért akkor kell majd visszarakni, ha lesz tesztelői ÉS fejlesztői kapacitás rá
|
|
1467
|
+
if (!properties.__created) {
|
|
1468
|
+
properties.__created = {
|
|
1469
|
+
key: '__created', type: DyFM_BasicProperty_Type.date/* , required: true */,
|
|
1470
|
+
};
|
|
1471
|
+
}
|
|
1472
|
+
|
|
1473
|
+
if (!properties.__createdBy) {
|
|
1474
|
+
properties.__createdBy = {
|
|
1475
|
+
key: '__createdBy', type: DyFM_BasicProperty_Type.string/* , required: true */,
|
|
1476
|
+
};
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1479
|
+
if (!properties.__lastModified) {
|
|
1480
|
+
properties.__lastModified = {
|
|
1481
|
+
key: '__lastModified', type: DyFM_BasicProperty_Type.date/* , required: true */,
|
|
1482
|
+
};
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
if (!properties.__lastModifiedBy) {
|
|
1486
|
+
properties.__lastModifiedBy = {
|
|
1487
|
+
key: '__lastModifiedBy', type: DyFM_BasicProperty_Type.string/* , required: true */,
|
|
1488
|
+
};
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1491
|
+
if (!properties._deleted) {
|
|
1492
|
+
properties._deleted = {
|
|
1493
|
+
key: '_deleted', type: DyFM_BasicProperty_Type.date,
|
|
1494
|
+
};
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
if (!properties._deletedBy) {
|
|
1498
|
+
properties._deletedBy = {
|
|
1499
|
+
key: '_deletedBy', type: DyFM_BasicProperty_Type.string,
|
|
1500
|
+
};
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
if (!properties._archived) {
|
|
1504
|
+
properties._archived = {
|
|
1505
|
+
key: '_archived', type: DyFM_BasicProperty_Type.date,
|
|
1506
|
+
};
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
return properties;
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1512
|
+
/* private addArchiveMetadataToSchema(schema: any): any {
|
|
1513
|
+
schema._originalId = { type: String, required: true, index: true, unique: true };
|
|
1514
|
+
schema._archived = { type: Date, required: true };
|
|
1515
|
+
|
|
1516
|
+
return schema;
|
|
1517
|
+
} */
|
|
1518
|
+
|
|
1519
|
+
private addArchiveMetadataToProperties(
|
|
1520
|
+
properties: DyFM_DataProperties<T>
|
|
1521
|
+
): DyFM_DataProperties<T> {
|
|
1522
|
+
if (!properties._originalId) {
|
|
1523
|
+
properties._originalId = {
|
|
1524
|
+
key: '_originalId', type: DyFM_BasicProperty_Type.string,
|
|
1525
|
+
required: true, index: true, unique: true,
|
|
1526
|
+
};
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1529
|
+
if (!properties._archived) {
|
|
1530
|
+
properties._archived = {
|
|
1531
|
+
key: '_archived', type: DyFM_BasicProperty_Type.date,
|
|
1532
|
+
required: true,
|
|
1533
|
+
};
|
|
1534
|
+
} else if (properties._archived.required === undefined) {
|
|
1535
|
+
properties._archived.required = true;
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
return properties;
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1541
|
+
/**
|
|
1542
|
+
* sets depDataKey
|
|
1543
|
+
*/
|
|
1544
|
+
private lookForDependencyDataSettings(): void {
|
|
1545
|
+
const dependencyParams: DyFM_DataProperty_Params<any, T>[] =
|
|
1546
|
+
Object.values(this.dataParams.properties).filter(
|
|
1547
|
+
(modelParams: DyFM_DataProperty_Params<any, T>): boolean =>
|
|
1548
|
+
Boolean(modelParams.dependencyDataName)
|
|
1549
|
+
);
|
|
1550
|
+
|
|
1551
|
+
if (dependencyParams) {
|
|
1552
|
+
this.depKeys.push(...dependencyParams.map(
|
|
1553
|
+
(dependencyParam: DyFM_DataProperty_Params<any, T>): string => dependencyParam.key
|
|
1554
|
+
));
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
private async deleteThrowMethod(data: any, issuer?: string): Promise<void> {
|
|
1559
|
+
throw new DyFM_Error({
|
|
1560
|
+
error: new Error(`Forbidden to delete any data! (${this.dataParams.dataName})`),
|
|
1561
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-CDAD`,
|
|
1562
|
+
additionalContent: { dataParams: this.dataParams, data: data },
|
|
1563
|
+
issuer: issuer,
|
|
1564
|
+
});
|
|
1565
|
+
};
|
|
1566
|
+
|
|
1567
|
+
private async modifyThrowMethod(data: any, issuer?: string): Promise<void> {
|
|
1568
|
+
throw new DyFM_Error({
|
|
1569
|
+
error: new Error(`Forbidden to modify any data! (${this.dataParams.dataName})`),
|
|
1570
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-DBS-CDAD`,
|
|
1571
|
+
additionalContent: { dataParams: this.dataParams, data: data },
|
|
1572
|
+
issuer: issuer,
|
|
1573
|
+
});
|
|
1574
|
+
}
|
|
1575
|
+
}
|