@loomcore/api 0.2.42 → 0.2.45
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/LICENSE +201 -201
- package/dist/__tests__/common-test.utils.d.ts +13 -13
- package/dist/__tests__/common-test.utils.js +72 -72
- package/dist/__tests__/models/category.model.d.ts +1 -1
- package/dist/__tests__/models/category.model.js +2 -2
- package/dist/__tests__/models/product-with-category.model.d.ts +3 -3
- package/dist/__tests__/models/product-with-category.model.js +4 -4
- package/dist/__tests__/models/product.model.d.ts +2 -2
- package/dist/__tests__/models/product.model.js +2 -2
- package/dist/__tests__/models/test-entity.model.d.ts +2 -2
- package/dist/__tests__/models/test-entity.model.js +2 -2
- package/dist/__tests__/models/test-item.model.d.ts +1 -1
- package/dist/__tests__/models/test-item.model.js +3 -3
- package/dist/__tests__/mongo-db.test-database.js +1 -1
- package/dist/__tests__/postgres-test-migrations/postgres-test-schema.d.ts +2 -2
- package/dist/__tests__/postgres-test-migrations/postgres-test-schema.js +38 -38
- package/dist/__tests__/postgres.test-database.d.ts +2 -2
- package/dist/__tests__/postgres.test-database.js +25 -25
- package/dist/__tests__/test-database.interface.d.ts +1 -1
- package/dist/__tests__/test-email-client.d.ts +1 -1
- package/dist/__tests__/test-express-app.d.ts +3 -3
- package/dist/__tests__/test-express-app.js +12 -12
- package/dist/__tests__/test-objects.d.ts +1 -1
- package/dist/__tests__/test-objects.js +26 -26
- package/dist/config/base-api-config.d.ts +2 -2
- package/dist/config/base-api-config.js +17 -17
- package/dist/controllers/auth.controller.d.ts +4 -4
- package/dist/controllers/auth.controller.js +32 -32
- package/dist/controllers/authorizations.controller.d.ts +4 -4
- package/dist/controllers/authorizations.controller.js +4 -4
- package/dist/controllers/features.controller.d.ts +4 -4
- package/dist/controllers/features.controller.js +4 -4
- package/dist/controllers/index.d.ts +10 -10
- package/dist/controllers/index.js +10 -10
- package/dist/controllers/organizations.controller.d.ts +5 -5
- package/dist/controllers/organizations.controller.js +10 -10
- package/dist/controllers/roles.controller.d.ts +4 -4
- package/dist/controllers/roles.controller.js +4 -4
- package/dist/controllers/types.d.ts +2 -2
- package/dist/controllers/user-roles.controller.d.ts +4 -4
- package/dist/controllers/user-roles.controller.js +4 -4
- package/dist/controllers/users.controller.d.ts +5 -5
- package/dist/controllers/users.controller.js +4 -4
- package/dist/databases/models/database.interface.d.ts +5 -5
- package/dist/databases/mongo-db/commands/mongo-batch-update.command.d.ts +3 -3
- package/dist/databases/mongo-db/commands/mongo-batch-update.command.js +5 -5
- package/dist/databases/mongo-db/commands/mongo-create-many.command.d.ts +1 -1
- package/dist/databases/mongo-db/commands/mongo-create-many.command.js +1 -1
- package/dist/databases/mongo-db/commands/mongo-create.command.d.ts +1 -1
- package/dist/databases/mongo-db/commands/mongo-create.command.js +1 -1
- package/dist/databases/mongo-db/commands/mongo-delete-by-id.command.d.ts +3 -3
- package/dist/databases/mongo-db/commands/mongo-delete-by-id.command.js +4 -4
- package/dist/databases/mongo-db/commands/mongo-delete-many.command.d.ts +3 -3
- package/dist/databases/mongo-db/commands/mongo-delete-many.command.js +2 -2
- package/dist/databases/mongo-db/commands/mongo-full-updateby-id.command.d.ts +3 -3
- package/dist/databases/mongo-db/commands/mongo-full-updateby-id.command.js +4 -4
- package/dist/databases/mongo-db/commands/mongo-partial-update-by-id.command.d.ts +3 -3
- package/dist/databases/mongo-db/commands/mongo-partial-update-by-id.command.js +4 -4
- package/dist/databases/mongo-db/commands/mongo-update.command.d.ts +3 -3
- package/dist/databases/mongo-db/commands/mongo-update.command.js +3 -3
- package/dist/databases/mongo-db/migrations/mongo-initial-schema.d.ts +2 -2
- package/dist/databases/mongo-db/migrations/mongo-initial-schema.js +108 -108
- package/dist/databases/mongo-db/models/no-sql-pipeline.d.ts +4 -4
- package/dist/databases/mongo-db/models/no-sql-pipeline.interface.d.ts +3 -3
- package/dist/databases/mongo-db/models/no-sql-pipeline.js +1 -1
- package/dist/databases/mongo-db/mongo-db.database.d.ts +7 -7
- package/dist/databases/mongo-db/mongo-db.database.js +5 -5
- package/dist/databases/mongo-db/queries/mongo-find-one.query.d.ts +2 -2
- package/dist/databases/mongo-db/queries/mongo-find-one.query.js +1 -1
- package/dist/databases/mongo-db/queries/mongo-find.query.d.ts +2 -2
- package/dist/databases/mongo-db/queries/mongo-find.query.js +1 -1
- package/dist/databases/mongo-db/queries/mongo-get-all.query.d.ts +2 -2
- package/dist/databases/mongo-db/queries/mongo-get-all.query.js +1 -1
- package/dist/databases/mongo-db/queries/mongo-get-by-id.query.d.ts +4 -4
- package/dist/databases/mongo-db/queries/mongo-get-by-id.query.js +3 -3
- package/dist/databases/mongo-db/queries/mongo-get-count.query.d.ts +1 -1
- package/dist/databases/mongo-db/queries/mongo-get.query.d.ts +3 -3
- package/dist/databases/mongo-db/queries/mongo-get.query.js +2 -2
- package/dist/databases/mongo-db/utils/build-find-options.util.d.ts +2 -2
- package/dist/databases/mongo-db/utils/build-mongo-url.util.d.ts +1 -1
- package/dist/databases/mongo-db/utils/build-mongo-url.util.js +4 -4
- package/dist/databases/operations/__tests__/models/test-agent.model.d.ts +2 -2
- package/dist/databases/operations/__tests__/models/test-agent.model.js +3 -3
- package/dist/databases/operations/__tests__/models/test-client-report.model.d.ts +4 -4
- package/dist/databases/operations/__tests__/models/test-client-report.model.js +5 -5
- package/dist/databases/operations/__tests__/models/test-district.model.d.ts +2 -2
- package/dist/databases/operations/__tests__/models/test-district.model.js +2 -2
- package/dist/databases/operations/__tests__/models/test-email-address.model.d.ts +1 -1
- package/dist/databases/operations/__tests__/models/test-email-address.model.js +2 -2
- package/dist/databases/operations/__tests__/models/test-person.model.d.ts +4 -4
- package/dist/databases/operations/__tests__/models/test-person.model.js +4 -4
- package/dist/databases/operations/__tests__/models/test-phone-number.model.d.ts +1 -1
- package/dist/databases/operations/__tests__/models/test-phone-number.model.js +2 -2
- package/dist/databases/operations/__tests__/models/test-policy.model.d.ts +3 -3
- package/dist/databases/operations/__tests__/models/test-policy.model.js +4 -4
- package/dist/databases/operations/__tests__/models/test-premium.model.d.ts +1 -1
- package/dist/databases/operations/__tests__/models/test-premium.model.js +2 -2
- package/dist/databases/operations/__tests__/models/test-school.model.d.ts +2 -2
- package/dist/databases/operations/__tests__/models/test-school.model.js +2 -2
- package/dist/databases/operations/__tests__/models/test-state.model.d.ts +1 -1
- package/dist/databases/operations/__tests__/models/test-state.model.js +2 -2
- package/dist/databases/operations/operation.d.ts +3 -3
- package/dist/databases/postgres/commands/postgres-batch-update.command.d.ts +1 -1
- package/dist/databases/postgres/commands/postgres-batch-update.command.js +11 -11
- package/dist/databases/postgres/commands/postgres-create-many.command.js +5 -5
- package/dist/databases/postgres/commands/postgres-create.command.d.ts +3 -3
- package/dist/databases/postgres/commands/postgres-create.command.js +5 -5
- package/dist/databases/postgres/commands/postgres-delete-by-id.command.d.ts +1 -1
- package/dist/databases/postgres/commands/postgres-delete-by-id.command.js +1 -1
- package/dist/databases/postgres/commands/postgres-delete-many.command.d.ts +2 -2
- package/dist/databases/postgres/commands/postgres-delete-many.command.js +1 -1
- package/dist/databases/postgres/commands/postgres-full-update-by-id.command.d.ts +1 -1
- package/dist/databases/postgres/commands/postgres-full-update-by-id.command.js +4 -4
- package/dist/databases/postgres/commands/postgres-partial-update-by-id.command.d.ts +1 -1
- package/dist/databases/postgres/commands/postgres-partial-update-by-id.command.js +11 -11
- package/dist/databases/postgres/commands/postgres-update.command.d.ts +2 -2
- package/dist/databases/postgres/commands/postgres-update.command.js +11 -11
- package/dist/databases/postgres/migrations/postgres-initial-schema.d.ts +2 -2
- package/dist/databases/postgres/migrations/postgres-initial-schema.js +69 -69
- package/dist/databases/postgres/postgres.database.d.ts +6 -6
- package/dist/databases/postgres/postgres.database.js +18 -18
- package/dist/databases/postgres/queries/postgres-find-one.query.d.ts +1 -1
- package/dist/databases/postgres/queries/postgres-find-one.query.js +2 -2
- package/dist/databases/postgres/queries/postgres-find.query.d.ts +1 -1
- package/dist/databases/postgres/queries/postgres-find.query.js +2 -2
- package/dist/databases/postgres/queries/postgres-get-all.query.d.ts +1 -1
- package/dist/databases/postgres/queries/postgres-get-all.query.js +3 -3
- package/dist/databases/postgres/queries/postgres-get-by-id.query.d.ts +1 -1
- package/dist/databases/postgres/queries/postgres-get-by-id.query.js +5 -5
- package/dist/databases/postgres/queries/postgres-get-count.query.js +1 -1
- package/dist/databases/postgres/queries/postgres-get.query.d.ts +2 -2
- package/dist/databases/postgres/queries/postgres-get.query.js +9 -9
- package/dist/databases/postgres/utils/build-count-query.d.ts +1 -1
- package/dist/databases/postgres/utils/build-count-query.js +1 -1
- package/dist/databases/postgres/utils/build-join-clauses.d.ts +1 -1
- package/dist/databases/postgres/utils/build-join-clauses.js +7 -7
- package/dist/databases/postgres/utils/build-order-by-clause.d.ts +1 -1
- package/dist/databases/postgres/utils/build-pagination-clause.d.ts +1 -1
- package/dist/databases/postgres/utils/build-postgres-url.util.d.ts +1 -1
- package/dist/databases/postgres/utils/build-postgres-url.util.js +2 -2
- package/dist/databases/postgres/utils/build-select-clause.js +9 -9
- package/dist/databases/postgres/utils/build-where-clause.d.ts +1 -1
- package/dist/databases/postgres/utils/build-where-clause.js +1 -1
- package/dist/databases/postgres/utils/columns-and-values-from-entity.d.ts +1 -1
- package/dist/databases/postgres/utils/does-table-exist.util.d.ts +1 -1
- package/dist/databases/postgres/utils/does-table-exist.util.js +5 -5
- package/dist/decorators/index.d.ts +1 -0
- package/dist/decorators/index.js +1 -0
- package/dist/middleware/authorize/authenticate-request.d.ts +2 -2
- package/dist/middleware/authorize/authenticate-request.js +5 -5
- package/dist/middleware/index.d.ts +4 -4
- package/dist/middleware/index.js +4 -4
- package/dist/models/app-config.interface.d.ts +1 -1
- package/dist/models/base-api-config.interface.d.ts +6 -6
- package/dist/models/initial-database-config.interface.d.ts +3 -3
- package/dist/models/log-level.type.d.ts +1 -1
- package/dist/services/authorizations.service.d.ts +3 -3
- package/dist/services/authorizations.service.js +7 -7
- package/dist/services/email.service.js +5 -5
- package/dist/services/features.service.d.ts +3 -3
- package/dist/services/features.service.js +4 -4
- package/dist/services/generic-api-service/generic-api-service.interface.d.ts +6 -6
- package/dist/services/generic-api-service/generic-api.service.d.ts +8 -8
- package/dist/services/generic-api-service/generic-api.service.js +7 -7
- package/dist/services/index.d.ts +16 -16
- package/dist/services/index.js +16 -16
- package/dist/services/multi-tenant-api.service.d.ts +4 -4
- package/dist/services/multi-tenant-api.service.js +9 -9
- package/dist/services/organization-domain.service.d.ts +3 -3
- package/dist/services/organization-domain.service.js +3 -3
- package/dist/services/organization.service.d.ts +4 -4
- package/dist/services/organization.service.js +7 -7
- package/dist/services/password-reset-token.service.d.ts +3 -3
- package/dist/services/password-reset-token.service.js +5 -5
- package/dist/services/refresh-token.service.d.ts +3 -3
- package/dist/services/refresh-token.service.js +3 -3
- package/dist/services/roles.service.d.ts +3 -3
- package/dist/services/roles.service.js +4 -4
- package/dist/services/tenant-query-decorator.d.ts +1 -1
- package/dist/services/tenant-query-decorator.js +8 -8
- package/dist/services/user-roles.service.d.ts +3 -3
- package/dist/services/user-roles.service.js +4 -4
- package/dist/services/user.service.d.ts +4 -4
- package/dist/services/user.service.js +11 -11
- package/dist/services/utils/audit-for-create.util.d.ts +1 -1
- package/dist/services/utils/audit-for-create.util.js +2 -2
- package/dist/services/utils/audit-for-update.util.d.ts +1 -1
- package/dist/services/utils/audit-for-update.util.js +2 -2
- package/dist/services/utils/strip-sender-provided-system-properties.util.d.ts +1 -1
- package/dist/services/utils/strip-sender-provided-system-properties.util.js +4 -4
- package/dist/utils/auth/assert-admin-or-feature.util.d.ts +1 -1
- package/dist/utils/auth/assert-admin-or-feature.util.js +2 -2
- package/dist/utils/auth/assert-admin.util.d.ts +1 -1
- package/dist/utils/auth/assert-admin.util.js +2 -2
- package/dist/utils/auth/assert-owner-or-admin.util.d.ts +1 -1
- package/dist/utils/auth/assert-owner-or-admin.util.js +2 -2
- package/dist/utils/auth/assert-user-has-feature.util.d.ts +1 -1
- package/dist/utils/auth/assert-user-has-feature.util.js +1 -1
- package/dist/utils/auth/assert-user-or-admin.util.d.ts +2 -2
- package/dist/utils/auth/assert-user-or-admin.util.js +2 -2
- package/dist/utils/auth/attempt-login.util.d.ts +4 -4
- package/dist/utils/auth/attempt-login.util.js +8 -8
- package/dist/utils/auth/auth-user-specs.util.d.ts +1 -1
- package/dist/utils/auth/auth-user-specs.util.js +3 -3
- package/dist/utils/auth/change-password.util.d.ts +4 -4
- package/dist/utils/auth/change-password.util.js +2 -2
- package/dist/utils/auth/create-new-refresh-token.util.d.ts +3 -3
- package/dist/utils/auth/create-new-refresh-token.util.js +8 -8
- package/dist/utils/auth/create-new-tokens.util.d.ts +1 -1
- package/dist/utils/auth/create-new-tokens.util.js +3 -3
- package/dist/utils/auth/generate-device-id.util.js +2 -2
- package/dist/utils/auth/generate-refresh-token.util.js +2 -2
- package/dist/utils/auth/get-active-refresh-token.util.d.ts +2 -2
- package/dist/utils/auth/get-active-refresh-token.util.js +1 -1
- package/dist/utils/auth/get-and-set-device-id-cookie.util.d.ts +1 -1
- package/dist/utils/auth/get-and-set-device-id-cookie.util.js +4 -4
- package/dist/utils/auth/get-auth-config.util.d.ts +1 -1
- package/dist/utils/auth/get-auth-config.util.js +3 -3
- package/dist/utils/auth/get-device-id-from-cookie.util.d.ts +1 -1
- package/dist/utils/auth/index.d.ts +26 -26
- package/dist/utils/auth/index.js +26 -26
- package/dist/utils/auth/is-admin.util.d.ts +1 -1
- package/dist/utils/auth/is-admin.util.js +1 -1
- package/dist/utils/auth/log-user-in.util.d.ts +3 -3
- package/dist/utils/auth/log-user-in.util.js +5 -5
- package/dist/utils/auth/request-token-using-refresh-token.util.d.ts +4 -4
- package/dist/utils/auth/request-token-using-refresh-token.util.js +7 -7
- package/dist/utils/auth/reset-password.util.d.ts +4 -4
- package/dist/utils/auth/reset-password.util.js +8 -8
- package/dist/utils/auth/send-reset-password-email.util.d.ts +2 -2
- package/dist/utils/auth/send-reset-password-email.util.js +5 -5
- package/dist/utils/auth/update-last-logged-in.util.d.ts +3 -3
- package/dist/utils/auth/update-last-logged-in.util.js +3 -3
- package/dist/utils/create-public-spec.utils.d.ts +1 -1
- package/dist/utils/create-public-spec.utils.js +2 -2
- package/dist/utils/express.utils.d.ts +4 -4
- package/dist/utils/express.utils.js +5 -5
- package/dist/utils/index.d.ts +10 -10
- package/dist/utils/index.js +10 -10
- package/dist/utils/jwt.utils.d.ts +1 -1
- package/dist/utils/jwt.utils.js +3 -3
- package/dist/utils/logger.utils.d.ts +1 -1
- package/dist/utils/logger.utils.js +10 -10
- package/dist/utils/password.utils.js +7 -7
- package/package.json +2 -1
|
@@ -32,14 +32,14 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
|
|
|
32
32
|
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
33
33
|
done = true;
|
|
34
34
|
};
|
|
35
|
-
import { EmptyUserContext, passwordValidator, PublicUserContextSpec, PublicUserSpec, TokenResponseSpec, UserSpec, } from
|
|
36
|
-
import { entityUtils } from
|
|
37
|
-
import { config } from
|
|
38
|
-
import { BadRequestError, UnauthenticatedError } from
|
|
39
|
-
import { OrganizationService, UserService } from
|
|
40
|
-
import { attemptLogin, authorizeMethod, changePassword, createLoginResponseSpec, getAndSetDeviceIdCookie, getDeviceIdFromCookie, requestTokenUsingRefreshToken, resetPassword, sendResetPasswordEmail, } from
|
|
41
|
-
import { apiUtils } from
|
|
42
|
-
import { Authorize } from
|
|
35
|
+
import { EmptyUserContext, passwordValidator, PublicUserContextSpec, PublicUserSpec, TokenResponseSpec, UserSpec, } from '@loomcore/common/models';
|
|
36
|
+
import { entityUtils } from '@loomcore/common/utils';
|
|
37
|
+
import { config } from '../config/base-api-config.js';
|
|
38
|
+
import { BadRequestError, UnauthenticatedError } from '../errors/index.js';
|
|
39
|
+
import { OrganizationService, UserService } from '../services/index.js';
|
|
40
|
+
import { attemptLogin, authorizeMethod, changePassword, createLoginResponseSpec, getAndSetDeviceIdCookie, getDeviceIdFromCookie, requestTokenUsingRefreshToken, resetPassword, sendResetPasswordEmail, } from '../utils/auth/index.js';
|
|
41
|
+
import { apiUtils } from '../utils/index.js';
|
|
42
|
+
import { Authorize } from '../decorators/authorize.decorator.js';
|
|
43
43
|
let AuthController = (() => {
|
|
44
44
|
let _instanceExtraInitializers = [];
|
|
45
45
|
let _getUserContext_decorators;
|
|
@@ -86,25 +86,25 @@ let AuthController = (() => {
|
|
|
86
86
|
}
|
|
87
87
|
async login(req, res) {
|
|
88
88
|
const { email, password } = req.body;
|
|
89
|
-
if (!email || typeof email !==
|
|
90
|
-
throw new BadRequestError(
|
|
89
|
+
if (!email || typeof email !== 'string') {
|
|
90
|
+
throw new BadRequestError('Missing required fields: email is required.');
|
|
91
91
|
}
|
|
92
|
-
if (!password || typeof password !==
|
|
93
|
-
throw new BadRequestError(
|
|
92
|
+
if (!password || typeof password !== 'string') {
|
|
93
|
+
throw new BadRequestError('Missing required fields: password is required.');
|
|
94
94
|
}
|
|
95
95
|
let organization = null;
|
|
96
96
|
if (config.app.isMultiTenant) {
|
|
97
|
-
const referer = req.get(
|
|
97
|
+
const referer = req.get('referer') || req.headers.referer;
|
|
98
98
|
if (!referer) {
|
|
99
|
-
throw new BadRequestError(
|
|
99
|
+
throw new BadRequestError('Missing required fields: referer is required.');
|
|
100
100
|
}
|
|
101
|
-
const domain = referer.split(
|
|
101
|
+
const domain = referer.split('/')[2];
|
|
102
102
|
organization = await this.organizationService.findByDomain(EmptyUserContext, domain);
|
|
103
103
|
if (!organization) {
|
|
104
104
|
throw new BadRequestError(`No organization found for domain: ${domain}`);
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
-
res.set(
|
|
107
|
+
res.set('Content-Type', 'application/json');
|
|
108
108
|
const deviceId = getAndSetDeviceIdCookie(req, res);
|
|
109
109
|
const loginResponse = await attemptLogin(this.database, email, password, deviceId, organization, this.userService);
|
|
110
110
|
await this.afterAuth(req, res, loginResponse);
|
|
@@ -112,8 +112,8 @@ let AuthController = (() => {
|
|
|
112
112
|
}
|
|
113
113
|
async requestTokenUsingRefreshToken(req, res) {
|
|
114
114
|
const refreshToken = req.query.refreshToken;
|
|
115
|
-
if (!refreshToken || typeof refreshToken !==
|
|
116
|
-
throw new BadRequestError(
|
|
115
|
+
if (!refreshToken || typeof refreshToken !== 'string') {
|
|
116
|
+
throw new BadRequestError('Missing required fields: refreshToken is required.');
|
|
117
117
|
}
|
|
118
118
|
const deviceId = getDeviceIdFromCookie(req);
|
|
119
119
|
const tokens = await requestTokenUsingRefreshToken(this.database, refreshToken, deviceId);
|
|
@@ -130,29 +130,29 @@ let AuthController = (() => {
|
|
|
130
130
|
async changePassword(req, res) {
|
|
131
131
|
const userContext = req.userContext;
|
|
132
132
|
if (!userContext) {
|
|
133
|
-
throw new BadRequestError(
|
|
133
|
+
throw new BadRequestError('Missing required fields: userContext is required.');
|
|
134
134
|
}
|
|
135
135
|
const password = req.body?.password;
|
|
136
136
|
const validationErrors = entityUtils.validate(this.userSpec, { password: password }, true, passwordValidator);
|
|
137
|
-
entityUtils.handleValidationResult(validationErrors,
|
|
137
|
+
entityUtils.handleValidationResult(validationErrors, 'AuthController.changePassword');
|
|
138
138
|
const updateResult = await changePassword(this.database, userContext, password, this.userService);
|
|
139
139
|
apiUtils.apiResponse(res, 200, { data: updateResult });
|
|
140
140
|
}
|
|
141
141
|
async forgotPassword(req, res) {
|
|
142
142
|
const email = req.body?.email;
|
|
143
|
-
if (!email || typeof email !==
|
|
144
|
-
throw new BadRequestError(
|
|
143
|
+
if (!email || typeof email !== 'string') {
|
|
144
|
+
throw new BadRequestError('Missing required fields: email is required.');
|
|
145
145
|
}
|
|
146
|
-
let referer = req.get(
|
|
146
|
+
let referer = req.get('referer') || req.headers.referer;
|
|
147
147
|
if (!referer) {
|
|
148
|
-
throw new BadRequestError(
|
|
148
|
+
throw new BadRequestError('Missing required fields: referer is required.');
|
|
149
149
|
}
|
|
150
|
-
referer = referer.replace(/\/$/,
|
|
150
|
+
referer = referer.replace(/\/$/, '');
|
|
151
151
|
let organization = null;
|
|
152
152
|
if (config.app.isMultiTenant) {
|
|
153
|
-
organization = await this.organizationService.findByDomain(EmptyUserContext, referer.split(
|
|
153
|
+
organization = await this.organizationService.findByDomain(EmptyUserContext, referer.split('/')[2]);
|
|
154
154
|
if (!organization) {
|
|
155
|
-
throw new BadRequestError(
|
|
155
|
+
throw new BadRequestError('Missing required fields: organization is required.');
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
const userContext = {
|
|
@@ -173,17 +173,17 @@ let AuthController = (() => {
|
|
|
173
173
|
async resetPassword(req, res) {
|
|
174
174
|
const { email, token, password } = req.body;
|
|
175
175
|
if (!email || !token || !password) {
|
|
176
|
-
throw new BadRequestError(
|
|
176
|
+
throw new BadRequestError('Missing required fields: email, token, and password are required.');
|
|
177
177
|
}
|
|
178
178
|
let organization = null;
|
|
179
179
|
if (config.app.isMultiTenant) {
|
|
180
|
-
const referer = req.get(
|
|
180
|
+
const referer = req.get('referer') || req.headers.referer;
|
|
181
181
|
if (!referer) {
|
|
182
|
-
throw new BadRequestError(
|
|
182
|
+
throw new BadRequestError('Missing required fields: referer is required.');
|
|
183
183
|
}
|
|
184
|
-
organization = await this.organizationService.findByDomain(EmptyUserContext, referer.split(
|
|
184
|
+
organization = await this.organizationService.findByDomain(EmptyUserContext, referer.split('/')[2]);
|
|
185
185
|
if (!organization) {
|
|
186
|
-
throw new BadRequestError(
|
|
186
|
+
throw new BadRequestError('Missing required fields: organization is required.');
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
const response = await resetPassword(this.database, email, token, password, organization, this.userService, this.userSpec);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Application } from
|
|
2
|
-
import type { IDatabase } from
|
|
3
|
-
import { ApiController } from
|
|
4
|
-
import { IAuthorization } from
|
|
1
|
+
import type { Application } from 'express';
|
|
2
|
+
import type { IDatabase } from '../databases/models/index.js';
|
|
3
|
+
import { ApiController } from './api.controller.js';
|
|
4
|
+
import { IAuthorization } from '@loomcore/common/models';
|
|
5
5
|
export declare class AuthorizationsController extends ApiController<IAuthorization> {
|
|
6
6
|
constructor(app: Application, database: IDatabase);
|
|
7
7
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ApiController } from
|
|
2
|
-
import { AuthorizationModelSpec } from
|
|
3
|
-
import { AuthorizationsService } from
|
|
1
|
+
import { ApiController } from './api.controller.js';
|
|
2
|
+
import { AuthorizationModelSpec } from '@loomcore/common/models';
|
|
3
|
+
import { AuthorizationsService } from '../services/authorizations.service.js';
|
|
4
4
|
export class AuthorizationsController extends ApiController {
|
|
5
5
|
constructor(app, database) {
|
|
6
6
|
const authorizationService = new AuthorizationsService(database);
|
|
7
|
-
super(
|
|
7
|
+
super('authorizations', app, authorizationService, 'authorization', AuthorizationModelSpec);
|
|
8
8
|
}
|
|
9
9
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Application } from
|
|
2
|
-
import type { IDatabase } from
|
|
3
|
-
import { type IFeature } from
|
|
4
|
-
import { ApiController } from
|
|
1
|
+
import type { Application } from 'express';
|
|
2
|
+
import type { IDatabase } from '../databases/models/index.js';
|
|
3
|
+
import { type IFeature } from '@loomcore/common/models';
|
|
4
|
+
import { ApiController } from './api.controller.js';
|
|
5
5
|
export declare class FeaturesController extends ApiController<IFeature> {
|
|
6
6
|
constructor(app: Application, database: IDatabase);
|
|
7
7
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { FeatureModelSpec } from
|
|
2
|
-
import { FeaturesService } from
|
|
3
|
-
import { ApiController } from
|
|
1
|
+
import { FeatureModelSpec } from '@loomcore/common/models';
|
|
2
|
+
import { FeaturesService } from '../services/features.service.js';
|
|
3
|
+
import { ApiController } from './api.controller.js';
|
|
4
4
|
export class FeaturesController extends ApiController {
|
|
5
5
|
constructor(app, database) {
|
|
6
6
|
const featureService = new FeaturesService(database);
|
|
7
|
-
super(
|
|
7
|
+
super('features', app, featureService, 'feature', FeatureModelSpec);
|
|
8
8
|
}
|
|
9
9
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
1
|
+
export * from './api.controller.js';
|
|
2
|
+
export * from './auth.controller.js';
|
|
3
|
+
export * from './authorizations.controller.js';
|
|
4
|
+
export * from './features.controller.js';
|
|
5
|
+
export * from './organizations.controller.js';
|
|
6
|
+
export * from './query-api.controller.js';
|
|
7
|
+
export * from './roles.controller.js';
|
|
8
|
+
export * from './types.js';
|
|
9
|
+
export * from './user-roles.controller.js';
|
|
10
|
+
export * from './users.controller.js';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
1
|
+
export * from './api.controller.js';
|
|
2
|
+
export * from './auth.controller.js';
|
|
3
|
+
export * from './authorizations.controller.js';
|
|
4
|
+
export * from './features.controller.js';
|
|
5
|
+
export * from './organizations.controller.js';
|
|
6
|
+
export * from './query-api.controller.js';
|
|
7
|
+
export * from './roles.controller.js';
|
|
8
|
+
export * from './types.js';
|
|
9
|
+
export * from './user-roles.controller.js';
|
|
10
|
+
export * from './users.controller.js';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { IOrganization } from
|
|
2
|
-
import type { Application, NextFunction, Request, Response } from
|
|
3
|
-
import type { IDatabase } from
|
|
4
|
-
import { OrganizationService } from
|
|
5
|
-
import { ApiController } from
|
|
1
|
+
import type { IOrganization } from '@loomcore/common/models';
|
|
2
|
+
import type { Application, NextFunction, Request, Response } from 'express';
|
|
3
|
+
import type { IDatabase } from '../databases/models/index.js';
|
|
4
|
+
import { OrganizationService } from '../services/index.js';
|
|
5
|
+
import { ApiController } from './api.controller.js';
|
|
6
6
|
export declare class OrganizationsController extends ApiController<IOrganization> {
|
|
7
7
|
orgService: OrganizationService;
|
|
8
8
|
constructor(app: Application, database: IDatabase);
|
|
@@ -32,11 +32,11 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
|
|
|
32
32
|
}
|
|
33
33
|
return useValue ? value : void 0;
|
|
34
34
|
};
|
|
35
|
-
import { BadRequestError } from
|
|
36
|
-
import { OrganizationService } from
|
|
37
|
-
import { apiUtils, authorizeMethod } from
|
|
38
|
-
import { ApiController } from
|
|
39
|
-
import { Authorize } from
|
|
35
|
+
import { BadRequestError } from '../errors/index.js';
|
|
36
|
+
import { OrganizationService } from '../services/index.js';
|
|
37
|
+
import { apiUtils, authorizeMethod } from '../utils/index.js';
|
|
38
|
+
import { ApiController } from './api.controller.js';
|
|
39
|
+
import { Authorize } from '../decorators/authorize.decorator.js';
|
|
40
40
|
let OrganizationsController = (() => {
|
|
41
41
|
let _classDecorators = [Authorize('admin')];
|
|
42
42
|
let _classDescriptor;
|
|
@@ -55,7 +55,7 @@ let OrganizationsController = (() => {
|
|
|
55
55
|
orgService;
|
|
56
56
|
constructor(app, database) {
|
|
57
57
|
const orgService = new OrganizationService(database);
|
|
58
|
-
super(
|
|
58
|
+
super('organizations', app, orgService);
|
|
59
59
|
this.orgService = orgService;
|
|
60
60
|
}
|
|
61
61
|
mapRoutes(app) {
|
|
@@ -67,12 +67,12 @@ let OrganizationsController = (() => {
|
|
|
67
67
|
async getByName(req, res, next) {
|
|
68
68
|
const { name } = req.params;
|
|
69
69
|
try {
|
|
70
|
-
res.set(
|
|
70
|
+
res.set('Content-Type', 'application/json');
|
|
71
71
|
const entity = await this.orgService.findOne(req.userContext, {
|
|
72
72
|
filters: { name: { contains: name } },
|
|
73
73
|
});
|
|
74
74
|
if (!entity)
|
|
75
|
-
throw new BadRequestError(
|
|
75
|
+
throw new BadRequestError('Organization name not found');
|
|
76
76
|
apiUtils.apiResponse(res, 200, { data: entity });
|
|
77
77
|
}
|
|
78
78
|
catch (err) {
|
|
@@ -83,12 +83,12 @@ let OrganizationsController = (() => {
|
|
|
83
83
|
async getByCode(req, res, next) {
|
|
84
84
|
const { code } = req.params;
|
|
85
85
|
try {
|
|
86
|
-
res.set(
|
|
86
|
+
res.set('Content-Type', 'application/json');
|
|
87
87
|
const entity = await this.orgService.findOne(req.userContext, {
|
|
88
88
|
filters: { code: { eq: code } },
|
|
89
89
|
});
|
|
90
90
|
if (!entity)
|
|
91
|
-
throw new BadRequestError(
|
|
91
|
+
throw new BadRequestError('Organization code not found');
|
|
92
92
|
apiUtils.apiResponse(res, 200, { data: entity });
|
|
93
93
|
}
|
|
94
94
|
catch (err) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Application } from
|
|
2
|
-
import type { IDatabase } from
|
|
3
|
-
import { type IRole } from
|
|
4
|
-
import { ApiController } from
|
|
1
|
+
import type { Application } from 'express';
|
|
2
|
+
import type { IDatabase } from '../databases/models/index.js';
|
|
3
|
+
import { type IRole } from '@loomcore/common/models';
|
|
4
|
+
import { ApiController } from './api.controller.js';
|
|
5
5
|
export declare class RolesController extends ApiController<IRole> {
|
|
6
6
|
constructor(app: Application, database: IDatabase);
|
|
7
7
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { RoleModelSpec } from
|
|
2
|
-
import { RolesService } from
|
|
3
|
-
import { ApiController } from
|
|
1
|
+
import { RoleModelSpec } from '@loomcore/common/models';
|
|
2
|
+
import { RolesService } from '../services/roles.service.js';
|
|
3
|
+
import { ApiController } from './api.controller.js';
|
|
4
4
|
export class RolesController extends ApiController {
|
|
5
5
|
constructor(app, database) {
|
|
6
6
|
const roleService = new RolesService(database);
|
|
7
|
-
super(
|
|
7
|
+
super('roles', app, roleService, 'role', RoleModelSpec);
|
|
8
8
|
}
|
|
9
9
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IEntity, IQueryOptions, IUserContext } from
|
|
2
|
-
import { Operation } from
|
|
1
|
+
import { IEntity, IQueryOptions, IUserContext } from '@loomcore/common/models';
|
|
2
|
+
import { Operation } from '../databases/index.js';
|
|
3
3
|
export type PrepareQueryCustomFunction = (userContext: IUserContext | undefined, queryObject: IQueryOptions, operations: Operation[]) => {
|
|
4
4
|
queryObject: IQueryOptions;
|
|
5
5
|
operations: Operation[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Application } from
|
|
2
|
-
import type { IDatabase } from
|
|
3
|
-
import { type IUserRole } from
|
|
4
|
-
import { ApiController } from
|
|
1
|
+
import type { Application } from 'express';
|
|
2
|
+
import type { IDatabase } from '../databases/models/index.js';
|
|
3
|
+
import { type IUserRole } from '@loomcore/common/models';
|
|
4
|
+
import { ApiController } from './api.controller.js';
|
|
5
5
|
export declare class UserRolesController extends ApiController<IUserRole> {
|
|
6
6
|
constructor(app: Application, database: IDatabase);
|
|
7
7
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { UserRoleModelSpec } from
|
|
2
|
-
import { UserRolesService } from
|
|
3
|
-
import { ApiController } from
|
|
1
|
+
import { UserRoleModelSpec } from '@loomcore/common/models';
|
|
2
|
+
import { UserRolesService } from '../services/user-roles.service.js';
|
|
3
|
+
import { ApiController } from './api.controller.js';
|
|
4
4
|
export class UserRolesController extends ApiController {
|
|
5
5
|
constructor(app, database) {
|
|
6
6
|
const userRoleService = new UserRolesService(database);
|
|
7
|
-
super(
|
|
7
|
+
super('user-roles', app, userRoleService, 'user-role', UserRoleModelSpec);
|
|
8
8
|
}
|
|
9
9
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type IModelSpec, type IUser } from
|
|
2
|
-
import type { Application } from
|
|
3
|
-
import type { IDatabase } from
|
|
4
|
-
import { UserService } from
|
|
5
|
-
import { ApiController } from
|
|
1
|
+
import { type IModelSpec, type IUser } from '@loomcore/common/models';
|
|
2
|
+
import type { Application } from 'express';
|
|
3
|
+
import type { IDatabase } from '../databases/models/index.js';
|
|
4
|
+
import { UserService } from '../services/index.js';
|
|
5
|
+
import { ApiController } from './api.controller.js';
|
|
6
6
|
export interface UsersControllerOptions {
|
|
7
7
|
userService: UserService;
|
|
8
8
|
userSpec: IModelSpec;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { PublicUserSpec, UserSpec, } from
|
|
2
|
-
import { UserService } from
|
|
3
|
-
import { ApiController } from
|
|
1
|
+
import { PublicUserSpec, UserSpec, } from '@loomcore/common/models';
|
|
2
|
+
import { UserService } from '../services/index.js';
|
|
3
|
+
import { ApiController } from './api.controller.js';
|
|
4
4
|
export class UsersController extends ApiController {
|
|
5
5
|
userService;
|
|
6
6
|
constructor(app, database, options = {
|
|
@@ -8,7 +8,7 @@ export class UsersController extends ApiController {
|
|
|
8
8
|
userSpec: UserSpec,
|
|
9
9
|
publicUserSpec: PublicUserSpec,
|
|
10
10
|
}) {
|
|
11
|
-
super(
|
|
11
|
+
super('users', app, options.userService, 'user', options.userSpec, options.publicUserSpec);
|
|
12
12
|
this.userService = options.userService;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { IModelSpec, IQueryOptions, IPagedResult, IEntity } from
|
|
2
|
-
import type { AppIdType } from
|
|
3
|
-
import { DeleteResult } from
|
|
4
|
-
import { TSchema } from
|
|
5
|
-
import { Operation } from
|
|
1
|
+
import { IModelSpec, IQueryOptions, IPagedResult, IEntity } from '@loomcore/common/models';
|
|
2
|
+
import type { AppIdType } from '@loomcore/common/types';
|
|
3
|
+
import { DeleteResult } from './delete-result.js';
|
|
4
|
+
import { TSchema } from '@sinclair/typebox';
|
|
5
|
+
import { Operation } from '../operations/operation.js';
|
|
6
6
|
export interface IDatabase {
|
|
7
7
|
close(): Promise<void>;
|
|
8
8
|
preProcessEntity<T extends IEntity>(entity: Partial<T>, modelSpec: TSchema): Partial<T>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Db } from
|
|
2
|
-
import { Operation } from
|
|
3
|
-
import { IQueryOptions } from
|
|
1
|
+
import { Db } from 'mongodb';
|
|
2
|
+
import { Operation } from '../../operations/operation.js';
|
|
3
|
+
import { IQueryOptions } from '@loomcore/common/models';
|
|
4
4
|
export declare function batchUpdate<T>(db: Db, entities: Partial<T>[], operations: Operation[], queryObject: IQueryOptions, pluralResourceName: string): Promise<T[]>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ObjectId } from
|
|
2
|
-
import { BadRequestError } from
|
|
3
|
-
import { convertOperationsToPipeline } from
|
|
4
|
-
import { buildNoSqlMatch } from
|
|
5
|
-
import NoSqlPipeline from
|
|
1
|
+
import { ObjectId } from 'mongodb';
|
|
2
|
+
import { BadRequestError } from '../../../errors/index.js';
|
|
3
|
+
import { convertOperationsToPipeline } from '../utils/index.js';
|
|
4
|
+
import { buildNoSqlMatch } from '../utils/build-no-sql-match.util.js';
|
|
5
|
+
import NoSqlPipeline from '../models/no-sql-pipeline.js';
|
|
6
6
|
export async function batchUpdate(db, entities, operations, queryObject, pluralResourceName) {
|
|
7
7
|
const collection = db.collection(pluralResourceName);
|
|
8
8
|
if (!entities || entities.length === 0) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BadRequestError, DuplicateKeyError } from
|
|
1
|
+
import { BadRequestError, DuplicateKeyError } from '../../../errors/index.js';
|
|
2
2
|
export async function createMany(db, pluralResourceName, entities) {
|
|
3
3
|
try {
|
|
4
4
|
const collection = db.collection(pluralResourceName);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BadRequestError, DuplicateKeyError } from
|
|
1
|
+
import { BadRequestError, DuplicateKeyError } from '../../../errors/index.js';
|
|
2
2
|
export async function create(db, pluralResourceName, entity) {
|
|
3
3
|
try {
|
|
4
4
|
const collection = db.collection(pluralResourceName);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Db } from
|
|
2
|
-
import { DeleteResult as GenericDeleteResult } from
|
|
3
|
-
import type { AppIdType } from
|
|
1
|
+
import { Db } from 'mongodb';
|
|
2
|
+
import { DeleteResult as GenericDeleteResult } from '../../models/delete-result.js';
|
|
3
|
+
import type { AppIdType } from '@loomcore/common/types';
|
|
4
4
|
export declare function deleteById(db: Db, id: AppIdType, pluralResourceName: string): Promise<GenericDeleteResult>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ObjectId } from
|
|
2
|
-
import { DeleteResult as GenericDeleteResult } from
|
|
3
|
-
import { BadRequestError } from
|
|
4
|
-
import { entityUtils } from
|
|
1
|
+
import { ObjectId } from 'mongodb';
|
|
2
|
+
import { DeleteResult as GenericDeleteResult } from '../../models/delete-result.js';
|
|
3
|
+
import { BadRequestError } from '../../../errors/index.js';
|
|
4
|
+
import { entityUtils } from '@loomcore/common/utils';
|
|
5
5
|
export async function deleteById(db, id, pluralResourceName) {
|
|
6
6
|
if (!entityUtils.isValidObjectId(id)) {
|
|
7
7
|
throw new BadRequestError('id is not a valid ObjectId');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Db } from
|
|
2
|
-
import { IQueryOptions } from
|
|
3
|
-
import { DeleteResult as GenericDeleteResult } from
|
|
1
|
+
import { Db } from 'mongodb';
|
|
2
|
+
import { IQueryOptions } from '@loomcore/common/models';
|
|
3
|
+
import { DeleteResult as GenericDeleteResult } from '../../models/delete-result.js';
|
|
4
4
|
export declare function deleteMany(db: Db, queryObject: IQueryOptions, pluralResourceName: string): Promise<GenericDeleteResult>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DeleteResult as GenericDeleteResult } from
|
|
2
|
-
import { buildNoSqlMatch } from
|
|
1
|
+
import { DeleteResult as GenericDeleteResult } from '../../models/delete-result.js';
|
|
2
|
+
import { buildNoSqlMatch } from '../utils/build-no-sql-match.util.js';
|
|
3
3
|
export async function deleteMany(db, queryObject, pluralResourceName) {
|
|
4
4
|
const collection = db.collection(pluralResourceName);
|
|
5
5
|
const matchDocument = buildNoSqlMatch(queryObject);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Db } from
|
|
2
|
-
import { Operation } from
|
|
3
|
-
import type { AppIdType } from
|
|
1
|
+
import { Db } from 'mongodb';
|
|
2
|
+
import { Operation } from '../../operations/operation.js';
|
|
3
|
+
import type { AppIdType } from '@loomcore/common/types';
|
|
4
4
|
export declare function fullUpdateById<T>(db: Db, operations: Operation[], id: AppIdType, entity: any, pluralResourceName: string): Promise<T>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BadRequestError, IdNotFoundError } from
|
|
2
|
-
import NoSqlPipeline from
|
|
3
|
-
import { buildNoSqlMatch } from
|
|
4
|
-
import { entityUtils } from
|
|
1
|
+
import { BadRequestError, IdNotFoundError } from '../../../errors/index.js';
|
|
2
|
+
import NoSqlPipeline from '../models/no-sql-pipeline.js';
|
|
3
|
+
import { buildNoSqlMatch } from '../utils/build-no-sql-match.util.js';
|
|
4
|
+
import { entityUtils } from '@loomcore/common/utils';
|
|
5
5
|
export async function fullUpdateById(db, operations, id, entity, pluralResourceName) {
|
|
6
6
|
if (!entityUtils.isValidObjectId(id)) {
|
|
7
7
|
throw new BadRequestError('id is not a valid ObjectId');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Db } from
|
|
2
|
-
import { Operation } from
|
|
3
|
-
import type { AppIdType } from
|
|
1
|
+
import { Db } from 'mongodb';
|
|
2
|
+
import { Operation } from '../../operations/operation.js';
|
|
3
|
+
import type { AppIdType } from '@loomcore/common/types';
|
|
4
4
|
export declare function partialUpdateById<T>(db: Db, operations: Operation[], id: AppIdType, entity: Partial<any>, pluralResourceName: string): Promise<T>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BadRequestError, IdNotFoundError } from
|
|
2
|
-
import NoSqlPipeline from
|
|
3
|
-
import { buildNoSqlMatch } from
|
|
4
|
-
import { entityUtils } from
|
|
1
|
+
import { BadRequestError, IdNotFoundError } from '../../../errors/index.js';
|
|
2
|
+
import NoSqlPipeline from '../models/no-sql-pipeline.js';
|
|
3
|
+
import { buildNoSqlMatch } from '../utils/build-no-sql-match.util.js';
|
|
4
|
+
import { entityUtils } from '@loomcore/common/utils';
|
|
5
5
|
export async function partialUpdateById(db, operations, id, entity, pluralResourceName) {
|
|
6
6
|
if (!entityUtils.isValidObjectId(id)) {
|
|
7
7
|
throw new BadRequestError('id is not a valid ObjectId');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Db } from
|
|
2
|
-
import { IQueryOptions } from
|
|
3
|
-
import { Operation } from
|
|
1
|
+
import { Db } from 'mongodb';
|
|
2
|
+
import { IQueryOptions } from '@loomcore/common/models';
|
|
3
|
+
import { Operation } from '../../operations/operation.js';
|
|
4
4
|
export declare function update<T>(db: Db, queryObject: IQueryOptions, entity: Partial<any>, operations: Operation[], pluralResourceName: string): Promise<T[]>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { NotFoundError } from
|
|
2
|
-
import NoSqlPipeline from
|
|
3
|
-
import { buildNoSqlMatch } from
|
|
1
|
+
import { NotFoundError } from '../../../errors/index.js';
|
|
2
|
+
import NoSqlPipeline from '../models/no-sql-pipeline.js';
|
|
3
|
+
import { buildNoSqlMatch } from '../utils/build-no-sql-match.util.js';
|
|
4
4
|
export async function update(db, queryObject, entity, operations, pluralResourceName) {
|
|
5
5
|
const collection = db.collection(pluralResourceName);
|
|
6
6
|
const matchDocument = buildNoSqlMatch(queryObject);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Db } from
|
|
2
|
-
import { IInitialDbMigrationConfig } from
|
|
1
|
+
import { Db } from 'mongodb';
|
|
2
|
+
import { IInitialDbMigrationConfig } from '../../../models/initial-database-config.interface.js';
|
|
3
3
|
export interface ISyntheticMigration {
|
|
4
4
|
name: string;
|
|
5
5
|
up: (context: {
|