@lenne.tech/nest-server 10.2.6 → 10.2.8
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/dist/config.env.js +75 -75
- package/dist/config.env.js.map +1 -1
- package/dist/core/common/args/filter.args.js +1 -1
- package/dist/core/common/args/filter.args.js.map +1 -1
- package/dist/core/common/args/pagination.args.js.map +1 -1
- package/dist/core/common/decorators/current-user.decorator.js.map +1 -1
- package/dist/core/common/decorators/graphql-populate.decorator.js.map +1 -1
- package/dist/core/common/decorators/graphql-service-options.decorator.js.map +1 -1
- package/dist/core/common/decorators/restricted.decorator.d.ts +4 -4
- package/dist/core/common/decorators/restricted.decorator.js +2 -2
- package/dist/core/common/decorators/restricted.decorator.js.map +1 -1
- package/dist/core/common/enums/comparison-operator.enum.js +1 -1
- package/dist/core/common/enums/comparison-operator.enum.js.map +1 -1
- package/dist/core/common/enums/logical-operator.enum.js +1 -1
- package/dist/core/common/enums/logical-operator.enum.js.map +1 -1
- package/dist/core/common/enums/role.enum.d.ts +3 -3
- package/dist/core/common/enums/role.enum.js +2 -2
- package/dist/core/common/enums/role.enum.js.map +1 -1
- package/dist/core/common/enums/sort-order.emum.js +1 -1
- package/dist/core/common/enums/sort-order.emum.js.map +1 -1
- package/dist/core/common/filters/http-exception-log.filter.js.map +1 -1
- package/dist/core/common/helpers/config.helper.js.map +1 -1
- package/dist/core/common/helpers/context.helper.js +1 -1
- package/dist/core/common/helpers/context.helper.js.map +1 -1
- package/dist/core/common/helpers/db.helper.d.ts +28 -4
- package/dist/core/common/helpers/db.helper.js +4 -4
- package/dist/core/common/helpers/db.helper.js.map +1 -1
- package/dist/core/common/helpers/decorator.helper.d.ts +24 -0
- package/dist/core/common/helpers/decorator.helper.js.map +1 -1
- package/dist/core/common/helpers/file.helper.js +1 -1
- package/dist/core/common/helpers/file.helper.js.map +1 -1
- package/dist/core/common/helpers/filter.helper.d.ts +26 -2
- package/dist/core/common/helpers/filter.helper.js +3 -3
- package/dist/core/common/helpers/filter.helper.js.map +1 -1
- package/dist/core/common/helpers/graphql.helper.d.ts +2 -2
- package/dist/core/common/helpers/graphql.helper.js +1 -1
- package/dist/core/common/helpers/graphql.helper.js.map +1 -1
- package/dist/core/common/helpers/input.helper.d.ts +3 -3
- package/dist/core/common/helpers/input.helper.js +5 -5
- package/dist/core/common/helpers/input.helper.js.map +1 -1
- package/dist/core/common/helpers/model.helper.d.ts +2 -2
- package/dist/core/common/helpers/model.helper.js +3 -3
- package/dist/core/common/helpers/model.helper.js.map +1 -1
- package/dist/core/common/helpers/service.helper.d.ts +6 -6
- package/dist/core/common/helpers/service.helper.js +5 -5
- package/dist/core/common/helpers/service.helper.js.map +1 -1
- package/dist/core/common/helpers/table.helper.d.ts +9 -0
- package/dist/core/common/helpers/table.helper.js +28 -0
- package/dist/core/common/helpers/table.helper.js.map +1 -0
- package/dist/core/common/inputs/combined-filter.input.js.map +1 -1
- package/dist/core/common/inputs/filter.input.js.map +1 -1
- package/dist/core/common/inputs/single-filter.input.js.map +1 -1
- package/dist/core/common/inputs/sort.input.js.map +1 -1
- package/dist/core/common/interceptors/check-response.interceptor.js.map +1 -1
- package/dist/core/common/interceptors/check-security.interceptor.js.map +1 -1
- package/dist/core/common/interfaces/core-persistence-model.interface.d.ts +3 -3
- package/dist/core/common/interfaces/mailjet-options.interface.d.ts +1 -1
- package/dist/core/common/interfaces/prepare-input-options.interface.d.ts +1 -1
- package/dist/core/common/interfaces/server-options.interface.d.ts +15 -7
- package/dist/core/common/interfaces/service-options.interface.d.ts +31 -5
- package/dist/core/common/models/core-model.model.js.map +1 -1
- package/dist/core/common/models/core-persistence.model.d.ts +24 -0
- package/dist/core/common/models/core-persistence.model.js.map +1 -1
- package/dist/core/common/pipes/check-input.pipe.js.map +1 -1
- package/dist/core/common/pipes/map-and-validate.pipe.js.map +1 -1
- package/dist/core/common/plugins/complexity.plugin.js +4 -4
- package/dist/core/common/plugins/complexity.plugin.js.map +1 -1
- package/dist/core/common/plugins/mongoose-id.plugin.js.map +1 -1
- package/dist/core/common/scalars/any.scalar.js.map +1 -1
- package/dist/core/common/scalars/date-timestamp.scalar.js.map +1 -1
- package/dist/core/common/scalars/date.scalar.js.map +1 -1
- package/dist/core/common/scalars/json.scalar.js.map +1 -1
- package/dist/core/common/services/brevo.service.d.ts +10 -0
- package/dist/core/common/services/brevo.service.js +75 -0
- package/dist/core/common/services/brevo.service.js.map +1 -0
- package/dist/core/common/services/config.service.js +1 -1
- package/dist/core/common/services/config.service.js.map +1 -1
- package/dist/core/common/services/core-cron-jobs.service.d.ts +2 -2
- package/dist/core/common/services/core-cron-jobs.service.js.map +1 -1
- package/dist/core/common/services/crud.service.d.ts +63 -32
- package/dist/core/common/services/crud.service.js +59 -21
- package/dist/core/common/services/crud.service.js.map +1 -1
- package/dist/core/common/services/email.service.js +5 -5
- package/dist/core/common/services/email.service.js.map +1 -1
- package/dist/core/common/services/mailjet.service.d.ts +4 -4
- package/dist/core/common/services/mailjet.service.js +8 -8
- package/dist/core/common/services/mailjet.service.js.map +1 -1
- package/dist/core/common/services/model-doc.service.d.ts +24 -0
- package/dist/core/common/services/model-doc.service.js +1 -1
- package/dist/core/common/services/model-doc.service.js.map +1 -1
- package/dist/core/common/services/module.service.d.ts +28 -4
- package/dist/core/common/services/module.service.js +23 -7
- package/dist/core/common/services/module.service.js.map +1 -1
- package/dist/core/common/services/template.service.js +3 -3
- package/dist/core/common/services/template.service.js.map +1 -1
- package/dist/core/common/types/core-model-constructor.type.d.ts +1 -1
- package/dist/core/common/types/falsy.type.d.ts +1 -1
- package/dist/core/common/types/field-selection.type.d.ts +25 -1
- package/dist/core/common/types/ids.type.d.ts +31 -7
- package/dist/core/common/types/maybe-promise.type.d.ts +1 -1
- package/dist/core/common/types/plain-input.type.d.ts +1 -1
- package/dist/core/common/types/populate-config.type.d.ts +25 -1
- package/dist/core/common/types/string-or-object-id.type.d.ts +25 -1
- package/dist/core/modules/auth/core-auth.controller.js +1 -1
- package/dist/core/modules/auth/core-auth.controller.js.map +1 -1
- package/dist/core/modules/auth/core-auth.model.js.map +1 -1
- package/dist/core/modules/auth/core-auth.module.d.ts +5 -5
- package/dist/core/modules/auth/core-auth.module.js +5 -5
- package/dist/core/modules/auth/core-auth.module.js.map +1 -1
- package/dist/core/modules/auth/core-auth.resolver.js +1 -1
- package/dist/core/modules/auth/core-auth.resolver.js.map +1 -1
- package/dist/core/modules/auth/guards/auth.guard.d.ts +1 -1
- package/dist/core/modules/auth/guards/auth.guard.js +1 -1
- package/dist/core/modules/auth/guards/auth.guard.js.map +1 -1
- package/dist/core/modules/auth/guards/refresh-token.guard.js.map +1 -1
- package/dist/core/modules/auth/guards/roles.guard.js.map +1 -1
- package/dist/core/modules/auth/inputs/core-auth-sign-in.input.js.map +1 -1
- package/dist/core/modules/auth/inputs/core-auth-sign-up.input.js.map +1 -1
- package/dist/core/modules/auth/interfaces/core-auth-user.interface.d.ts +1 -1
- package/dist/core/modules/auth/interfaces/core-token-data.interface.d.ts +1 -1
- package/dist/core/modules/auth/interfaces/jwt-payload.interface.d.ts +1 -1
- package/dist/core/modules/auth/services/core-auth.service.d.ts +1 -1
- package/dist/core/modules/auth/services/core-auth.service.js +10 -10
- package/dist/core/modules/auth/services/core-auth.service.js.map +1 -1
- package/dist/core/modules/auth/strategies/jwt-refresh.strategy.js +1 -1
- package/dist/core/modules/auth/strategies/jwt-refresh.strategy.js.map +1 -1
- package/dist/core/modules/auth/strategies/jwt.strategy.js.map +1 -1
- package/dist/core/modules/auth/tokens.decorator.js +1 -1
- package/dist/core/modules/auth/tokens.decorator.js.map +1 -1
- package/dist/core/modules/file/core-file-info.model.d.ts +24 -0
- package/dist/core/modules/file/core-file-info.model.js +5 -5
- package/dist/core/modules/file/core-file-info.model.js.map +1 -1
- package/dist/core/modules/file/core-file.controller.js.map +1 -1
- package/dist/core/modules/file/core-file.resolver.js +1 -1
- package/dist/core/modules/file/core-file.resolver.js.map +1 -1
- package/dist/core/modules/file/core-file.service.d.ts +30 -6
- package/dist/core/modules/file/core-file.service.js +3 -3
- package/dist/core/modules/file/core-file.service.js.map +1 -1
- package/dist/core/modules/file/interfaces/file-service-options.interface.d.ts +1 -1
- package/dist/core/modules/file/interfaces/file-upload.interface.d.ts +2 -2
- package/dist/core/modules/health-check/core-health-check-result.model.js.map +1 -1
- package/dist/core/modules/health-check/core-health-check.controller.js.map +1 -1
- package/dist/core/modules/health-check/core-health-check.module.js +1 -1
- package/dist/core/modules/health-check/core-health-check.module.js.map +1 -1
- package/dist/core/modules/health-check/core-health-check.resolver.js +2 -2
- package/dist/core/modules/health-check/core-health-check.resolver.js.map +1 -1
- package/dist/core/modules/health-check/core-health-check.service.js +1 -1
- package/dist/core/modules/health-check/core-health-check.service.js.map +1 -1
- package/dist/core/modules/user/core-user.model.d.ts +24 -0
- package/dist/core/modules/user/core-user.model.js +1 -1
- package/dist/core/modules/user/core-user.model.js.map +1 -1
- package/dist/core/modules/user/core-user.service.d.ts +25 -1
- package/dist/core/modules/user/core-user.service.js +3 -3
- package/dist/core/modules/user/core-user.service.js.map +1 -1
- package/dist/core/modules/user/inputs/core-user-create.input.js +1 -1
- package/dist/core/modules/user/inputs/core-user-create.input.js.map +1 -1
- package/dist/core/modules/user/inputs/core-user.input.js +1 -1
- package/dist/core/modules/user/inputs/core-user.input.js.map +1 -1
- package/dist/core.module.js +20 -20
- package/dist/core.module.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/main.js +3 -3
- package/dist/main.js.map +1 -1
- package/dist/server/common/models/persistence.model.d.ts +24 -0
- package/dist/server/common/models/persistence.model.js +4 -4
- package/dist/server/common/models/persistence.model.js.map +1 -1
- package/dist/server/common/services/cron-jobs.service.js.map +1 -1
- package/dist/server/modules/auth/auth.controller.js.map +1 -1
- package/dist/server/modules/auth/auth.model.js.map +1 -1
- package/dist/server/modules/auth/auth.module.js +2 -2
- package/dist/server/modules/auth/auth.module.js.map +1 -1
- package/dist/server/modules/auth/auth.resolver.js.map +1 -1
- package/dist/server/modules/auth/auth.service.js +1 -1
- package/dist/server/modules/auth/auth.service.js.map +1 -1
- package/dist/server/modules/auth/inputs/auth-sign-in.input.js.map +1 -1
- package/dist/server/modules/auth/inputs/auth-sign-up.input.js.map +1 -1
- package/dist/server/modules/file/file-info.model.js.map +1 -1
- package/dist/server/modules/file/file.controller.js.map +1 -1
- package/dist/server/modules/file/file.module.js +2 -2
- package/dist/server/modules/file/file.module.js.map +1 -1
- package/dist/server/modules/file/file.resolver.js +5 -5
- package/dist/server/modules/file/file.resolver.js.map +1 -1
- package/dist/server/modules/file/file.service.d.ts +24 -0
- package/dist/server/modules/file/file.service.js.map +1 -1
- package/dist/server/modules/file/multer-config.service.js +2 -2
- package/dist/server/modules/file/multer-config.service.js.map +1 -1
- package/dist/server/modules/user/avatar.controller.js.map +1 -1
- package/dist/server/modules/user/inputs/user-create.input.js.map +1 -1
- package/dist/server/modules/user/inputs/user.input.js.map +1 -1
- package/dist/server/modules/user/outputs/find-and-count-users-result.output.js.map +1 -1
- package/dist/server/modules/user/user.model.js +2 -2
- package/dist/server/modules/user/user.model.js.map +1 -1
- package/dist/server/modules/user/user.module.js +2 -2
- package/dist/server/modules/user/user.module.js.map +1 -1
- package/dist/server/modules/user/user.resolver.d.ts +1 -1
- package/dist/server/modules/user/user.resolver.js +1 -1
- package/dist/server/modules/user/user.resolver.js.map +1 -1
- package/dist/server/modules/user/user.service.d.ts +25 -1
- package/dist/server/modules/user/user.service.js +2 -2
- package/dist/server/modules/user/user.service.js.map +1 -1
- package/dist/server/server.controller.js.map +1 -1
- package/dist/server/server.module.js +2 -2
- package/dist/server/server.module.js.map +1 -1
- package/dist/test/test.helper.d.ts +13 -13
- package/dist/test/test.helper.js +15 -15
- package/dist/test/test.helper.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +35 -34
- package/src/config.env.ts +79 -78
- package/src/core/common/args/filter.args.ts +2 -1
- package/src/core/common/args/pagination.args.ts +1 -0
- package/src/core/common/decorators/current-user.decorator.ts +1 -0
- package/src/core/common/decorators/graphql-populate.decorator.ts +1 -0
- package/src/core/common/decorators/graphql-service-options.decorator.ts +1 -0
- package/src/core/common/decorators/restricted.decorator.ts +7 -5
- package/src/core/common/enums/comparison-operator.enum.ts +1 -1
- package/src/core/common/enums/logical-operator.enum.ts +1 -1
- package/src/core/common/enums/role.enum.ts +6 -6
- package/src/core/common/enums/sort-order.emum.ts +1 -1
- package/src/core/common/helpers/context.helper.ts +1 -1
- package/src/core/common/helpers/db.helper.ts +14 -12
- package/src/core/common/helpers/decorator.helper.ts +1 -0
- package/src/core/common/helpers/file.helper.ts +1 -1
- package/src/core/common/helpers/filter.helper.ts +6 -5
- package/src/core/common/helpers/graphql.helper.ts +7 -6
- package/src/core/common/helpers/input.helper.ts +10 -8
- package/src/core/common/helpers/model.helper.ts +6 -5
- package/src/core/common/helpers/service.helper.ts +13 -11
- package/src/core/common/helpers/table.helper.ts +37 -0
- package/src/core/common/inputs/combined-filter.input.ts +1 -0
- package/src/core/common/inputs/filter.input.ts +1 -0
- package/src/core/common/inputs/single-filter.input.ts +1 -0
- package/src/core/common/inputs/sort.input.ts +1 -0
- package/src/core/common/interceptors/check-response.interceptor.ts +1 -0
- package/src/core/common/interceptors/check-security.interceptor.ts +1 -0
- package/src/core/common/interfaces/core-persistence-model.interface.ts +3 -3
- package/src/core/common/interfaces/cron-job-config-with-time-zone.interface.ts +1 -0
- package/src/core/common/interfaces/cron-job-config-with-utc-offset.interface.ts +1 -0
- package/src/core/common/interfaces/mailjet-options.interface.ts +1 -1
- package/src/core/common/interfaces/prepare-input-options.interface.ts +1 -1
- package/src/core/common/interfaces/server-options.interface.ts +49 -23
- package/src/core/common/interfaces/service-options.interface.ts +31 -16
- package/src/core/common/models/core-persistence.model.ts +1 -0
- package/src/core/common/pipes/check-input.pipe.ts +1 -0
- package/src/core/common/pipes/map-and-validate.pipe.ts +1 -0
- package/src/core/common/plugins/complexity.plugin.ts +5 -4
- package/src/core/common/scalars/date-timestamp.scalar.ts +1 -0
- package/src/core/common/scalars/date.scalar.ts +1 -0
- package/src/core/common/services/brevo.service.ts +93 -0
- package/src/core/common/services/config.service.ts +3 -1
- package/src/core/common/services/core-cron-jobs.service.ts +3 -2
- package/src/core/common/services/crud.service.ts +113 -41
- package/src/core/common/services/email.service.ts +7 -5
- package/src/core/common/services/mailjet.service.ts +14 -13
- package/src/core/common/services/model-doc.service.ts +2 -1
- package/src/core/common/services/module.service.ts +33 -13
- package/src/core/common/services/template.service.ts +5 -3
- package/src/core/common/types/core-model-constructor.type.ts +1 -1
- package/src/core/common/types/falsy.type.ts +1 -1
- package/src/core/common/types/field-selection.type.ts +4 -3
- package/src/core/common/types/ids.type.ts +3 -3
- package/src/core/common/types/maybe-promise.type.ts +1 -1
- package/src/core/common/types/plain-input.type.ts +1 -1
- package/src/core/common/types/populate-config.type.ts +1 -1
- package/src/core/common/types/string-or-object-id.type.ts +1 -1
- package/src/core/modules/auth/core-auth.controller.ts +2 -1
- package/src/core/modules/auth/core-auth.model.ts +1 -0
- package/src/core/modules/auth/core-auth.module.ts +8 -7
- package/src/core/modules/auth/core-auth.resolver.ts +2 -1
- package/src/core/modules/auth/guards/auth.guard.ts +4 -2
- package/src/core/modules/auth/guards/refresh-token.guard.ts +1 -0
- package/src/core/modules/auth/guards/roles.guard.ts +1 -0
- package/src/core/modules/auth/inputs/core-auth-sign-in.input.ts +1 -0
- package/src/core/modules/auth/inputs/core-auth-sign-up.input.ts +1 -0
- package/src/core/modules/auth/interfaces/core-auth-user.interface.ts +4 -4
- package/src/core/modules/auth/interfaces/core-token-data.interface.ts +4 -4
- package/src/core/modules/auth/interfaces/jwt-payload.interface.ts +1 -1
- package/src/core/modules/auth/services/core-auth.service.ts +13 -11
- package/src/core/modules/auth/strategies/jwt-refresh.strategy.ts +3 -2
- package/src/core/modules/auth/strategies/jwt.strategy.ts +3 -2
- package/src/core/modules/auth/tokens.decorator.ts +4 -3
- package/src/core/modules/file/core-file-info.model.ts +6 -5
- package/src/core/modules/file/core-file.controller.ts +1 -0
- package/src/core/modules/file/core-file.resolver.ts +2 -1
- package/src/core/modules/file/core-file.service.ts +9 -8
- package/src/core/modules/file/interfaces/file-service-options.interface.ts +1 -1
- package/src/core/modules/file/interfaces/file-upload.interface.ts +2 -2
- package/src/core/modules/health-check/core-health-check-result.model.ts +1 -0
- package/src/core/modules/health-check/core-health-check.controller.ts +1 -0
- package/src/core/modules/health-check/core-health-check.module.ts +2 -1
- package/src/core/modules/health-check/core-health-check.resolver.ts +3 -2
- package/src/core/modules/health-check/core-health-check.service.ts +2 -1
- package/src/core/modules/user/core-user.model.ts +2 -1
- package/src/core/modules/user/core-user.service.ts +6 -4
- package/src/core/modules/user/inputs/core-user-create.input.ts +2 -1
- package/src/core/modules/user/inputs/core-user.input.ts +2 -1
- package/src/core.module.ts +24 -22
- package/src/index.ts +2 -0
- package/src/main.ts +5 -3
- package/src/server/common/models/persistence.model.ts +7 -5
- package/src/server/common/services/cron-jobs.service.ts +1 -0
- package/src/server/modules/auth/auth.controller.ts +1 -0
- package/src/server/modules/auth/auth.model.ts +1 -0
- package/src/server/modules/auth/auth.module.ts +3 -2
- package/src/server/modules/auth/auth.resolver.ts +1 -0
- package/src/server/modules/auth/auth.service.ts +2 -1
- package/src/server/modules/auth/inputs/auth-sign-in.input.ts +1 -0
- package/src/server/modules/auth/inputs/auth-sign-up.input.ts +1 -0
- package/src/server/modules/file/file-info.model.ts +1 -0
- package/src/server/modules/file/file.controller.ts +1 -0
- package/src/server/modules/file/file.module.ts +3 -2
- package/src/server/modules/file/file.resolver.ts +7 -5
- package/src/server/modules/file/file.service.ts +1 -0
- package/src/server/modules/file/multer-config.service.ts +3 -2
- package/src/server/modules/user/avatar.controller.ts +1 -0
- package/src/server/modules/user/inputs/user-create.input.ts +1 -0
- package/src/server/modules/user/inputs/user.input.ts +1 -0
- package/src/server/modules/user/outputs/find-and-count-users-result.output.ts +1 -0
- package/src/server/modules/user/user.model.ts +3 -2
- package/src/server/modules/user/user.module.ts +3 -2
- package/src/server/modules/user/user.resolver.ts +2 -1
- package/src/server/modules/user/user.service.ts +5 -3
- package/src/server/server.controller.ts +1 -0
- package/src/server/server.module.ts +7 -6
- package/src/test/test.helper.ts +28 -26
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NotFoundException } from '@nestjs/common';
|
|
2
|
-
import { Document, FilterQuery, PipelineStage, Query, QueryOptions } from 'mongoose';
|
|
2
|
+
import { AggregateOptions, Document, FilterQuery, Model as MongooseModel, PipelineStage, Query, QueryOptions } from 'mongoose';
|
|
3
|
+
|
|
3
4
|
import { FilterArgs } from '../args/filter.args';
|
|
4
5
|
import { getStringIds } from '../helpers/db.helper';
|
|
5
6
|
import { convertFilterArgsToQuery } from '../helpers/filter.helper';
|
|
@@ -15,6 +16,50 @@ export abstract class CrudService<
|
|
|
15
16
|
CreateInput = any,
|
|
16
17
|
UpdateInput = any,
|
|
17
18
|
> extends ModuleService<Model> {
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Aggregate
|
|
22
|
+
* @param serviceOptions.aggregateOptions Aggregate options, see https://www.mongodb.com/docs/manual/core/aggregation-pipeline/
|
|
23
|
+
* @param serviceOptions.collation Collation, see https://www.mongodb.com/docs/manual/reference/collation/
|
|
24
|
+
* @param serviceOptions.outputPath Output path of items which should be prepared, e.g. 'items'
|
|
25
|
+
*/
|
|
26
|
+
async aggregate<T = any>(
|
|
27
|
+
pipeline: PipelineStage[],
|
|
28
|
+
serviceOptions?: ServiceOptions & { aggregateOptions?: AggregateOptions },
|
|
29
|
+
): Promise<T> {
|
|
30
|
+
return this.process(
|
|
31
|
+
async () => {
|
|
32
|
+
const aggregateOptions = serviceOptions?.aggregateOptions || {};
|
|
33
|
+
const collation = serviceOptions?.collation || ConfigService.get('mongoose.collation');
|
|
34
|
+
if (collation && !aggregateOptions.collation) {
|
|
35
|
+
aggregateOptions.collation = collation;
|
|
36
|
+
}
|
|
37
|
+
return this.mainDbModel.aggregate(pipeline, aggregateOptions).exec();
|
|
38
|
+
},
|
|
39
|
+
{ serviceOptions },
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Aggregate without checks or restrictions
|
|
45
|
+
* Warning: Disables the handling of rights and restrictions!
|
|
46
|
+
*/
|
|
47
|
+
async aggregateForce<T = any>(pipeline: PipelineStage[], serviceOptions: ServiceOptions = {}): Promise<T> {
|
|
48
|
+
serviceOptions = serviceOptions || {};
|
|
49
|
+
serviceOptions.force = true;
|
|
50
|
+
return this.aggregate(pipeline, serviceOptions);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Aggregate without checks, restrictions or preparations
|
|
55
|
+
* Warning: Disables the handling of rights and restrictions! The raw data may contain secrets (such as passwords).
|
|
56
|
+
*/
|
|
57
|
+
async aggregateRaw<T = any>(pipeline: PipelineStage[], serviceOptions: ServiceOptions = {}): Promise<T> {
|
|
58
|
+
serviceOptions = serviceOptions || {};
|
|
59
|
+
serviceOptions.raw = true;
|
|
60
|
+
return this.aggregateForce(pipeline, serviceOptions);
|
|
61
|
+
}
|
|
62
|
+
|
|
18
63
|
/**
|
|
19
64
|
* Create item
|
|
20
65
|
*/
|
|
@@ -45,16 +90,26 @@ export abstract class CrudService<
|
|
|
45
90
|
*/
|
|
46
91
|
async createRaw(input: PlainObject<CreateInput>, serviceOptions: ServiceOptions = {}): Promise<Model> {
|
|
47
92
|
serviceOptions = serviceOptions || {};
|
|
48
|
-
serviceOptions.
|
|
49
|
-
serviceOptions.prepareOutput = null;
|
|
93
|
+
serviceOptions.raw = true;
|
|
50
94
|
return this.createForce(input, serviceOptions);
|
|
51
95
|
}
|
|
52
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Get distinct values of a property
|
|
99
|
+
*/
|
|
100
|
+
distinct(property: string): Promise<string[]> {
|
|
101
|
+
return this.mainDbModel.distinct(property);
|
|
102
|
+
}
|
|
103
|
+
|
|
53
104
|
/**
|
|
54
105
|
* Get item by ID
|
|
55
106
|
*/
|
|
56
107
|
async get(id: string, serviceOptions?: ServiceOptions): Promise<Model> {
|
|
57
|
-
const
|
|
108
|
+
const query = this.mainDbModel.findById(id);
|
|
109
|
+
if (serviceOptions?.select) {
|
|
110
|
+
query.select(serviceOptions.select);
|
|
111
|
+
}
|
|
112
|
+
const dbObject = await query.exec();
|
|
58
113
|
if (!dbObject) {
|
|
59
114
|
throw new NotFoundException(`No ${this.mainModelConstructor.name} found with ID: ${id}`);
|
|
60
115
|
}
|
|
@@ -77,8 +132,7 @@ export abstract class CrudService<
|
|
|
77
132
|
*/
|
|
78
133
|
async getRaw(id: string, serviceOptions: ServiceOptions = {}): Promise<Model> {
|
|
79
134
|
serviceOptions = serviceOptions || {};
|
|
80
|
-
serviceOptions.
|
|
81
|
-
serviceOptions.prepareOutput = null;
|
|
135
|
+
serviceOptions.raw = true;
|
|
82
136
|
return this.getForce(id, serviceOptions);
|
|
83
137
|
}
|
|
84
138
|
|
|
@@ -86,7 +140,7 @@ export abstract class CrudService<
|
|
|
86
140
|
* Get items via filter
|
|
87
141
|
*/
|
|
88
142
|
async find(
|
|
89
|
-
filter?:
|
|
143
|
+
filter?: { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number } | FilterArgs,
|
|
90
144
|
serviceOptions?: ServiceOptions,
|
|
91
145
|
): Promise<Model[]> {
|
|
92
146
|
// If filter is not instance of FilterArgs a simple form with filterQuery and queryOptions is set
|
|
@@ -116,6 +170,9 @@ export abstract class CrudService<
|
|
|
116
170
|
if (collation) {
|
|
117
171
|
find = find.collation(collation);
|
|
118
172
|
}
|
|
173
|
+
if (serviceOptions?.select) {
|
|
174
|
+
find = find.select(serviceOptions.select);
|
|
175
|
+
}
|
|
119
176
|
return find.exec();
|
|
120
177
|
},
|
|
121
178
|
{ input: filter, serviceOptions },
|
|
@@ -127,7 +184,7 @@ export abstract class CrudService<
|
|
|
127
184
|
* Warning: Disables the handling of rights and restrictions!
|
|
128
185
|
*/
|
|
129
186
|
async findForce(
|
|
130
|
-
filter?:
|
|
187
|
+
filter?: { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number } | FilterArgs,
|
|
131
188
|
serviceOptions: ServiceOptions = {},
|
|
132
189
|
): Promise<Model[]> {
|
|
133
190
|
serviceOptions = serviceOptions || {};
|
|
@@ -140,12 +197,11 @@ export abstract class CrudService<
|
|
|
140
197
|
* Warning: Disables the handling of rights and restrictions! The raw data may contain secrets (such as passwords).
|
|
141
198
|
*/
|
|
142
199
|
async findRaw(
|
|
143
|
-
filter?:
|
|
200
|
+
filter?: { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number } | FilterArgs,
|
|
144
201
|
serviceOptions: ServiceOptions = {},
|
|
145
202
|
): Promise<Model[]> {
|
|
146
203
|
serviceOptions = serviceOptions || {};
|
|
147
|
-
serviceOptions.
|
|
148
|
-
serviceOptions.prepareOutput = null;
|
|
204
|
+
serviceOptions.raw = true;
|
|
149
205
|
return this.findForce(filter, serviceOptions);
|
|
150
206
|
}
|
|
151
207
|
|
|
@@ -153,7 +209,7 @@ export abstract class CrudService<
|
|
|
153
209
|
* Get items and total count via filter
|
|
154
210
|
*/
|
|
155
211
|
async findAndCount(
|
|
156
|
-
filter?:
|
|
212
|
+
filter?: { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number } | FilterArgs,
|
|
157
213
|
serviceOptions?: ServiceOptions,
|
|
158
214
|
): Promise<{ items: Model[]; totalCount: number }> {
|
|
159
215
|
// If filter is not instance of FilterArgs a simple form with filterQuery and queryOptions is set
|
|
@@ -232,11 +288,10 @@ export abstract class CrudService<
|
|
|
232
288
|
* Warning: Disables the handling of rights and restrictions!
|
|
233
289
|
*/
|
|
234
290
|
async findAndCountForce(
|
|
235
|
-
filter?:
|
|
291
|
+
filter?: { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number } | FilterArgs,
|
|
236
292
|
serviceOptions: ServiceOptions = {},
|
|
237
293
|
): Promise<{ items: Model[]; totalCount: number }> {
|
|
238
|
-
serviceOptions =
|
|
239
|
-
serviceOptions.force = true;
|
|
294
|
+
serviceOptions.raw = true;
|
|
240
295
|
return this.findAndCount(filter, serviceOptions);
|
|
241
296
|
}
|
|
242
297
|
|
|
@@ -245,12 +300,11 @@ export abstract class CrudService<
|
|
|
245
300
|
* Warning: Disables the handling of rights and restrictions! The raw data may contain secrets (such as passwords).
|
|
246
301
|
*/
|
|
247
302
|
async findAndCountRaw(
|
|
248
|
-
filter?:
|
|
303
|
+
filter?: { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number } | FilterArgs,
|
|
249
304
|
serviceOptions: ServiceOptions = {},
|
|
250
305
|
): Promise<{ items: Model[]; totalCount: number }> {
|
|
251
306
|
serviceOptions = serviceOptions || {};
|
|
252
|
-
serviceOptions.
|
|
253
|
-
serviceOptions.prepareOutput = null;
|
|
307
|
+
serviceOptions.raw = true;
|
|
254
308
|
return this.findAndCountForce(filter, serviceOptions);
|
|
255
309
|
}
|
|
256
310
|
|
|
@@ -258,7 +312,7 @@ export abstract class CrudService<
|
|
|
258
312
|
* Find and update
|
|
259
313
|
*/
|
|
260
314
|
async findAndUpdate(
|
|
261
|
-
filter:
|
|
315
|
+
filter: { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number } | FilterArgs,
|
|
262
316
|
update: PlainObject<UpdateInput>,
|
|
263
317
|
serviceOptions?: ServiceOptions,
|
|
264
318
|
): Promise<Model[]> {
|
|
@@ -287,7 +341,7 @@ export abstract class CrudService<
|
|
|
287
341
|
* Warning: Disables the handling of rights and restrictions!
|
|
288
342
|
*/
|
|
289
343
|
async findAndUpdateForce(
|
|
290
|
-
filter:
|
|
344
|
+
filter: { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number } | FilterArgs,
|
|
291
345
|
update: PlainObject<UpdateInput>,
|
|
292
346
|
serviceOptions: ServiceOptions = {},
|
|
293
347
|
): Promise<Model[]> {
|
|
@@ -301,13 +355,12 @@ export abstract class CrudService<
|
|
|
301
355
|
* Warning: Disables the handling of rights and restrictions! The raw data may contain secrets (such as passwords).
|
|
302
356
|
*/
|
|
303
357
|
async findAndUpdateRaw(
|
|
304
|
-
filter:
|
|
358
|
+
filter: { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number } | FilterArgs,
|
|
305
359
|
update: PlainObject<UpdateInput>,
|
|
306
360
|
serviceOptions: ServiceOptions = {},
|
|
307
361
|
): Promise<Model[]> {
|
|
308
362
|
serviceOptions = serviceOptions || {};
|
|
309
|
-
serviceOptions.
|
|
310
|
-
serviceOptions.prepareOutput = null;
|
|
363
|
+
serviceOptions.raw = true;
|
|
311
364
|
return this.findAndUpdateForce(filter, update, serviceOptions);
|
|
312
365
|
}
|
|
313
366
|
|
|
@@ -315,7 +368,7 @@ export abstract class CrudService<
|
|
|
315
368
|
* Find one item via filter
|
|
316
369
|
*/
|
|
317
370
|
async findOne(
|
|
318
|
-
filter?:
|
|
371
|
+
filter?: { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions } | FilterArgs,
|
|
319
372
|
serviceOptions?: ServiceOptions,
|
|
320
373
|
): Promise<Model> {
|
|
321
374
|
// If filter is not instance of FilterArgs a simple form with filterQuery and queryOptions is set
|
|
@@ -341,6 +394,9 @@ export abstract class CrudService<
|
|
|
341
394
|
if (collation) {
|
|
342
395
|
find = find.collation(collation);
|
|
343
396
|
}
|
|
397
|
+
if (serviceOptions?.select) {
|
|
398
|
+
find = find.select(serviceOptions.select);
|
|
399
|
+
}
|
|
344
400
|
return find.exec();
|
|
345
401
|
},
|
|
346
402
|
{ input: filter, serviceOptions },
|
|
@@ -352,7 +408,7 @@ export abstract class CrudService<
|
|
|
352
408
|
* Warning: Disables the handling of rights and restrictions!
|
|
353
409
|
*/
|
|
354
410
|
async findOneForce(
|
|
355
|
-
filter?:
|
|
411
|
+
filter?: { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number } | FilterArgs,
|
|
356
412
|
serviceOptions: ServiceOptions = {},
|
|
357
413
|
): Promise<Model> {
|
|
358
414
|
serviceOptions = serviceOptions || {};
|
|
@@ -365,15 +421,22 @@ export abstract class CrudService<
|
|
|
365
421
|
* Warning: Disables the handling of rights and restrictions! The raw data may contain secrets (such as passwords).
|
|
366
422
|
*/
|
|
367
423
|
async findOneRaw(
|
|
368
|
-
filter?:
|
|
424
|
+
filter?: { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions; samples?: number } | FilterArgs,
|
|
369
425
|
serviceOptions: ServiceOptions = {},
|
|
370
426
|
): Promise<Model> {
|
|
371
427
|
serviceOptions = serviceOptions || {};
|
|
372
|
-
serviceOptions.
|
|
373
|
-
serviceOptions.prepareOutput = null;
|
|
428
|
+
serviceOptions.raw = true;
|
|
374
429
|
return this.findOneForce(filter, serviceOptions);
|
|
375
430
|
}
|
|
376
431
|
|
|
432
|
+
/**
|
|
433
|
+
* Get service model to process queries directly
|
|
434
|
+
* See https://mongoosejs.com/docs/api/model.html
|
|
435
|
+
*/
|
|
436
|
+
getModel(): MongooseModel<Model & Document> {
|
|
437
|
+
return this.mainDbModel;
|
|
438
|
+
}
|
|
439
|
+
|
|
377
440
|
/**
|
|
378
441
|
* CRUD alias for get
|
|
379
442
|
*/
|
|
@@ -383,7 +446,7 @@ export abstract class CrudService<
|
|
|
383
446
|
* CRUD alias for find
|
|
384
447
|
*/
|
|
385
448
|
async read(
|
|
386
|
-
filter:
|
|
449
|
+
filter: { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions } | FilterArgs,
|
|
387
450
|
serviceOptions?: ServiceOptions
|
|
388
451
|
): Promise<Model[]>;
|
|
389
452
|
|
|
@@ -391,7 +454,7 @@ export abstract class CrudService<
|
|
|
391
454
|
* CRUD alias for get or find
|
|
392
455
|
*/
|
|
393
456
|
async read(
|
|
394
|
-
input:
|
|
457
|
+
input: { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions } | FilterArgs | string,
|
|
395
458
|
serviceOptions?: ServiceOptions,
|
|
396
459
|
): Promise<Model | Model[]> {
|
|
397
460
|
if (typeof input === 'string') {
|
|
@@ -412,7 +475,7 @@ export abstract class CrudService<
|
|
|
412
475
|
* Warning: Disables the handling of rights and restrictions!
|
|
413
476
|
*/
|
|
414
477
|
async readForce(
|
|
415
|
-
filter:
|
|
478
|
+
filter: { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions } | FilterArgs,
|
|
416
479
|
serviceOptions?: ServiceOptions
|
|
417
480
|
): Promise<Model[]>;
|
|
418
481
|
|
|
@@ -421,7 +484,7 @@ export abstract class CrudService<
|
|
|
421
484
|
* Warning: Disables the handling of rights and restrictions!
|
|
422
485
|
*/
|
|
423
486
|
async readForce(
|
|
424
|
-
input:
|
|
487
|
+
input: { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions } | FilterArgs | string,
|
|
425
488
|
serviceOptions?: ServiceOptions,
|
|
426
489
|
): Promise<Model | Model[]> {
|
|
427
490
|
if (typeof input === 'string') {
|
|
@@ -442,7 +505,7 @@ export abstract class CrudService<
|
|
|
442
505
|
* Warning: Disables the handling of rights and restrictions! The raw data may contain secrets (such as passwords).
|
|
443
506
|
*/
|
|
444
507
|
async readRaw(
|
|
445
|
-
filter:
|
|
508
|
+
filter: { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions } | FilterArgs,
|
|
446
509
|
serviceOptions?: ServiceOptions
|
|
447
510
|
): Promise<Model[]>;
|
|
448
511
|
|
|
@@ -451,7 +514,7 @@ export abstract class CrudService<
|
|
|
451
514
|
* Warning: Disables the handling of rights and restrictions! The raw data may contain secrets (such as passwords).
|
|
452
515
|
*/
|
|
453
516
|
async readRaw(
|
|
454
|
-
input:
|
|
517
|
+
input: { filterQuery?: FilterQuery<any>; queryOptions?: QueryOptions } | FilterArgs | string,
|
|
455
518
|
serviceOptions?: ServiceOptions,
|
|
456
519
|
): Promise<Model | Model[]> {
|
|
457
520
|
if (typeof input === 'string') {
|
|
@@ -473,7 +536,11 @@ export abstract class CrudService<
|
|
|
473
536
|
async (data) => {
|
|
474
537
|
const currentUserId = serviceOptions?.currentUser?.id;
|
|
475
538
|
const merged = mergePlain(dbObject, data.input, { updatedBy: currentUserId });
|
|
476
|
-
|
|
539
|
+
const query = this.mainDbModel.findByIdAndUpdate(id, merged, { returnDocument: 'after' });
|
|
540
|
+
if (serviceOptions?.select) {
|
|
541
|
+
query.select(serviceOptions.select);
|
|
542
|
+
}
|
|
543
|
+
return await query.exec();
|
|
477
544
|
},
|
|
478
545
|
{ dbObject, input, serviceOptions },
|
|
479
546
|
);
|
|
@@ -495,8 +562,7 @@ export abstract class CrudService<
|
|
|
495
562
|
*/
|
|
496
563
|
async updateRaw(id: string, input: PlainObject<UpdateInput>, serviceOptions?: ServiceOptions): Promise<Model> {
|
|
497
564
|
serviceOptions = serviceOptions || {};
|
|
498
|
-
serviceOptions.
|
|
499
|
-
serviceOptions.prepareOutput = null;
|
|
565
|
+
serviceOptions.raw = true;
|
|
500
566
|
return this.updateForce(id, input, serviceOptions);
|
|
501
567
|
}
|
|
502
568
|
|
|
@@ -504,7 +570,11 @@ export abstract class CrudService<
|
|
|
504
570
|
* Delete item via ID
|
|
505
571
|
*/
|
|
506
572
|
async delete(id: string, serviceOptions?: ServiceOptions): Promise<Model> {
|
|
507
|
-
const
|
|
573
|
+
const query = this.mainDbModel.findById(id);
|
|
574
|
+
if (serviceOptions?.select) {
|
|
575
|
+
query.select(serviceOptions.select);
|
|
576
|
+
}
|
|
577
|
+
const dbObject = await query.exec();
|
|
508
578
|
if (!dbObject) {
|
|
509
579
|
throw new NotFoundException(`No ${this.mainModelConstructor.name} found with ID: ${id}`);
|
|
510
580
|
}
|
|
@@ -533,8 +603,7 @@ export abstract class CrudService<
|
|
|
533
603
|
*/
|
|
534
604
|
async deleteRaw(id: string, serviceOptions?: ServiceOptions): Promise<Model> {
|
|
535
605
|
serviceOptions = serviceOptions || {};
|
|
536
|
-
serviceOptions.
|
|
537
|
-
serviceOptions.prepareOutput = null;
|
|
606
|
+
serviceOptions.raw = true;
|
|
538
607
|
return this.deleteForce(id, serviceOptions);
|
|
539
608
|
}
|
|
540
609
|
|
|
@@ -546,11 +615,14 @@ export abstract class CrudService<
|
|
|
546
615
|
* @example const users = await this.populateAndProcessQuery<User[]>(User.find({name: {'$regex': 'ma'}}), {...serviceOptions, populate:['contacts'], force: true});
|
|
547
616
|
*/
|
|
548
617
|
async processQueryOrDocument<T extends CoreModel | CoreModel[] = CoreModel>(
|
|
549
|
-
queryOrDocument:
|
|
618
|
+
queryOrDocument: Document | Document[] | Query<unknown, unknown>,
|
|
550
619
|
serviceOptions?: ServiceOptions,
|
|
551
620
|
): Promise<T> {
|
|
552
621
|
return this.process(() => {
|
|
553
622
|
if (queryOrDocument instanceof Query) {
|
|
623
|
+
if (serviceOptions?.select && queryOrDocument.select && typeof queryOrDocument.select === 'function') {
|
|
624
|
+
queryOrDocument.select(serviceOptions.select);
|
|
625
|
+
}
|
|
554
626
|
return queryOrDocument.exec();
|
|
555
627
|
}
|
|
556
628
|
return queryOrDocument;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { Injectable } from '@nestjs/common';
|
|
2
|
-
import nodemailer = require('nodemailer');
|
|
3
2
|
import { Attachment } from 'nodemailer/lib/mailer';
|
|
3
|
+
|
|
4
4
|
import { isNonEmptyString, isTrue, returnFalse } from '../helpers/input.helper';
|
|
5
5
|
import { ConfigService } from './config.service';
|
|
6
6
|
import { TemplateService } from './template.service';
|
|
7
7
|
|
|
8
|
+
import nodemailer = require('nodemailer');
|
|
9
|
+
|
|
8
10
|
/**
|
|
9
11
|
* Email service
|
|
10
12
|
*/
|
|
@@ -33,7 +35,7 @@ export class EmailService {
|
|
|
33
35
|
},
|
|
34
36
|
): Promise<any> {
|
|
35
37
|
// Process config
|
|
36
|
-
const { attachments, htmlTemplate,
|
|
38
|
+
const { attachments, htmlTemplate, senderEmail, senderName, templateData, textTemplate } = {
|
|
37
39
|
senderEmail: this.configService.getFastButReadOnly('email.defaultSender.email'),
|
|
38
40
|
senderName: this.configService.getFastButReadOnly('email.defaultSender.name'),
|
|
39
41
|
...config,
|
|
@@ -71,12 +73,12 @@ export class EmailService {
|
|
|
71
73
|
|
|
72
74
|
// Send mail
|
|
73
75
|
return transporter.sendMail({
|
|
76
|
+
attachments,
|
|
74
77
|
from: `"${senderName}" <${senderEmail}>`,
|
|
75
|
-
|
|
78
|
+
html,
|
|
76
79
|
subject,
|
|
77
80
|
text,
|
|
78
|
-
|
|
79
|
-
attachments,
|
|
81
|
+
to: recipients,
|
|
80
82
|
});
|
|
81
83
|
}
|
|
82
84
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { HttpException, Injectable } from '@nestjs/common';
|
|
2
2
|
import Mailjet from 'node-mailjet';
|
|
3
|
+
|
|
3
4
|
import { ConfigService } from './config.service';
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -20,24 +21,24 @@ export class MailjetService {
|
|
|
20
21
|
subject: string,
|
|
21
22
|
templateId: number,
|
|
22
23
|
config: {
|
|
23
|
-
senderEmail?: string;
|
|
24
|
-
senderName?: string;
|
|
25
24
|
attachments?: {
|
|
25
|
+
Base64Content: string;
|
|
26
26
|
ContentID?: string;
|
|
27
27
|
ContentType: string;
|
|
28
28
|
Filename: string;
|
|
29
|
-
Base64Content: string;
|
|
30
29
|
}[];
|
|
31
|
-
templateData?: { [key: string]: any };
|
|
32
30
|
sandbox?: boolean;
|
|
31
|
+
senderEmail?: string;
|
|
32
|
+
senderName?: string;
|
|
33
|
+
templateData?: { [key: string]: any };
|
|
33
34
|
},
|
|
34
35
|
) {
|
|
35
36
|
// Process config
|
|
36
|
-
const {
|
|
37
|
+
const { attachments, sandbox, senderEmail, senderName, templateData } = {
|
|
38
|
+
attachments: null,
|
|
39
|
+
sandbox: false,
|
|
37
40
|
senderEmail: this.configService.getFastButReadOnly('email.defaultSender.email'),
|
|
38
41
|
senderName: this.configService.getFastButReadOnly('email.defaultSender.name'),
|
|
39
|
-
sandbox: false,
|
|
40
|
-
attachments: null,
|
|
41
42
|
templateData: null,
|
|
42
43
|
...config,
|
|
43
44
|
};
|
|
@@ -57,16 +58,16 @@ export class MailjetService {
|
|
|
57
58
|
const body = {
|
|
58
59
|
Messages: [
|
|
59
60
|
{
|
|
61
|
+
Attachments: attachments,
|
|
60
62
|
From: {
|
|
61
63
|
Email: senderEmail,
|
|
62
64
|
Name: senderName,
|
|
63
65
|
},
|
|
64
|
-
|
|
66
|
+
Subject: subject,
|
|
65
67
|
TemplateID: templateId,
|
|
66
68
|
TemplateLanguage: true,
|
|
69
|
+
To: to,
|
|
67
70
|
Variables: templateData,
|
|
68
|
-
Subject: subject,
|
|
69
|
-
Attachments: attachments,
|
|
70
71
|
},
|
|
71
72
|
],
|
|
72
73
|
SandboxMode: sandbox,
|
|
@@ -89,11 +90,11 @@ export class MailjetService {
|
|
|
89
90
|
console.debug(
|
|
90
91
|
JSON.stringify(
|
|
91
92
|
{
|
|
92
|
-
'info': 'Mailjet credentials are missing',
|
|
93
|
-
'email.mailjet.api_key_public':
|
|
94
|
-
this.configService.getFastButReadOnly('email.mailjet.api_key_public') || 'missing',
|
|
95
93
|
'email.mailjet.api_key_private':
|
|
96
94
|
this.configService.getFastButReadOnly('email.mailjet.api_key_private') || 'missing',
|
|
95
|
+
'email.mailjet.api_key_public':
|
|
96
|
+
this.configService.getFastButReadOnly('email.mailjet.api_key_public') || 'missing',
|
|
97
|
+
'info': 'Mailjet credentials are missing',
|
|
97
98
|
'templateData': templateData,
|
|
98
99
|
},
|
|
99
100
|
null,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import fs = require('fs');
|
|
2
1
|
import { Injectable, OnApplicationBootstrap } from '@nestjs/common';
|
|
3
2
|
import { InjectConnection } from '@nestjs/mongoose';
|
|
4
3
|
import { Connection } from 'mongoose';
|
|
4
|
+
|
|
5
|
+
import fs = require('fs');
|
|
5
6
|
import YumlDiagram = require('yuml-diagram');
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import _ = require('lodash');
|
|
2
1
|
import { Document, Model, Types } from 'mongoose';
|
|
2
|
+
|
|
3
3
|
import { ProcessType } from '../enums/process-type.enum';
|
|
4
4
|
import { getStringIds, popAndMap } from '../helpers/db.helper';
|
|
5
5
|
import { check } from '../helpers/input.helper';
|
|
@@ -9,6 +9,8 @@ import { CoreModel } from '../models/core-model.model';
|
|
|
9
9
|
import { FieldSelection } from '../types/field-selection.type';
|
|
10
10
|
import { ConfigService } from './config.service';
|
|
11
11
|
|
|
12
|
+
import _ = require('lodash');
|
|
13
|
+
|
|
12
14
|
/**
|
|
13
15
|
* Module service class to be extended by concrete module services
|
|
14
16
|
*/
|
|
@@ -46,7 +48,7 @@ export abstract class ModuleService<T extends CoreModel = any> {
|
|
|
46
48
|
*/
|
|
47
49
|
checkRights(
|
|
48
50
|
input: any,
|
|
49
|
-
currentUser: {
|
|
51
|
+
currentUser: { hasRole: (roles: string[]) => boolean; id: any },
|
|
50
52
|
options?: {
|
|
51
53
|
dbObject?: any;
|
|
52
54
|
metatype?: any;
|
|
@@ -73,31 +75,37 @@ export abstract class ModuleService<T extends CoreModel = any> {
|
|
|
73
75
|
serviceFunc: (options?: { [key: string]: any; input?: any; serviceOptions?: ServiceOptions }) => any,
|
|
74
76
|
options?: {
|
|
75
77
|
[key: string]: any;
|
|
76
|
-
dbObject?:
|
|
77
|
-
outputPath?: string | string[];
|
|
78
|
+
dbObject?: Types.ObjectId | any | string;
|
|
78
79
|
input?: any;
|
|
80
|
+
outputPath?: string | string[];
|
|
79
81
|
serviceOptions?: ServiceOptions;
|
|
80
82
|
},
|
|
81
83
|
) {
|
|
82
84
|
// Configuration with default values
|
|
83
85
|
const config: {
|
|
84
|
-
dbObject:
|
|
85
|
-
outputPath: string | string[];
|
|
86
|
+
dbObject: Types.ObjectId | any | string;
|
|
86
87
|
input: any;
|
|
88
|
+
outputPath: string | string[];
|
|
87
89
|
} & ServiceOptions = {
|
|
88
90
|
checkRights: true,
|
|
89
91
|
dbObject: options?.dbObject,
|
|
90
|
-
outputPath: options?.outputPath,
|
|
91
92
|
force: false,
|
|
92
93
|
input: options?.input,
|
|
93
|
-
|
|
94
|
+
outputPath: options?.outputPath,
|
|
94
95
|
prepareInput: {},
|
|
95
96
|
prepareOutput: {},
|
|
97
|
+
processFieldSelection: {},
|
|
96
98
|
pubSub: true,
|
|
97
99
|
setCreateOrUpdateUserId: true,
|
|
98
100
|
...options?.serviceOptions,
|
|
99
101
|
};
|
|
100
102
|
|
|
103
|
+
// Note raw configuration
|
|
104
|
+
if (config.raw) {
|
|
105
|
+
config.prepareInput = null;
|
|
106
|
+
config.prepareOutput = null;
|
|
107
|
+
}
|
|
108
|
+
|
|
101
109
|
// Set default for ignoreSelections if not set
|
|
102
110
|
const ignoreSelections = this.configService?.getFastButReadOnly('ignoreSelectionsForPopulate', true);
|
|
103
111
|
if (ignoreSelections) {
|
|
@@ -180,8 +188,14 @@ export abstract class ModuleService<T extends CoreModel = any> {
|
|
|
180
188
|
|
|
181
189
|
// Pop and map main model
|
|
182
190
|
if (config.processFieldSelection && config.fieldSelection && this.processFieldSelection) {
|
|
183
|
-
|
|
184
|
-
|
|
191
|
+
let temps = result;
|
|
192
|
+
if (!Array.isArray(result)) {
|
|
193
|
+
temps = [result];
|
|
194
|
+
}
|
|
195
|
+
for (const temp of temps) {
|
|
196
|
+
const field = config.outputPath ? _.get(temp, config.outputPath) : temp;
|
|
197
|
+
await this.processFieldSelection(field, config.fieldSelection, config.processFieldSelection);
|
|
198
|
+
}
|
|
185
199
|
}
|
|
186
200
|
|
|
187
201
|
// Prepare output
|
|
@@ -191,7 +205,13 @@ export abstract class ModuleService<T extends CoreModel = any> {
|
|
|
191
205
|
opts.targetModel = config.outputType;
|
|
192
206
|
}
|
|
193
207
|
if (config.outputPath) {
|
|
194
|
-
|
|
208
|
+
let temps = result;
|
|
209
|
+
if (!Array.isArray(result)) {
|
|
210
|
+
temps = [result];
|
|
211
|
+
}
|
|
212
|
+
for (const temp of temps) {
|
|
213
|
+
_.set(temp, config.outputPath, await this.prepareOutput(_.get(temp, config.outputPath), opts));
|
|
214
|
+
}
|
|
195
215
|
} else {
|
|
196
216
|
result = await this.prepareOutput(result, config);
|
|
197
217
|
}
|
|
@@ -244,14 +264,14 @@ export abstract class ModuleService<T extends CoreModel = any> {
|
|
|
244
264
|
data: any,
|
|
245
265
|
fieldsSelection: FieldSelection,
|
|
246
266
|
options: {
|
|
247
|
-
model?: new (...args: any[]) => T;
|
|
248
267
|
dbModel?: Model<T & Document>;
|
|
249
268
|
ignoreSelections?: boolean;
|
|
269
|
+
model?: new (...args: any[]) => T;
|
|
250
270
|
} = {},
|
|
251
271
|
) {
|
|
252
272
|
const config = {
|
|
253
|
-
model: this.mainModelConstructor,
|
|
254
273
|
dbModel: this.mainDbModel,
|
|
274
|
+
model: this.mainModelConstructor,
|
|
255
275
|
...options,
|
|
256
276
|
};
|
|
257
277
|
return popAndMap(data, fieldsSelection, config.model, config.dbModel, {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import fs = require('fs');
|
|
2
|
-
import { join } from 'path';
|
|
3
1
|
import { Injectable } from '@nestjs/common';
|
|
4
|
-
import ejs = require('ejs');
|
|
5
2
|
import { TemplateFunction } from 'ejs';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
|
|
6
5
|
import { ConfigService } from './config.service';
|
|
7
6
|
|
|
7
|
+
import ejs = require('ejs');
|
|
8
|
+
import fs = require('fs');
|
|
9
|
+
|
|
8
10
|
/**
|
|
9
11
|
* Template service
|
|
10
12
|
*/
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { CoreModel } from '../models/core-model.model';
|
|
2
2
|
|
|
3
3
|
export interface CoreModelConstructor<T extends CoreModel> {
|
|
4
|
-
new (): T;
|
|
5
4
|
init(this: new (...args: any[]) => T, ...args: any[]): T;
|
|
6
5
|
map(
|
|
7
6
|
this: new (...args: any[]) => T,
|
|
@@ -27,4 +26,5 @@ export interface CoreModelConstructor<T extends CoreModel> {
|
|
|
27
26
|
mapId?: boolean;
|
|
28
27
|
}
|
|
29
28
|
): T;
|
|
29
|
+
new (): T;
|
|
30
30
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { SelectionNode } from 'graphql';
|
|
2
2
|
import { PopulateOptions } from 'mongoose';
|
|
3
|
+
|
|
3
4
|
import { ResolveSelector } from '../interfaces/resolve-selector.interface';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Field selection to set fields of (populated) result
|
|
7
8
|
*/
|
|
8
9
|
export type FieldSelection =
|
|
9
|
-
| string
|
|
10
|
-
| PopulateOptions
|
|
11
10
|
| (PopulateOptions | string)[]
|
|
11
|
+
| PopulateOptions
|
|
12
|
+
| ResolveSelector
|
|
12
13
|
| SelectionNode[]
|
|
13
|
-
|
|
|
14
|
+
| string;
|