@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
|
@@ -1,203 +1,203 @@
|
|
|
1
|
-
import { EmptyUserContext, getSystemUserContext, initializeSystemUserContext, isSystemUserContextInitialized, } from
|
|
2
|
-
import { OrganizationService } from
|
|
3
|
-
import { passwordUtils } from
|
|
4
|
-
import { MongoDBDatabase } from
|
|
1
|
+
import { EmptyUserContext, getSystemUserContext, initializeSystemUserContext, isSystemUserContextInitialized, } from '@loomcore/common/models';
|
|
2
|
+
import { OrganizationService } from '../../../services/index.js';
|
|
3
|
+
import { passwordUtils } from '../../../utils/index.js';
|
|
4
|
+
import { MongoDBDatabase } from '../mongo-db.database.js';
|
|
5
5
|
export const getMongoInitialSchema = (dbConfig) => {
|
|
6
6
|
const migrations = [];
|
|
7
7
|
const isMultiTenant = dbConfig.app.isMultiTenant;
|
|
8
8
|
if (isMultiTenant && !dbConfig.multiTenant) {
|
|
9
|
-
throw new Error(
|
|
9
|
+
throw new Error('Multi-tenant configuration is enabled but multi-tenant configuration is not provided');
|
|
10
10
|
}
|
|
11
11
|
const isAuthEnabled = dbConfig.app.isAuthEnabled;
|
|
12
12
|
if (isMultiTenant) {
|
|
13
13
|
migrations.push({
|
|
14
|
-
name:
|
|
14
|
+
name: '00000000000001_schema-organizations',
|
|
15
15
|
up: async ({ context: db }) => {
|
|
16
|
-
await db.createCollection(
|
|
16
|
+
await db.createCollection('organizations');
|
|
17
17
|
await db
|
|
18
|
-
.collection(
|
|
18
|
+
.collection('organizations')
|
|
19
19
|
.createIndex({ name: 1 }, { unique: true });
|
|
20
20
|
await db
|
|
21
|
-
.collection(
|
|
21
|
+
.collection('organizations')
|
|
22
22
|
.createIndex({ code: 1 }, { unique: true });
|
|
23
|
-
await db.collection(
|
|
23
|
+
await db.collection('organizations').createIndex({ isMetaOrg: 1 });
|
|
24
24
|
},
|
|
25
25
|
down: async ({ context: db }) => {
|
|
26
|
-
await db.collection(
|
|
26
|
+
await db.collection('organizations').drop();
|
|
27
27
|
},
|
|
28
28
|
});
|
|
29
29
|
migrations.push({
|
|
30
|
-
name:
|
|
30
|
+
name: '00000000000001_schema-organizations-domains',
|
|
31
31
|
up: async ({ context: db }) => {
|
|
32
|
-
await db.createCollection(
|
|
32
|
+
await db.createCollection('organizationDomains');
|
|
33
33
|
await db
|
|
34
|
-
.collection(
|
|
34
|
+
.collection('organizationDomains')
|
|
35
35
|
.createIndex({ domain: 1 }, { unique: true });
|
|
36
36
|
await db
|
|
37
|
-
.collection(
|
|
37
|
+
.collection('organizationDomains')
|
|
38
38
|
.createIndex({ organizationId: 1 });
|
|
39
39
|
},
|
|
40
40
|
down: async ({ context: db }) => {
|
|
41
|
-
await db.collection(
|
|
41
|
+
await db.collection('organizationDomains').drop();
|
|
42
42
|
},
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
if (isAuthEnabled)
|
|
46
46
|
migrations.push({
|
|
47
|
-
name:
|
|
47
|
+
name: '00000000000002_schema-users',
|
|
48
48
|
up: async ({ context: db }) => {
|
|
49
|
-
await db.createCollection(
|
|
49
|
+
await db.createCollection('users');
|
|
50
50
|
if (dbConfig.app.isMultiTenant) {
|
|
51
51
|
await db
|
|
52
|
-
.collection(
|
|
52
|
+
.collection('users')
|
|
53
53
|
.createIndex({ _orgId: 1, email: 1 }, { unique: true });
|
|
54
|
-
await db.collection(
|
|
54
|
+
await db.collection('users').createIndex({ _orgId: 1 });
|
|
55
55
|
}
|
|
56
56
|
else {
|
|
57
57
|
await db
|
|
58
|
-
.collection(
|
|
58
|
+
.collection('users')
|
|
59
59
|
.createIndex({ email: 1 }, { unique: true });
|
|
60
60
|
}
|
|
61
61
|
await db
|
|
62
|
-
.collection(
|
|
62
|
+
.collection('users')
|
|
63
63
|
.createIndex({ externalId: 1 }, { unique: true, sparse: true });
|
|
64
64
|
},
|
|
65
65
|
down: async ({ context: db }) => {
|
|
66
|
-
await db.collection(
|
|
66
|
+
await db.collection('users').drop();
|
|
67
67
|
},
|
|
68
68
|
});
|
|
69
69
|
if (isAuthEnabled)
|
|
70
70
|
migrations.push({
|
|
71
|
-
name:
|
|
71
|
+
name: '00000000000003_schema-refresh-tokens',
|
|
72
72
|
up: async ({ context: db }) => {
|
|
73
|
-
await db.createCollection(
|
|
73
|
+
await db.createCollection('refreshTokens');
|
|
74
74
|
await db
|
|
75
|
-
.collection(
|
|
75
|
+
.collection('refreshTokens')
|
|
76
76
|
.createIndex({ token: 1 }, { unique: true });
|
|
77
|
-
await db.collection(
|
|
78
|
-
await db.collection(
|
|
77
|
+
await db.collection('refreshTokens').createIndex({ userId: 1 });
|
|
78
|
+
await db.collection('refreshTokens').createIndex({ deviceId: 1 });
|
|
79
79
|
if (isMultiTenant) {
|
|
80
|
-
await db.collection(
|
|
80
|
+
await db.collection('refreshTokens').createIndex({ _orgId: 1 });
|
|
81
81
|
}
|
|
82
82
|
},
|
|
83
83
|
down: async ({ context: db }) => {
|
|
84
|
-
await db.collection(
|
|
84
|
+
await db.collection('refreshTokens').drop();
|
|
85
85
|
},
|
|
86
86
|
});
|
|
87
87
|
if (isAuthEnabled)
|
|
88
88
|
migrations.push({
|
|
89
|
-
name:
|
|
89
|
+
name: '00000000000004_schema-password-reset-tokens',
|
|
90
90
|
up: async ({ context: db }) => {
|
|
91
|
-
await db.createCollection(
|
|
91
|
+
await db.createCollection('passwordResetTokens');
|
|
92
92
|
if (isMultiTenant) {
|
|
93
93
|
await db
|
|
94
|
-
.collection(
|
|
94
|
+
.collection('passwordResetTokens')
|
|
95
95
|
.createIndex({ _orgId: 1, email: 1 }, { unique: true });
|
|
96
96
|
await db
|
|
97
|
-
.collection(
|
|
97
|
+
.collection('passwordResetTokens')
|
|
98
98
|
.createIndex({ _orgId: 1 });
|
|
99
99
|
}
|
|
100
100
|
else {
|
|
101
101
|
await db
|
|
102
|
-
.collection(
|
|
102
|
+
.collection('passwordResetTokens')
|
|
103
103
|
.createIndex({ email: 1 }, { unique: true });
|
|
104
104
|
}
|
|
105
105
|
},
|
|
106
106
|
down: async ({ context: db }) => {
|
|
107
|
-
await db.collection(
|
|
107
|
+
await db.collection('passwordResetTokens').drop();
|
|
108
108
|
},
|
|
109
109
|
});
|
|
110
110
|
if (isAuthEnabled)
|
|
111
111
|
migrations.push({
|
|
112
|
-
name:
|
|
112
|
+
name: '00000000000005_schema-roles',
|
|
113
113
|
up: async ({ context: db }) => {
|
|
114
|
-
await db.createCollection(
|
|
114
|
+
await db.createCollection('roles');
|
|
115
115
|
if (isMultiTenant) {
|
|
116
116
|
await db
|
|
117
|
-
.collection(
|
|
117
|
+
.collection('roles')
|
|
118
118
|
.createIndex({ _orgId: 1, name: 1 }, { unique: true });
|
|
119
|
-
await db.collection(
|
|
119
|
+
await db.collection('roles').createIndex({ _orgId: 1 });
|
|
120
120
|
}
|
|
121
121
|
else {
|
|
122
122
|
await db
|
|
123
|
-
.collection(
|
|
123
|
+
.collection('roles')
|
|
124
124
|
.createIndex({ name: 1 }, { unique: true });
|
|
125
125
|
}
|
|
126
126
|
},
|
|
127
127
|
down: async ({ context: db }) => {
|
|
128
|
-
await db.collection(
|
|
128
|
+
await db.collection('roles').drop();
|
|
129
129
|
},
|
|
130
130
|
});
|
|
131
131
|
if (isAuthEnabled)
|
|
132
132
|
migrations.push({
|
|
133
|
-
name:
|
|
133
|
+
name: '00000000000006_schema-user-roles',
|
|
134
134
|
up: async ({ context: db }) => {
|
|
135
|
-
await db.createCollection(
|
|
135
|
+
await db.createCollection('userRoles');
|
|
136
136
|
if (isMultiTenant) {
|
|
137
137
|
await db
|
|
138
|
-
.collection(
|
|
138
|
+
.collection('userRoles')
|
|
139
139
|
.createIndex({ _orgId: 1, userId: 1, roleId: 1 }, { unique: true });
|
|
140
|
-
await db.collection(
|
|
140
|
+
await db.collection('userRoles').createIndex({ _orgId: 1 });
|
|
141
141
|
}
|
|
142
142
|
else {
|
|
143
143
|
await db
|
|
144
|
-
.collection(
|
|
144
|
+
.collection('userRoles')
|
|
145
145
|
.createIndex({ userId: 1, roleId: 1 }, { unique: true });
|
|
146
146
|
}
|
|
147
|
-
await db.collection(
|
|
148
|
-
await db.collection(
|
|
147
|
+
await db.collection('userRoles').createIndex({ userId: 1 });
|
|
148
|
+
await db.collection('userRoles').createIndex({ roleId: 1 });
|
|
149
149
|
},
|
|
150
150
|
down: async ({ context: db }) => {
|
|
151
|
-
await db.collection(
|
|
151
|
+
await db.collection('userRoles').drop();
|
|
152
152
|
},
|
|
153
153
|
});
|
|
154
154
|
if (isAuthEnabled)
|
|
155
155
|
migrations.push({
|
|
156
|
-
name:
|
|
156
|
+
name: '00000000000007_schema-features',
|
|
157
157
|
up: async ({ context: db }) => {
|
|
158
|
-
await db.createCollection(
|
|
158
|
+
await db.createCollection('features');
|
|
159
159
|
if (isMultiTenant) {
|
|
160
160
|
await db
|
|
161
|
-
.collection(
|
|
161
|
+
.collection('features')
|
|
162
162
|
.createIndex({ _orgId: 1, name: 1 }, { unique: true });
|
|
163
|
-
await db.collection(
|
|
163
|
+
await db.collection('features').createIndex({ _orgId: 1 });
|
|
164
164
|
}
|
|
165
165
|
else {
|
|
166
166
|
await db
|
|
167
|
-
.collection(
|
|
167
|
+
.collection('features')
|
|
168
168
|
.createIndex({ name: 1 }, { unique: true });
|
|
169
169
|
}
|
|
170
170
|
},
|
|
171
171
|
down: async ({ context: db }) => {
|
|
172
|
-
await db.collection(
|
|
172
|
+
await db.collection('features').drop();
|
|
173
173
|
},
|
|
174
174
|
});
|
|
175
175
|
if (isAuthEnabled)
|
|
176
176
|
migrations.push({
|
|
177
|
-
name:
|
|
177
|
+
name: '00000000000008_schema-authorizations',
|
|
178
178
|
up: async ({ context: db }) => {
|
|
179
|
-
await db.createCollection(
|
|
179
|
+
await db.createCollection('authorizations');
|
|
180
180
|
if (isMultiTenant) {
|
|
181
181
|
await db
|
|
182
|
-
.collection(
|
|
182
|
+
.collection('authorizations')
|
|
183
183
|
.createIndex({ _orgId: 1, roleId: 1, featureId: 1 }, { unique: true });
|
|
184
|
-
await db.collection(
|
|
184
|
+
await db.collection('authorizations').createIndex({ _orgId: 1 });
|
|
185
185
|
}
|
|
186
186
|
else {
|
|
187
187
|
await db
|
|
188
|
-
.collection(
|
|
188
|
+
.collection('authorizations')
|
|
189
189
|
.createIndex({ roleId: 1, featureId: 1 }, { unique: true });
|
|
190
190
|
}
|
|
191
|
-
await db.collection(
|
|
192
|
-
await db.collection(
|
|
191
|
+
await db.collection('authorizations').createIndex({ roleId: 1 });
|
|
192
|
+
await db.collection('authorizations').createIndex({ featureId: 1 });
|
|
193
193
|
},
|
|
194
194
|
down: async ({ context: db }) => {
|
|
195
|
-
await db.collection(
|
|
195
|
+
await db.collection('authorizations').drop();
|
|
196
196
|
},
|
|
197
197
|
});
|
|
198
198
|
if (isMultiTenant) {
|
|
199
199
|
migrations.push({
|
|
200
|
-
name:
|
|
200
|
+
name: '00000000000009_data-meta-org',
|
|
201
201
|
up: async ({ context: db }) => {
|
|
202
202
|
const metaOrgDoc = {
|
|
203
203
|
name: dbConfig.multiTenant.metaOrgName,
|
|
@@ -207,14 +207,14 @@ export const getMongoInitialSchema = (dbConfig) => {
|
|
|
207
207
|
isMetaOrg: true,
|
|
208
208
|
authToken: undefined,
|
|
209
209
|
_created: new Date(),
|
|
210
|
-
_createdBy:
|
|
210
|
+
_createdBy: 'system',
|
|
211
211
|
_updated: new Date(),
|
|
212
|
-
_updatedBy:
|
|
212
|
+
_updatedBy: 'system',
|
|
213
213
|
_deleted: undefined,
|
|
214
214
|
_deletedBy: undefined,
|
|
215
215
|
};
|
|
216
216
|
const result = await db
|
|
217
|
-
.collection(
|
|
217
|
+
.collection('organizations')
|
|
218
218
|
.insertOne(metaOrgDoc);
|
|
219
219
|
const metaOrgObjectId = result.insertedId;
|
|
220
220
|
const metaOrg = {
|
|
@@ -223,33 +223,33 @@ export const getMongoInitialSchema = (dbConfig) => {
|
|
|
223
223
|
};
|
|
224
224
|
const metaOrgDomains = dbConfig.multiTenant.metaOrgDomains ?? [];
|
|
225
225
|
if (metaOrgDomains.length > 0) {
|
|
226
|
-
await db.collection(
|
|
226
|
+
await db.collection('organizationDomains').insertMany(metaOrgDomains.map((domain) => ({
|
|
227
227
|
organizationId: metaOrgObjectId,
|
|
228
228
|
domain,
|
|
229
229
|
_created: new Date(),
|
|
230
|
-
_createdBy:
|
|
230
|
+
_createdBy: 'system',
|
|
231
231
|
_updated: new Date(),
|
|
232
|
-
_updatedBy:
|
|
232
|
+
_updatedBy: 'system',
|
|
233
233
|
})));
|
|
234
234
|
}
|
|
235
|
-
initializeSystemUserContext(dbConfig.email?.systemEmailAddress ||
|
|
235
|
+
initializeSystemUserContext(dbConfig.email?.systemEmailAddress || 'system@example.com', metaOrg);
|
|
236
236
|
},
|
|
237
237
|
down: async ({ context: db }) => {
|
|
238
|
-
await db.collection(
|
|
239
|
-
await db.collection(
|
|
238
|
+
await db.collection('organizationDomains').deleteMany({});
|
|
239
|
+
await db.collection('organizations').deleteMany({ isMetaOrg: true });
|
|
240
240
|
},
|
|
241
241
|
});
|
|
242
242
|
}
|
|
243
243
|
if (isAuthEnabled && dbConfig.adminUser) {
|
|
244
244
|
migrations.push({
|
|
245
|
-
name:
|
|
245
|
+
name: '00000000000010_data-admin-user',
|
|
246
246
|
up: async ({ context: db }) => {
|
|
247
247
|
if (!isSystemUserContextInitialized()) {
|
|
248
248
|
const errorMessage = isMultiTenant
|
|
249
|
-
?
|
|
250
|
-
|
|
251
|
-
:
|
|
252
|
-
console.error(
|
|
249
|
+
? 'SystemUserContext has not been initialized. The meta-org migration (00000000000009_data-meta-org) should have run before this migration. ' +
|
|
250
|
+
'Please ensure metaOrgName and metaOrgCode are provided in your dbConfig.'
|
|
251
|
+
: 'BUG: SystemUserContext has not been initialized. For non-multi-tenant setups, SystemUserContext should be initialized before migrations run.';
|
|
252
|
+
console.error('❌ Migration Error:', errorMessage);
|
|
253
253
|
throw new Error(errorMessage);
|
|
254
254
|
}
|
|
255
255
|
const systemUserContext = getSystemUserContext();
|
|
@@ -258,29 +258,29 @@ export const getMongoInitialSchema = (dbConfig) => {
|
|
|
258
258
|
: {};
|
|
259
259
|
const hashedPassword = await passwordUtils.hashPassword(dbConfig.adminUser.password);
|
|
260
260
|
const email = dbConfig.adminUser.email.toLowerCase();
|
|
261
|
-
await db.collection(
|
|
261
|
+
await db.collection('users').insertOne({
|
|
262
262
|
...orgDoc,
|
|
263
263
|
email,
|
|
264
264
|
password: hashedPassword,
|
|
265
|
-
displayName:
|
|
265
|
+
displayName: 'Admin User',
|
|
266
266
|
_created: new Date(),
|
|
267
|
-
_createdBy:
|
|
267
|
+
_createdBy: 'system',
|
|
268
268
|
_updated: new Date(),
|
|
269
|
-
_updatedBy:
|
|
269
|
+
_updatedBy: 'system',
|
|
270
270
|
});
|
|
271
271
|
},
|
|
272
272
|
down: async ({ context: db }) => {
|
|
273
273
|
if (!dbConfig?.adminUser?.email)
|
|
274
274
|
return;
|
|
275
275
|
await db
|
|
276
|
-
.collection(
|
|
276
|
+
.collection('users')
|
|
277
277
|
.deleteOne({ email: dbConfig.adminUser.email.toLowerCase() });
|
|
278
278
|
},
|
|
279
279
|
});
|
|
280
280
|
}
|
|
281
281
|
if (isAuthEnabled && dbConfig.adminUser) {
|
|
282
282
|
migrations.push({
|
|
283
|
-
name:
|
|
283
|
+
name: '00000000000011_data-admin-authorizations',
|
|
284
284
|
up: async ({ context: db }) => {
|
|
285
285
|
const database = new MongoDBDatabase(db);
|
|
286
286
|
const organizationService = new OrganizationService(database);
|
|
@@ -288,36 +288,36 @@ export const getMongoInitialSchema = (dbConfig) => {
|
|
|
288
288
|
? await organizationService.getMetaOrg(EmptyUserContext)
|
|
289
289
|
: undefined;
|
|
290
290
|
if (isMultiTenant && !metaOrg) {
|
|
291
|
-
throw new Error(
|
|
291
|
+
throw new Error('Meta organization not found. Ensure meta-org migration ran successfully.');
|
|
292
292
|
}
|
|
293
293
|
const email = dbConfig.adminUser.email.toLowerCase();
|
|
294
|
-
const adminUser = await db.collection(
|
|
294
|
+
const adminUser = await db.collection('users').findOne({ email });
|
|
295
295
|
if (!adminUser) {
|
|
296
|
-
throw new Error(
|
|
296
|
+
throw new Error('Admin user not found. Ensure admin-user migration ran successfully.');
|
|
297
297
|
}
|
|
298
298
|
const orgDoc = isMultiTenant && metaOrg?._id
|
|
299
299
|
? { _orgId: String(metaOrg._id) }
|
|
300
300
|
: {};
|
|
301
|
-
const roleResult = await db.collection(
|
|
301
|
+
const roleResult = await db.collection('roles').insertOne({
|
|
302
302
|
...orgDoc,
|
|
303
|
-
name:
|
|
303
|
+
name: 'admin',
|
|
304
304
|
});
|
|
305
|
-
await db.collection(
|
|
305
|
+
await db.collection('userRoles').insertOne({
|
|
306
306
|
...orgDoc,
|
|
307
307
|
userId: adminUser._id,
|
|
308
308
|
roleId: roleResult.insertedId,
|
|
309
309
|
_created: new Date(),
|
|
310
|
-
_createdBy:
|
|
310
|
+
_createdBy: 'system',
|
|
311
311
|
_updated: new Date(),
|
|
312
|
-
_updatedBy:
|
|
312
|
+
_updatedBy: 'system',
|
|
313
313
|
_deleted: undefined,
|
|
314
314
|
_deletedBy: undefined,
|
|
315
315
|
});
|
|
316
|
-
const featureResult = await db.collection(
|
|
316
|
+
const featureResult = await db.collection('features').insertOne({
|
|
317
317
|
...orgDoc,
|
|
318
|
-
name:
|
|
318
|
+
name: 'admin',
|
|
319
319
|
});
|
|
320
|
-
await db.collection(
|
|
320
|
+
await db.collection('authorizations').insertOne({
|
|
321
321
|
...orgDoc,
|
|
322
322
|
roleId: roleResult.insertedId,
|
|
323
323
|
featureId: featureResult.insertedId,
|
|
@@ -325,9 +325,9 @@ export const getMongoInitialSchema = (dbConfig) => {
|
|
|
325
325
|
endDate: undefined,
|
|
326
326
|
config: undefined,
|
|
327
327
|
_created: new Date(),
|
|
328
|
-
_createdBy:
|
|
328
|
+
_createdBy: 'system',
|
|
329
329
|
_updated: new Date(),
|
|
330
|
-
_updatedBy:
|
|
330
|
+
_updatedBy: 'system',
|
|
331
331
|
_deleted: undefined,
|
|
332
332
|
_deletedBy: undefined,
|
|
333
333
|
});
|
|
@@ -344,30 +344,30 @@ export const getMongoInitialSchema = (dbConfig) => {
|
|
|
344
344
|
? { _orgId: String(metaOrg._id) }
|
|
345
345
|
: {};
|
|
346
346
|
const adminRole = await db
|
|
347
|
-
.collection(
|
|
348
|
-
.findOne({ ...orgFilter, name:
|
|
347
|
+
.collection('roles')
|
|
348
|
+
.findOne({ ...orgFilter, name: 'admin' });
|
|
349
349
|
const adminFeature = await db
|
|
350
|
-
.collection(
|
|
351
|
-
.findOne({ ...orgFilter, name:
|
|
350
|
+
.collection('features')
|
|
351
|
+
.findOne({ ...orgFilter, name: 'admin' });
|
|
352
352
|
if (adminRole && adminFeature) {
|
|
353
|
-
await db.collection(
|
|
353
|
+
await db.collection('authorizations').deleteMany({
|
|
354
354
|
...orgFilter,
|
|
355
355
|
roleId: adminRole._id,
|
|
356
356
|
featureId: adminFeature._id,
|
|
357
357
|
});
|
|
358
358
|
}
|
|
359
359
|
await db
|
|
360
|
-
.collection(
|
|
361
|
-
.deleteMany({ ...orgFilter, name:
|
|
360
|
+
.collection('features')
|
|
361
|
+
.deleteMany({ ...orgFilter, name: 'admin' });
|
|
362
362
|
if (adminRole) {
|
|
363
|
-
await db.collection(
|
|
363
|
+
await db.collection('userRoles').deleteMany({
|
|
364
364
|
...orgFilter,
|
|
365
365
|
roleId: adminRole._id,
|
|
366
366
|
});
|
|
367
367
|
}
|
|
368
368
|
await db
|
|
369
|
-
.collection(
|
|
370
|
-
.deleteMany({ ...orgFilter, name:
|
|
369
|
+
.collection('roles')
|
|
370
|
+
.deleteMany({ ...orgFilter, name: 'admin' });
|
|
371
371
|
},
|
|
372
372
|
});
|
|
373
373
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Document } from
|
|
2
|
-
import { IQueryOptions, IModelSpec } from
|
|
3
|
-
import { Operation } from
|
|
4
|
-
import { INoSqlPipeline } from
|
|
1
|
+
import { Document } from 'mongodb';
|
|
2
|
+
import { IQueryOptions, IModelSpec } from '@loomcore/common/models';
|
|
3
|
+
import { Operation } from '../../operations/operation.js';
|
|
4
|
+
import { INoSqlPipeline } from './no-sql-pipeline.interface.js';
|
|
5
5
|
declare class NoSqlPipeline implements INoSqlPipeline {
|
|
6
6
|
private pipeline;
|
|
7
7
|
constructor(pipeline?: Document[] | null);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Document } from
|
|
2
|
-
import { IQueryOptions, IModelSpec } from
|
|
3
|
-
import { Operation } from
|
|
1
|
+
import { Document } from 'mongodb';
|
|
2
|
+
import { IQueryOptions, IModelSpec } from '@loomcore/common/models';
|
|
3
|
+
import { Operation } from '../../operations/operation.js';
|
|
4
4
|
export interface INoSqlPipeline {
|
|
5
5
|
addStage(stage: Document): INoSqlPipeline;
|
|
6
6
|
addStages(stages: Document[]): INoSqlPipeline;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { buildNoSqlMatch, convertOperationsToPipeline, convertQueryOptionsToPipeline } from
|
|
1
|
+
import { buildNoSqlMatch, convertOperationsToPipeline, convertQueryOptionsToPipeline } from '../utils/index.js';
|
|
2
2
|
class NoSqlPipeline {
|
|
3
3
|
pipeline;
|
|
4
4
|
constructor(pipeline = null) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Db, MongoClient } from
|
|
2
|
-
import { IModelSpec, IQueryOptions, IPagedResult, IEntity } from
|
|
3
|
-
import type { AppIdType } from
|
|
4
|
-
import { Operation } from
|
|
5
|
-
import { DeleteResult as GenericDeleteResult } from
|
|
6
|
-
import { TSchema } from
|
|
7
|
-
import { IDatabase } from
|
|
1
|
+
import { Db, MongoClient } from 'mongodb';
|
|
2
|
+
import { IModelSpec, IQueryOptions, IPagedResult, IEntity } from '@loomcore/common/models';
|
|
3
|
+
import type { AppIdType } from '@loomcore/common/types';
|
|
4
|
+
import { Operation } from '../operations/operation.js';
|
|
5
|
+
import { DeleteResult as GenericDeleteResult } from '../models/delete-result.js';
|
|
6
|
+
import { TSchema } from '@sinclair/typebox';
|
|
7
|
+
import { IDatabase } from '../models/database.interface.js';
|
|
8
8
|
export declare class MongoDBDatabase implements IDatabase {
|
|
9
9
|
private db;
|
|
10
10
|
private mongoClient?;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { convertObjectIdsToStrings, convertStringsToObjectIds } from
|
|
2
|
-
import { create, createMany, batchUpdate, fullUpdateById, partialUpdateById, update, deleteById, deleteMany } from
|
|
3
|
-
import { getAll, get, getById, getCount, find, findOne } from
|
|
4
|
-
import { entityUtils } from
|
|
5
|
-
import { BadRequestError } from
|
|
1
|
+
import { convertObjectIdsToStrings, convertStringsToObjectIds } from './utils/index.js';
|
|
2
|
+
import { create, createMany, batchUpdate, fullUpdateById, partialUpdateById, update, deleteById, deleteMany } from './commands/index.js';
|
|
3
|
+
import { getAll, get, getById, getCount, find, findOne } from './queries/index.js';
|
|
4
|
+
import { entityUtils } from '@loomcore/common/utils';
|
|
5
|
+
import { BadRequestError } from '../../errors/bad-request.error.js';
|
|
6
6
|
export class MongoDBDatabase {
|
|
7
7
|
db;
|
|
8
8
|
mongoClient;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Db } from
|
|
2
|
-
import { IQueryOptions } from
|
|
1
|
+
import { Db } from 'mongodb';
|
|
2
|
+
import { IQueryOptions } from '@loomcore/common/models';
|
|
3
3
|
export declare function findOne<T>(db: Db, queryObject: IQueryOptions, pluralResourceName: string): Promise<T | null>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { buildNoSqlMatch, buildFindOptions } from
|
|
1
|
+
import { buildNoSqlMatch, buildFindOptions } from '../utils/index.js';
|
|
2
2
|
export async function findOne(db, queryObject, pluralResourceName) {
|
|
3
3
|
const collection = db.collection(pluralResourceName);
|
|
4
4
|
const matchDocument = buildNoSqlMatch(queryObject);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Db } from
|
|
2
|
-
import { IQueryOptions } from
|
|
1
|
+
import { Db } from 'mongodb';
|
|
2
|
+
import { IQueryOptions } from '@loomcore/common/models';
|
|
3
3
|
export declare function find<T>(db: Db, queryObject: IQueryOptions, pluralResourceName: string): Promise<T[]>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { buildNoSqlMatch, buildFindOptions } from
|
|
1
|
+
import { buildNoSqlMatch, buildFindOptions } from '../utils/index.js';
|
|
2
2
|
export async function find(db, queryObject, pluralResourceName) {
|
|
3
3
|
const collection = db.collection(pluralResourceName);
|
|
4
4
|
const matchDocument = buildNoSqlMatch(queryObject);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Db } from
|
|
2
|
-
import { Operation } from
|
|
1
|
+
import { Db } from 'mongodb';
|
|
2
|
+
import { Operation } from '../../operations/operation.js';
|
|
3
3
|
export declare function getAll<T>(db: Db, operations: Operation[], pluralResourceName: string): Promise<T[]>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import NoSqlPipeline from
|
|
1
|
+
import NoSqlPipeline from '../models/no-sql-pipeline.js';
|
|
2
2
|
export async function getAll(db, operations, pluralResourceName) {
|
|
3
3
|
const collection = db.collection(pluralResourceName);
|
|
4
4
|
const pipeline = new NoSqlPipeline()
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Db } from
|
|
2
|
-
import { Operation } from
|
|
3
|
-
import { IQueryOptions } from
|
|
4
|
-
import type { AppIdType } from
|
|
1
|
+
import { Db } from 'mongodb';
|
|
2
|
+
import { Operation } from '../../operations/operation.js';
|
|
3
|
+
import { IQueryOptions } from '@loomcore/common/models';
|
|
4
|
+
import type { AppIdType } from '@loomcore/common/types';
|
|
5
5
|
export declare function getById<T>(db: Db, operations: Operation[], queryObject: IQueryOptions, id: AppIdType, pluralResourceName: string): Promise<T | null>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { entityUtils } from
|
|
2
|
-
import { BadRequestError } from
|
|
3
|
-
import NoSqlPipeline from
|
|
1
|
+
import { entityUtils } from '@loomcore/common/utils';
|
|
2
|
+
import { BadRequestError } from '../../../errors/index.js';
|
|
3
|
+
import NoSqlPipeline from '../models/no-sql-pipeline.js';
|
|
4
4
|
export async function getById(db, operations, queryObject, id, pluralResourceName) {
|
|
5
5
|
if (!entityUtils.isValidObjectId(id)) {
|
|
6
6
|
throw new BadRequestError('id is not a valid ObjectId');
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Db } from
|
|
1
|
+
import { Db } from 'mongodb';
|
|
2
2
|
export declare function getCount(db: Db, pluralResourceName: string): Promise<number>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Db } from
|
|
2
|
-
import { IModelSpec, IQueryOptions, IPagedResult } from
|
|
3
|
-
import { Operation } from
|
|
1
|
+
import { Db } from 'mongodb';
|
|
2
|
+
import { IModelSpec, IQueryOptions, IPagedResult } from '@loomcore/common/models';
|
|
3
|
+
import { Operation } from '../../operations/operation.js';
|
|
4
4
|
export declare function get<T>(db: Db, operations: Operation[], queryOptions: IQueryOptions, modelSpec: IModelSpec, pluralResourceName: string): Promise<IPagedResult<T>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import NoSqlPipeline from
|
|
2
|
-
import { apiUtils } from
|
|
1
|
+
import NoSqlPipeline from '../models/no-sql-pipeline.js';
|
|
2
|
+
import { apiUtils } from '../../../utils/api.utils.js';
|
|
3
3
|
export async function get(db, operations, queryOptions, modelSpec, pluralResourceName) {
|
|
4
4
|
const collection = db.collection(pluralResourceName);
|
|
5
5
|
const pipeline = new NoSqlPipeline()
|