@aneuhold/be-ts-db-lib 1.0.115 → 2.0.20

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.
Files changed (150) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +46 -10
  3. package/lib/index.d.ts +8 -8
  4. package/lib/index.d.ts.map +1 -1
  5. package/lib/index.js +10 -20
  6. package/lib/index.js.map +1 -0
  7. package/lib/index.ts +21 -0
  8. package/lib/repositories/BaseRepository.d.ts +84 -11
  9. package/lib/repositories/BaseRepository.d.ts.map +1 -1
  10. package/lib/repositories/BaseRepository.js +89 -21
  11. package/lib/repositories/BaseRepository.js.map +1 -0
  12. package/lib/repositories/BaseRepository.ts +339 -0
  13. package/lib/repositories/common/ApiKeyRepository.d.ts +2 -2
  14. package/lib/repositories/common/ApiKeyRepository.d.ts.map +1 -1
  15. package/lib/repositories/common/ApiKeyRepository.js +8 -13
  16. package/lib/repositories/common/ApiKeyRepository.js.map +1 -0
  17. package/lib/repositories/common/ApiKeyRepository.ts +55 -0
  18. package/lib/repositories/common/UserRepository.d.ts +1 -1
  19. package/lib/repositories/common/UserRepository.d.ts.map +1 -1
  20. package/lib/repositories/common/UserRepository.js +15 -20
  21. package/lib/repositories/common/UserRepository.js.map +1 -0
  22. package/lib/repositories/common/UserRepository.ts +65 -0
  23. package/lib/repositories/dashboard/DashboardBaseRepository.d.ts +2 -2
  24. package/lib/repositories/dashboard/DashboardBaseRepository.d.ts.map +1 -1
  25. package/lib/repositories/dashboard/DashboardBaseRepository.js +6 -11
  26. package/lib/repositories/dashboard/DashboardBaseRepository.js.map +1 -0
  27. package/lib/repositories/dashboard/DashboardBaseRepository.ts +31 -0
  28. package/lib/repositories/dashboard/DashboardNonogramKatanaItemRepository.d.ts +2 -2
  29. package/lib/repositories/dashboard/DashboardNonogramKatanaItemRepository.d.ts.map +1 -1
  30. package/lib/repositories/dashboard/DashboardNonogramKatanaItemRepository.js +7 -12
  31. package/lib/repositories/dashboard/DashboardNonogramKatanaItemRepository.js.map +1 -0
  32. package/lib/repositories/dashboard/DashboardNonogramKatanaItemRepository.ts +64 -0
  33. package/lib/repositories/dashboard/DashboardNonogramKatanaUpgradeRepository.d.ts +2 -2
  34. package/lib/repositories/dashboard/DashboardNonogramKatanaUpgradeRepository.d.ts.map +1 -1
  35. package/lib/repositories/dashboard/DashboardNonogramKatanaUpgradeRepository.js +7 -12
  36. package/lib/repositories/dashboard/DashboardNonogramKatanaUpgradeRepository.js.map +1 -0
  37. package/lib/repositories/dashboard/DashboardNonogramKatanaUpgradeRepository.ts +66 -0
  38. package/lib/repositories/dashboard/DashboardTaskRepository.d.ts +17 -4
  39. package/lib/repositories/dashboard/DashboardTaskRepository.d.ts.map +1 -1
  40. package/lib/repositories/dashboard/DashboardTaskRepository.js +26 -18
  41. package/lib/repositories/dashboard/DashboardTaskRepository.js.map +1 -0
  42. package/lib/repositories/dashboard/DashboardTaskRepository.ts +166 -0
  43. package/lib/repositories/dashboard/DashboardUserConfigRepository.d.ts +29 -5
  44. package/lib/repositories/dashboard/DashboardUserConfigRepository.d.ts.map +1 -1
  45. package/lib/repositories/dashboard/DashboardUserConfigRepository.js +38 -19
  46. package/lib/repositories/dashboard/DashboardUserConfigRepository.js.map +1 -0
  47. package/lib/repositories/dashboard/DashboardUserConfigRepository.ts +254 -0
  48. package/lib/services/MigrationService.d.ts.map +1 -1
  49. package/lib/services/MigrationService.js +10 -15
  50. package/lib/services/MigrationService.js.map +1 -0
  51. package/lib/services/MigrationService.ts +52 -0
  52. package/lib/services/RepoSubscriptionService.d.ts.map +1 -1
  53. package/lib/services/RepoSubscriptionService.js +2 -4
  54. package/lib/services/RepoSubscriptionService.js.map +1 -0
  55. package/lib/services/RepoSubscriptionService.ts +63 -0
  56. package/lib/tests/globalTestVariables.d.ts +5 -0
  57. package/lib/tests/globalTestVariables.d.ts.map +1 -0
  58. package/lib/tests/globalTestVariables.js +5 -0
  59. package/lib/tests/globalTestVariables.js.map +1 -0
  60. package/lib/tests/globalTestVariables.ts +4 -0
  61. package/lib/tests/repositories/BaseRepository.spec.ts +61 -0
  62. package/lib/tests/repositories/common/UserRepository.spec.ts +113 -0
  63. package/lib/tests/repositories/dashboard/NonogramKatanaItemRepository.spec.ts +55 -0
  64. package/lib/tests/repositories/dashboard/NonogramKatanaUpgradeRepository.spec.ts +14 -0
  65. package/lib/tests/repositories/dashboard/TaskRepository.spec.ts +101 -0
  66. package/lib/tests/repositories/dashboard/UserConfigRepository.spec.ts +155 -0
  67. package/lib/tests/testsUtil.d.ts +20 -4
  68. package/lib/tests/testsUtil.d.ts.map +1 -1
  69. package/lib/tests/testsUtil.js +29 -20
  70. package/lib/tests/testsUtil.js.map +1 -0
  71. package/lib/tests/testsUtil.ts +68 -0
  72. package/lib/util/DbSchemaUpdater.d.ts.map +1 -1
  73. package/lib/util/DbSchemaUpdater.js +10 -15
  74. package/lib/util/DbSchemaUpdater.js.map +1 -0
  75. package/lib/util/DbSchemaUpdater.ts +16 -0
  76. package/lib/util/DocumentCleaner.d.ts.map +1 -1
  77. package/lib/util/DocumentCleaner.js +2 -4
  78. package/lib/util/DocumentCleaner.js.map +1 -0
  79. package/lib/util/DocumentCleaner.ts +31 -0
  80. package/lib/util/DocumentDb.d.ts +4 -1
  81. package/lib/util/DocumentDb.d.ts.map +1 -1
  82. package/lib/util/DocumentDb.js +11 -10
  83. package/lib/util/DocumentDb.js.map +1 -0
  84. package/lib/util/DocumentDb.ts +47 -0
  85. package/lib/validators/BaseValidator.d.ts +11 -0
  86. package/lib/validators/BaseValidator.d.ts.map +1 -1
  87. package/lib/validators/BaseValidator.js +26 -18
  88. package/lib/validators/BaseValidator.js.map +1 -0
  89. package/lib/validators/BaseValidator.ts +150 -0
  90. package/lib/validators/common/ApiKeyValidator.d.ts +1 -1
  91. package/lib/validators/common/ApiKeyValidator.d.ts.map +1 -1
  92. package/lib/validators/common/ApiKeyValidator.js +16 -21
  93. package/lib/validators/common/ApiKeyValidator.js.map +1 -0
  94. package/lib/validators/common/ApiKeyValidator.ts +67 -0
  95. package/lib/validators/common/UserValidator.d.ts +14 -1
  96. package/lib/validators/common/UserValidator.d.ts.map +1 -1
  97. package/lib/validators/common/UserValidator.js +29 -21
  98. package/lib/validators/common/UserValidator.js.map +1 -0
  99. package/lib/validators/common/UserValidator.ts +98 -0
  100. package/lib/validators/dashboard/NonogramKatanaItemValidator.d.ts +1 -1
  101. package/lib/validators/dashboard/NonogramKatanaItemValidator.d.ts.map +1 -1
  102. package/lib/validators/dashboard/NonogramKatanaItemValidator.js +16 -21
  103. package/lib/validators/dashboard/NonogramKatanaItemValidator.js.map +1 -0
  104. package/lib/validators/dashboard/NonogramKatanaItemValidator.ts +78 -0
  105. package/lib/validators/dashboard/NonogramKatanaUpgradeValidator.d.ts +1 -1
  106. package/lib/validators/dashboard/NonogramKatanaUpgradeValidator.d.ts.map +1 -1
  107. package/lib/validators/dashboard/NonogramKatanaUpgradeValidator.js +16 -21
  108. package/lib/validators/dashboard/NonogramKatanaUpgradeValidator.js.map +1 -0
  109. package/lib/validators/dashboard/NonogramKatanaUpgradeValidator.ts +78 -0
  110. package/lib/validators/dashboard/TaskValidator.d.ts +1 -1
  111. package/lib/validators/dashboard/TaskValidator.d.ts.map +1 -1
  112. package/lib/validators/dashboard/TaskValidator.js +15 -20
  113. package/lib/validators/dashboard/TaskValidator.js.map +1 -0
  114. package/lib/validators/dashboard/TaskValidator.ts +105 -0
  115. package/lib/validators/dashboard/UserConfigValidator.d.ts +1 -1
  116. package/lib/validators/dashboard/UserConfigValidator.d.ts.map +1 -1
  117. package/lib/validators/dashboard/UserConfigValidator.js +19 -24
  118. package/lib/validators/dashboard/UserConfigValidator.js.map +1 -0
  119. package/lib/validators/dashboard/UserConfigValidator.ts +112 -0
  120. package/package.json +47 -41
  121. package/lib/scripts/migrate.d.ts +0 -2
  122. package/lib/scripts/migrate.d.ts.map +0 -1
  123. package/lib/scripts/migrate.js +0 -7
  124. package/lib/scripts/migrateDry.d.ts +0 -2
  125. package/lib/scripts/migrateDry.d.ts.map +0 -1
  126. package/lib/scripts/migrateDry.js +0 -7
  127. package/lib/scripts/validateSchema.d.ts +0 -2
  128. package/lib/scripts/validateSchema.d.ts.map +0 -1
  129. package/lib/scripts/validateSchema.js +0 -9
  130. package/lib/scripts/validateSchemaDryRun.d.ts +0 -2
  131. package/lib/scripts/validateSchemaDryRun.d.ts.map +0 -1
  132. package/lib/scripts/validateSchemaDryRun.js +0 -9
  133. package/lib/tests/repositories/BaseRepository.spec.d.ts +0 -2
  134. package/lib/tests/repositories/BaseRepository.spec.d.ts.map +0 -1
  135. package/lib/tests/repositories/BaseRepository.spec.js +0 -52
  136. package/lib/tests/repositories/common/UserRepository.spec.d.ts +0 -2
  137. package/lib/tests/repositories/common/UserRepository.spec.d.ts.map +0 -1
  138. package/lib/tests/repositories/common/UserRepository.spec.js +0 -108
  139. package/lib/tests/repositories/dashboard/NonogramKatanaItemRepository.spec.d.ts +0 -2
  140. package/lib/tests/repositories/dashboard/NonogramKatanaItemRepository.spec.d.ts.map +0 -1
  141. package/lib/tests/repositories/dashboard/NonogramKatanaItemRepository.spec.js +0 -39
  142. package/lib/tests/repositories/dashboard/NonogramKatanaUpgradeRepository.spec.d.ts +0 -2
  143. package/lib/tests/repositories/dashboard/NonogramKatanaUpgradeRepository.spec.d.ts.map +0 -1
  144. package/lib/tests/repositories/dashboard/NonogramKatanaUpgradeRepository.spec.js +0 -16
  145. package/lib/tests/repositories/dashboard/TaskRepository.spec.d.ts +0 -2
  146. package/lib/tests/repositories/dashboard/TaskRepository.spec.d.ts.map +0 -1
  147. package/lib/tests/repositories/dashboard/TaskRepository.spec.js +0 -84
  148. package/lib/tests/repositories/dashboard/UserConfigRepository.spec.d.ts +0 -2
  149. package/lib/tests/repositories/dashboard/UserConfigRepository.spec.d.ts.map +0 -1
  150. package/lib/tests/repositories/dashboard/UserConfigRepository.spec.js +0 -115
@@ -0,0 +1,78 @@
1
+ import {
2
+ NonogramKatanaItem,
3
+ validateNonogramKatanaItem
4
+ } from '@aneuhold/core-ts-db-lib';
5
+ import { ErrorUtils, Logger } from '@aneuhold/core-ts-lib';
6
+ import { ObjectId } from 'bson';
7
+ import UserRepository from '../../repositories/common/UserRepository.js';
8
+ import DashboardNonogramKatanaItemRepository from '../../repositories/dashboard/DashboardNonogramKatanaItemRepository.js';
9
+ import IValidator from '../BaseValidator.js';
10
+
11
+ export default class DashboardNonogramKatanaItemValidator extends IValidator<NonogramKatanaItem> {
12
+ async validateNewObject(newItem: NonogramKatanaItem): Promise<void> {
13
+ // Check if the item already exists for the user
14
+ const itemRepo = DashboardNonogramKatanaItemRepository.getRepo();
15
+ const existingItem = await itemRepo.get({
16
+ userId: newItem.userId,
17
+ itemName: newItem.itemName
18
+ });
19
+ if (existingItem) {
20
+ ErrorUtils.throwError(
21
+ `Nonogram Katana item already exists for user: ${newItem.userId.toString()}`,
22
+ newItem
23
+ );
24
+ }
25
+ const userRepo = UserRepository.getRepo();
26
+ const user = await userRepo.get({ _id: newItem.userId });
27
+ if (!user) {
28
+ ErrorUtils.throwError(
29
+ `User does not exist: ${newItem.userId.toString()}`,
30
+ newItem
31
+ );
32
+ }
33
+ }
34
+
35
+ // eslint-disable-next-line @typescript-eslint/require-await
36
+ async validateUpdateObject(
37
+ updatedItem: Partial<NonogramKatanaItem>
38
+ ): Promise<void> {
39
+ // Check if an id is defined
40
+ if (!updatedItem._id) {
41
+ ErrorUtils.throwError(
42
+ `No _id defined for NonogramKatanaItem update.`,
43
+ updatedItem
44
+ );
45
+ }
46
+ }
47
+
48
+ async validateRepositoryInDb(dryRun: boolean): Promise<void> {
49
+ const itemRepo = DashboardNonogramKatanaItemRepository.getRepo();
50
+ const allItems = await itemRepo.getAll();
51
+ const allUserIds = await UserRepository.getRepo().getAllIdsAsHash();
52
+
53
+ await this.runStandardValidationForRepository({
54
+ dryRun,
55
+ docName: 'Nonogram Katana Item',
56
+ allDocs: allItems,
57
+ shouldDelete: (item: NonogramKatanaItem) => {
58
+ if (!allUserIds[item.userId.toString()]) {
59
+ Logger.error(
60
+ `Nonogram Katana Item with ID: ${item._id.toString()} has no valid associated user.`
61
+ );
62
+ return true;
63
+ }
64
+ return false;
65
+ },
66
+ documentValidator: (item) => {
67
+ const { updatedDoc, errors } = validateNonogramKatanaItem(item);
68
+ return { updatedDoc, errors };
69
+ },
70
+ deletionFunction: async (docIdsToDelete: ObjectId[]) => {
71
+ await itemRepo.deleteList(docIdsToDelete);
72
+ },
73
+ updateFunction: async (docsToUpdate: NonogramKatanaItem[]) => {
74
+ await itemRepo.updateMany(docsToUpdate);
75
+ }
76
+ });
77
+ }
78
+ }
@@ -1,5 +1,5 @@
1
1
  import { NonogramKatanaUpgrade } from '@aneuhold/core-ts-db-lib';
2
- import IValidator from '../BaseValidator';
2
+ import IValidator from '../BaseValidator.js';
3
3
  export default class DashboardNonogramKatanaUpgradeValidator extends IValidator<NonogramKatanaUpgrade> {
4
4
  validateNewObject(newUpgrade: NonogramKatanaUpgrade): Promise<void>;
5
5
  validateUpdateObject(updatedUpgrade: Partial<NonogramKatanaUpgrade>): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"NonogramKatanaUpgradeValidator.d.ts","sourceRoot":"","sources":["../../../src/validators/dashboard/NonogramKatanaUpgradeValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EAEtB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAI1C,MAAM,CAAC,OAAO,OAAO,uCAAwC,SAAQ,UAAU,CAAC,qBAAqB,CAAC;IAC9F,iBAAiB,CAAC,UAAU,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;IAwBnE,oBAAoB,CACxB,cAAc,EAAE,OAAO,CAAC,qBAAqB,CAAC,GAC7C,OAAO,CAAC,IAAI,CAAC;IAUV,sBAAsB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CA8B7D"}
1
+ {"version":3,"file":"NonogramKatanaUpgradeValidator.d.ts","sourceRoot":"./src/","sources":["validators/dashboard/NonogramKatanaUpgradeValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EAEtB,MAAM,0BAA0B,CAAC;AAKlC,OAAO,UAAU,MAAM,qBAAqB,CAAC;AAE7C,MAAM,CAAC,OAAO,OAAO,uCAAwC,SAAQ,UAAU,CAAC,qBAAqB,CAAC;IAC9F,iBAAiB,CAAC,UAAU,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;IAwBnE,oBAAoB,CACxB,cAAc,EAAE,OAAO,CAAC,qBAAqB,CAAC,GAC7C,OAAO,CAAC,IAAI,CAAC;IAUV,sBAAsB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CA8B7D"}
@@ -1,54 +1,49 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const core_ts_db_lib_1 = require("@aneuhold/core-ts-db-lib");
7
- const core_ts_lib_1 = require("@aneuhold/core-ts-lib");
8
- const BaseValidator_1 = __importDefault(require("../BaseValidator"));
9
- const UserRepository_1 = __importDefault(require("../../repositories/common/UserRepository"));
10
- const DashboardNonogramKatanaUpgradeRepository_1 = __importDefault(require("../../repositories/dashboard/DashboardNonogramKatanaUpgradeRepository"));
11
- class DashboardNonogramKatanaUpgradeValidator extends BaseValidator_1.default {
1
+ import { validateNonogramKatanaUpgrade } from '@aneuhold/core-ts-db-lib';
2
+ import { ErrorUtils, Logger } from '@aneuhold/core-ts-lib';
3
+ import UserRepository from '../../repositories/common/UserRepository.js';
4
+ import DashboardNonogramKatanaUpgradeRepository from '../../repositories/dashboard/DashboardNonogramKatanaUpgradeRepository.js';
5
+ import IValidator from '../BaseValidator.js';
6
+ export default class DashboardNonogramKatanaUpgradeValidator extends IValidator {
12
7
  async validateNewObject(newUpgrade) {
13
8
  // Check if the item already exists for the user
14
- const upgradeRepo = DashboardNonogramKatanaUpgradeRepository_1.default.getRepo();
9
+ const upgradeRepo = DashboardNonogramKatanaUpgradeRepository.getRepo();
15
10
  const existingItem = await upgradeRepo.get({
16
11
  userId: newUpgrade.userId,
17
12
  upgradeName: newUpgrade.upgradeName
18
13
  });
19
14
  if (existingItem) {
20
- core_ts_lib_1.ErrorUtils.throwError(`Nonogram Katana upgrade already exists for user: ${newUpgrade.userId.toString()}`, newUpgrade);
15
+ ErrorUtils.throwError(`Nonogram Katana upgrade already exists for user: ${newUpgrade.userId.toString()}`, newUpgrade);
21
16
  }
22
- const userRepo = UserRepository_1.default.getRepo();
17
+ const userRepo = UserRepository.getRepo();
23
18
  const user = await userRepo.get({ _id: newUpgrade.userId });
24
19
  if (!user) {
25
- core_ts_lib_1.ErrorUtils.throwError(`User does not exist: ${newUpgrade.userId.toString()}`, newUpgrade);
20
+ ErrorUtils.throwError(`User does not exist: ${newUpgrade.userId.toString()}`, newUpgrade);
26
21
  }
27
22
  }
28
23
  // eslint-disable-next-line @typescript-eslint/require-await
29
24
  async validateUpdateObject(updatedUpgrade) {
30
25
  // Check if an id is defined
31
26
  if (!updatedUpgrade._id) {
32
- core_ts_lib_1.ErrorUtils.throwError(`No _id defined for NonogramKatanaUpgrade update.`, updatedUpgrade);
27
+ ErrorUtils.throwError(`No _id defined for NonogramKatanaUpgrade update.`, updatedUpgrade);
33
28
  }
34
29
  }
35
30
  async validateRepositoryInDb(dryRun) {
36
- const upgradeRepo = DashboardNonogramKatanaUpgradeRepository_1.default.getRepo();
31
+ const upgradeRepo = DashboardNonogramKatanaUpgradeRepository.getRepo();
37
32
  const allUpgrades = await upgradeRepo.getAll();
38
- const allUserIds = await UserRepository_1.default.getRepo().getAllIdsAsHash();
33
+ const allUserIds = await UserRepository.getRepo().getAllIdsAsHash();
39
34
  await this.runStandardValidationForRepository({
40
35
  dryRun,
41
36
  docName: 'Nonogram Katana Upgrade',
42
37
  allDocs: allUpgrades,
43
38
  shouldDelete: (upgrade) => {
44
39
  if (!allUserIds[upgrade.userId.toString()]) {
45
- core_ts_lib_1.Logger.error(`Nonogram Katana Upgrade with ID: ${upgrade._id.toString()} has no valid associated user.`);
40
+ Logger.error(`Nonogram Katana Upgrade with ID: ${upgrade._id.toString()} has no valid associated user.`);
46
41
  return true;
47
42
  }
48
43
  return false;
49
44
  },
50
45
  documentValidator: (upgrade) => {
51
- const { updatedDoc, errors } = (0, core_ts_db_lib_1.validateNonogramKatanaUpgrade)(upgrade);
46
+ const { updatedDoc, errors } = validateNonogramKatanaUpgrade(upgrade);
52
47
  return { updatedDoc, errors };
53
48
  },
54
49
  deletionFunction: async (docIdsToDelete) => {
@@ -60,4 +55,4 @@ class DashboardNonogramKatanaUpgradeValidator extends BaseValidator_1.default {
60
55
  });
61
56
  }
62
57
  }
63
- exports.default = DashboardNonogramKatanaUpgradeValidator;
58
+ //# sourceMappingURL=NonogramKatanaUpgradeValidator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NonogramKatanaUpgradeValidator.js","sourceRoot":"./src/","sources":["validators/dashboard/NonogramKatanaUpgradeValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,6BAA6B,EAC9B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,cAAc,MAAM,6CAA6C,CAAC;AACzE,OAAO,wCAAwC,MAAM,0EAA0E,CAAC;AAChI,OAAO,UAAU,MAAM,qBAAqB,CAAC;AAE7C,MAAM,CAAC,OAAO,OAAO,uCAAwC,SAAQ,UAAiC;IACpG,KAAK,CAAC,iBAAiB,CAAC,UAAiC;QACvD,gDAAgD;QAChD,MAAM,WAAW,GAAG,wCAAwC,CAAC,OAAO,EAAE,CAAC;QACvE,MAAM,YAAY,GAAG,MAAM,WAAW,CAAC,GAAG,CAAC;YACzC,MAAM,EAAE,UAAU,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KAAK,CACV,oCAAoC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,gCAAgC,CAC3F,CAAC;oBACF,OAAO,IAAI,CAAC;gBACd,CAAC;gBACD,OAAO,KAAK,CAAC;YACf,CAAC;YACD,iBAAiB,EAAE,CAAC,OAAO,EAAE,EAAE;gBAC7B,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,6BAA6B,CAAC,OAAO,CAAC,CAAC;gBACtE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;YAChC,CAAC;YACD,gBAAgB,EAAE,KAAK,EAAE,cAA0B,EAAE,EAAE;gBACrD,MAAM,WAAW,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;YAC/C,CAAC;YACD,cAAc,EAAE,KAAK,EAAE,YAAqC,EAAE,EAAE;gBAC9D,MAAM,WAAW,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;YAC7C,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,78 @@
1
+ import {
2
+ NonogramKatanaUpgrade,
3
+ validateNonogramKatanaUpgrade
4
+ } from '@aneuhold/core-ts-db-lib';
5
+ import { ErrorUtils, Logger } from '@aneuhold/core-ts-lib';
6
+ import { ObjectId } from 'bson';
7
+ import UserRepository from '../../repositories/common/UserRepository.js';
8
+ import DashboardNonogramKatanaUpgradeRepository from '../../repositories/dashboard/DashboardNonogramKatanaUpgradeRepository.js';
9
+ import IValidator from '../BaseValidator.js';
10
+
11
+ export default class DashboardNonogramKatanaUpgradeValidator extends IValidator<NonogramKatanaUpgrade> {
12
+ async validateNewObject(newUpgrade: NonogramKatanaUpgrade): Promise<void> {
13
+ // Check if the item already exists for the user
14
+ const upgradeRepo = DashboardNonogramKatanaUpgradeRepository.getRepo();
15
+ const existingItem = await upgradeRepo.get({
16
+ userId: newUpgrade.userId,
17
+ upgradeName: newUpgrade.upgradeName
18
+ });
19
+ if (existingItem) {
20
+ ErrorUtils.throwError(
21
+ `Nonogram Katana upgrade already exists for user: ${newUpgrade.userId.toString()}`,
22
+ newUpgrade
23
+ );
24
+ }
25
+ const userRepo = UserRepository.getRepo();
26
+ const user = await userRepo.get({ _id: newUpgrade.userId });
27
+ if (!user) {
28
+ ErrorUtils.throwError(
29
+ `User does not exist: ${newUpgrade.userId.toString()}`,
30
+ newUpgrade
31
+ );
32
+ }
33
+ }
34
+
35
+ // eslint-disable-next-line @typescript-eslint/require-await
36
+ async validateUpdateObject(
37
+ updatedUpgrade: Partial<NonogramKatanaUpgrade>
38
+ ): Promise<void> {
39
+ // Check if an id is defined
40
+ if (!updatedUpgrade._id) {
41
+ ErrorUtils.throwError(
42
+ `No _id defined for NonogramKatanaUpgrade update.`,
43
+ updatedUpgrade
44
+ );
45
+ }
46
+ }
47
+
48
+ async validateRepositoryInDb(dryRun: boolean): Promise<void> {
49
+ const upgradeRepo = DashboardNonogramKatanaUpgradeRepository.getRepo();
50
+ const allUpgrades = await upgradeRepo.getAll();
51
+ const allUserIds = await UserRepository.getRepo().getAllIdsAsHash();
52
+
53
+ await this.runStandardValidationForRepository({
54
+ dryRun,
55
+ docName: 'Nonogram Katana Upgrade',
56
+ allDocs: allUpgrades,
57
+ shouldDelete: (upgrade: NonogramKatanaUpgrade) => {
58
+ if (!allUserIds[upgrade.userId.toString()]) {
59
+ Logger.error(
60
+ `Nonogram Katana Upgrade with ID: ${upgrade._id.toString()} has no valid associated user.`
61
+ );
62
+ return true;
63
+ }
64
+ return false;
65
+ },
66
+ documentValidator: (upgrade) => {
67
+ const { updatedDoc, errors } = validateNonogramKatanaUpgrade(upgrade);
68
+ return { updatedDoc, errors };
69
+ },
70
+ deletionFunction: async (docIdsToDelete: ObjectId[]) => {
71
+ await upgradeRepo.deleteList(docIdsToDelete);
72
+ },
73
+ updateFunction: async (docsToUpdate: NonogramKatanaUpgrade[]) => {
74
+ await upgradeRepo.updateMany(docsToUpdate);
75
+ }
76
+ });
77
+ }
78
+ }
@@ -1,5 +1,5 @@
1
1
  import { DashboardTask } from '@aneuhold/core-ts-db-lib';
2
- import IValidator from '../BaseValidator';
2
+ import IValidator from '../BaseValidator.js';
3
3
  export default class DashboardTaskValidator extends IValidator<DashboardTask> {
4
4
  validateNewObject(newTask: DashboardTask): Promise<void>;
5
5
  validateUpdateObject(updatedTask: Partial<DashboardTask>): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"TaskValidator.d.ts","sourceRoot":"","sources":["../../../src/validators/dashboard/TaskValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAyB,MAAM,0BAA0B,CAAC;AAGhF,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAI1C,MAAM,CAAC,OAAO,OAAO,sBAAuB,SAAQ,UAAU,CAAC,aAAa,CAAC;IACrE,iBAAiB,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAoBxD,oBAAoB,CACxB,WAAW,EAAE,OAAO,CAAC,aAAa,CAAC,GAClC,OAAO,CAAC,IAAI,CAAC;IAqBV,sBAAsB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAqD7D"}
1
+ {"version":3,"file":"TaskValidator.d.ts","sourceRoot":"./src/","sources":["validators/dashboard/TaskValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAyB,MAAM,0BAA0B,CAAC;AAKhF,OAAO,UAAU,MAAM,qBAAqB,CAAC;AAE7C,MAAM,CAAC,OAAO,OAAO,sBAAuB,SAAQ,UAAU,CAAC,aAAa,CAAC;IACrE,iBAAiB,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAoBxD,oBAAoB,CACxB,WAAW,EAAE,OAAO,CAAC,aAAa,CAAC,GAClC,OAAO,CAAC,IAAI,CAAC;IAqBV,sBAAsB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAqD7D"}
@@ -1,18 +1,13 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const core_ts_db_lib_1 = require("@aneuhold/core-ts-db-lib");
7
- const core_ts_lib_1 = require("@aneuhold/core-ts-lib");
8
- const BaseValidator_1 = __importDefault(require("../BaseValidator"));
9
- const UserRepository_1 = __importDefault(require("../../repositories/common/UserRepository"));
10
- const DashboardTaskRepository_1 = __importDefault(require("../../repositories/dashboard/DashboardTaskRepository"));
11
- class DashboardTaskValidator extends BaseValidator_1.default {
1
+ import { validateDashboardTask } from '@aneuhold/core-ts-db-lib';
2
+ import { ErrorUtils, Logger } from '@aneuhold/core-ts-lib';
3
+ import UserRepository from '../../repositories/common/UserRepository.js';
4
+ import DashboardTaskRepository from '../../repositories/dashboard/DashboardTaskRepository.js';
5
+ import IValidator from '../BaseValidator.js';
6
+ export default class DashboardTaskValidator extends IValidator {
12
7
  async validateNewObject(newTask) {
13
8
  const errors = [];
14
9
  // Check if the user exists, and any shared users exist
15
- const userRepo = UserRepository_1.default.getRepo();
10
+ const userRepo = UserRepository.getRepo();
16
11
  const userIds = [newTask.userId, ...newTask.sharedWith];
17
12
  const usersFound = await userRepo.getList(userIds);
18
13
  if (usersFound.length !== userIds.length) {
@@ -21,7 +16,7 @@ class DashboardTaskValidator extends BaseValidator_1.default {
21
16
  // Do not check if it has a parent, becuase multiple could be inserted at
22
17
  // once and the parent may not exist yet.
23
18
  if (errors.length > 0) {
24
- core_ts_lib_1.ErrorUtils.throwErrorList(errors, newTask);
19
+ ErrorUtils.throwErrorList(errors, newTask);
25
20
  }
26
21
  }
27
22
  async validateUpdateObject(updatedTask) {
@@ -31,7 +26,7 @@ class DashboardTaskValidator extends BaseValidator_1.default {
31
26
  errors.push(`No _id defined for DashboardTask update.`);
32
27
  }
33
28
  if (updatedTask.parentTaskId) {
34
- const parentTask = await DashboardTaskRepository_1.default.getRepo().get({
29
+ const parentTask = await DashboardTaskRepository.getRepo().get({
35
30
  _id: updatedTask.parentTaskId
36
31
  });
37
32
  if (!parentTask) {
@@ -39,26 +34,26 @@ class DashboardTaskValidator extends BaseValidator_1.default {
39
34
  }
40
35
  }
41
36
  if (errors.length > 0) {
42
- core_ts_lib_1.ErrorUtils.throwErrorList(errors, updatedTask);
37
+ ErrorUtils.throwErrorList(errors, updatedTask);
43
38
  }
44
39
  }
45
40
  async validateRepositoryInDb(dryRun) {
46
- const taskRepo = DashboardTaskRepository_1.default.getRepo();
41
+ const taskRepo = DashboardTaskRepository.getRepo();
47
42
  const allTasks = await taskRepo.getAll();
48
- const allUserIds = await UserRepository_1.default.getRepo().getAllIdsAsHash();
43
+ const allUserIds = await UserRepository.getRepo().getAllIdsAsHash();
49
44
  await this.runStandardValidationForRepository({
50
45
  dryRun,
51
46
  docName: 'Dashboard Task',
52
47
  allDocs: allTasks,
53
48
  shouldDelete: (task) => {
54
49
  if (!allUserIds[task.userId.toString()]) {
55
- core_ts_lib_1.Logger.error(`Dashboard Task with ID: ${task._id.toString()} has no valid associated owner (user).`);
50
+ Logger.error(`Dashboard Task with ID: ${task._id.toString()} has no valid associated owner (user).`);
56
51
  return true;
57
52
  }
58
53
  return false;
59
54
  },
60
55
  documentValidator: (task) => {
61
- const { updatedDoc, errors } = (0, core_ts_db_lib_1.validateDashboardTask)(task);
56
+ const { updatedDoc, errors } = validateDashboardTask(task);
62
57
  // Check sharedWith
63
58
  const sharedWithUserIds = [...task.sharedWith];
64
59
  sharedWithUserIds.forEach((userId) => {
@@ -83,4 +78,4 @@ class DashboardTaskValidator extends BaseValidator_1.default {
83
78
  });
84
79
  }
85
80
  }
86
- exports.default = DashboardTaskValidator;
81
+ //# sourceMappingURL=TaskValidator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TaskValidator.js","sourceRoot":"./src/","sources":["validators/dashboard/TaskValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,qBAAqB,EAAE,MAAM,0BAA0B,CAAC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
+ import { ObjectId } from 'bson';
4
+ import UserRepository from '../../repositories/common/UserRepository.js';
5
+ import DashboardTaskRepository from '../../repositories/dashboard/DashboardTaskRepository.js';
6
+ import IValidator from '../BaseValidator.js';
7
+
8
+ export default class DashboardTaskValidator extends IValidator<DashboardTask> {
9
+ async validateNewObject(newTask: DashboardTask): Promise<void> {
10
+ const errors: string[] = [];
11
+ // Check if the user exists, and any shared users exist
12
+ const userRepo = UserRepository.getRepo();
13
+ const userIds = [newTask.userId, ...newTask.sharedWith];
14
+ const usersFound = await userRepo.getList(userIds);
15
+ if (usersFound.length !== userIds.length) {
16
+ errors.push(
17
+ `Not all users exist. Found: ${usersFound.length}, expected: ${
18
+ userIds.length
19
+ }. List searched was: ${JSON.stringify(userIds)}.`
20
+ );
21
+ }
22
+ // Do not check if it has a parent, becuase multiple could be inserted at
23
+ // once and the parent may not exist yet.
24
+ if (errors.length > 0) {
25
+ ErrorUtils.throwErrorList(errors, newTask);
26
+ }
27
+ }
28
+
29
+ async validateUpdateObject(
30
+ updatedTask: Partial<DashboardTask>
31
+ ): Promise<void> {
32
+ const errors: string[] = [];
33
+ // Check if an id is defined
34
+ if (!updatedTask._id) {
35
+ errors.push(`No _id defined for DashboardTask update.`);
36
+ }
37
+ if (updatedTask.parentTaskId) {
38
+ const parentTask = await DashboardTaskRepository.getRepo().get({
39
+ _id: updatedTask.parentTaskId
40
+ });
41
+ if (!parentTask) {
42
+ errors.push(
43
+ `Parent task with ID: ${updatedTask.parentTaskId.toString()} does not exist.`
44
+ );
45
+ }
46
+ }
47
+ if (errors.length > 0) {
48
+ ErrorUtils.throwErrorList(errors, updatedTask);
49
+ }
50
+ }
51
+
52
+ async validateRepositoryInDb(dryRun: boolean): Promise<void> {
53
+ const taskRepo = DashboardTaskRepository.getRepo();
54
+ const allTasks = await taskRepo.getAll();
55
+ const allUserIds = await UserRepository.getRepo().getAllIdsAsHash();
56
+
57
+ await this.runStandardValidationForRepository({
58
+ dryRun,
59
+ docName: 'Dashboard Task',
60
+ allDocs: allTasks,
61
+ shouldDelete: (task: DashboardTask) => {
62
+ if (!allUserIds[task.userId.toString()]) {
63
+ Logger.error(
64
+ `Dashboard Task with ID: ${task._id.toString()} has no valid associated owner (user).`
65
+ );
66
+ return true;
67
+ }
68
+ return false;
69
+ },
70
+ documentValidator: (task: DashboardTask) => {
71
+ const { updatedDoc, errors } = validateDashboardTask(task);
72
+
73
+ // Check sharedWith
74
+ const sharedWithUserIds = [...task.sharedWith];
75
+ sharedWithUserIds.forEach((userId) => {
76
+ if (!allUserIds[userId.toString()]) {
77
+ errors.push(
78
+ `User with ID: ${userId.toString()} does not exist in sharedWith property of task with ID: ${task._id.toString()}.`
79
+ );
80
+
81
+ task.sharedWith = task.sharedWith.filter(
82
+ (id) => id.toString() !== userId.toString()
83
+ );
84
+ }
85
+ });
86
+
87
+ // Check assignedTo
88
+ if (task.assignedTo && !allUserIds[task.assignedTo.toString()]) {
89
+ errors.push(
90
+ `User with ID: ${task.assignedTo.toString()} does not exist in assignedTo property of task with ID: ${task._id.toString()}.`
91
+ );
92
+ updatedDoc.assignedTo = undefined;
93
+ }
94
+
95
+ return { updatedDoc, errors };
96
+ },
97
+ deletionFunction: async (docIdsToDelete: ObjectId[]) => {
98
+ await taskRepo.deleteList(docIdsToDelete);
99
+ },
100
+ updateFunction: async (docsToUpdate: DashboardTask[]) => {
101
+ await taskRepo.updateMany(docsToUpdate);
102
+ }
103
+ });
104
+ }
105
+ }
@@ -1,5 +1,5 @@
1
1
  import { DashboardUserConfig } from '@aneuhold/core-ts-db-lib';
2
- import IValidator from '../BaseValidator';
2
+ import IValidator from '../BaseValidator.js';
3
3
  export default class DashboardUserConfigValidator extends IValidator<DashboardUserConfig> {
4
4
  validateNewObject(newUserConfig: DashboardUserConfig): Promise<void>;
5
5
  validateUpdateObject(updatedUserConfig: Partial<DashboardUserConfig>): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"UserConfigValidator.d.ts","sourceRoot":"","sources":["../../../src/validators/dashboard/UserConfigValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EAEpB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAI1C,MAAM,CAAC,OAAO,OAAO,4BAA6B,SAAQ,UAAU,CAAC,mBAAmB,CAAC;IACjF,iBAAiB,CAAC,aAAa,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IA+BpE,oBAAoB,CACxB,iBAAiB,EAAE,OAAO,CAAC,mBAAmB,CAAC,GAC9C,OAAO,CAAC,IAAI,CAAC;IAyBV,sBAAsB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CA0C7D"}
1
+ {"version":3,"file":"UserConfigValidator.d.ts","sourceRoot":"./src/","sources":["validators/dashboard/UserConfigValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EAEpB,MAAM,0BAA0B,CAAC;AAKlC,OAAO,UAAU,MAAM,qBAAqB,CAAC;AAE7C,MAAM,CAAC,OAAO,OAAO,4BAA6B,SAAQ,UAAU,CAAC,mBAAmB,CAAC;IACjF,iBAAiB,CAAC,aAAa,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IA+BpE,oBAAoB,CACxB,iBAAiB,EAAE,OAAO,CAAC,mBAAmB,CAAC,GAC9C,OAAO,CAAC,IAAI,CAAC;IAyBV,sBAAsB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CA0C7D"}
@@ -1,66 +1,61 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const core_ts_db_lib_1 = require("@aneuhold/core-ts-db-lib");
7
- const core_ts_lib_1 = require("@aneuhold/core-ts-lib");
8
- const BaseValidator_1 = __importDefault(require("../BaseValidator"));
9
- const DashboardUserConfigRepository_1 = __importDefault(require("../../repositories/dashboard/DashboardUserConfigRepository"));
10
- const UserRepository_1 = __importDefault(require("../../repositories/common/UserRepository"));
11
- class DashboardUserConfigValidator extends BaseValidator_1.default {
1
+ import { validateDashboardUserConfig } from '@aneuhold/core-ts-db-lib';
2
+ import { ErrorUtils, Logger } from '@aneuhold/core-ts-lib';
3
+ import UserRepository from '../../repositories/common/UserRepository.js';
4
+ import DashboardUserConfigRepository from '../../repositories/dashboard/DashboardUserConfigRepository.js';
5
+ import IValidator from '../BaseValidator.js';
6
+ export default class DashboardUserConfigValidator extends IValidator {
12
7
  async validateNewObject(newUserConfig) {
13
8
  // Check if the config already exists for the user
14
- const configRepo = DashboardUserConfigRepository_1.default.getRepo();
9
+ const configRepo = DashboardUserConfigRepository.getRepo();
15
10
  const existingConfig = await configRepo.get({
16
11
  userId: newUserConfig.userId
17
12
  });
18
13
  if (existingConfig) {
19
- core_ts_lib_1.ErrorUtils.throwError(`Config already exists for user: ${newUserConfig.userId.toString()}`, newUserConfig);
14
+ ErrorUtils.throwError(`Config already exists for user: ${newUserConfig.userId.toString()}`, newUserConfig);
20
15
  }
21
- const userRepo = UserRepository_1.default.getRepo();
16
+ const userRepo = UserRepository.getRepo();
22
17
  const user = await userRepo.get({ _id: newUserConfig.userId });
23
18
  if (!user) {
24
- core_ts_lib_1.ErrorUtils.throwError(`User does not exist: ${newUserConfig.userId.toString()}`, newUserConfig);
19
+ ErrorUtils.throwError(`User does not exist: ${newUserConfig.userId.toString()}`, newUserConfig);
25
20
  }
26
21
  if (newUserConfig.collaborators.length > 0) {
27
22
  const collaborators = await userRepo.getList(newUserConfig.collaborators);
28
23
  if (collaborators.length !== newUserConfig.collaborators.length) {
29
- core_ts_lib_1.ErrorUtils.throwError(`Some collaborators not found. Expected ${newUserConfig.collaborators.length}, found ${collaborators.length}`, newUserConfig);
24
+ ErrorUtils.throwError(`Some collaborators not found. Expected ${newUserConfig.collaborators.length}, found ${collaborators.length}`, newUserConfig);
30
25
  }
31
26
  }
32
27
  }
33
28
  async validateUpdateObject(updatedUserConfig) {
34
29
  // Check if an id is defined
35
30
  if (!updatedUserConfig._id) {
36
- core_ts_lib_1.ErrorUtils.throwError(`No _id defined for DashboardUserConfig update.`, updatedUserConfig);
31
+ ErrorUtils.throwError(`No _id defined for DashboardUserConfig update.`, updatedUserConfig);
37
32
  }
38
33
  if (updatedUserConfig.collaborators &&
39
34
  updatedUserConfig.collaborators.length > 0) {
40
- const userRepo = UserRepository_1.default.getRepo();
35
+ const userRepo = UserRepository.getRepo();
41
36
  const collaborators = await userRepo.getList(updatedUserConfig.collaborators);
42
37
  if (collaborators.length !== updatedUserConfig.collaborators.length) {
43
- core_ts_lib_1.ErrorUtils.throwError(`Some collaborators not found. Expected ${updatedUserConfig.collaborators.length}, found ${collaborators.length}`, updatedUserConfig);
38
+ ErrorUtils.throwError(`Some collaborators not found. Expected ${updatedUserConfig.collaborators.length}, found ${collaborators.length}`, updatedUserConfig);
44
39
  }
45
40
  }
46
41
  }
47
42
  async validateRepositoryInDb(dryRun) {
48
- const userConfigRepo = DashboardUserConfigRepository_1.default.getRepo();
43
+ const userConfigRepo = DashboardUserConfigRepository.getRepo();
49
44
  const allUserConfigs = await userConfigRepo.getAll();
50
- const allUserIds = await UserRepository_1.default.getRepo().getAllIdsAsHash();
45
+ const allUserIds = await UserRepository.getRepo().getAllIdsAsHash();
51
46
  await this.runStandardValidationForRepository({
52
47
  dryRun,
53
48
  docName: 'Dashboard User Config',
54
49
  allDocs: allUserConfigs,
55
50
  shouldDelete: (userConfig) => {
56
51
  if (!allUserIds[userConfig.userId.toString()]) {
57
- core_ts_lib_1.Logger.error(`Dashboard User Config with ID: ${userConfig._id.toString()} has no valid associated user.`);
52
+ Logger.error(`Dashboard User Config with ID: ${userConfig._id.toString()} has no valid associated user.`);
58
53
  return true;
59
54
  }
60
55
  return false;
61
56
  },
62
57
  documentValidator: (userConfig) => {
63
- const { updatedDoc, errors } = (0, core_ts_db_lib_1.validateDashboardUserConfig)(userConfig);
58
+ const { updatedDoc, errors } = validateDashboardUserConfig(userConfig);
64
59
  const collaboratorIds = [...userConfig.collaborators];
65
60
  collaboratorIds.forEach((userId) => {
66
61
  if (!allUserIds[userId.toString()]) {
@@ -79,4 +74,4 @@ class DashboardUserConfigValidator extends BaseValidator_1.default {
79
74
  });
80
75
  }
81
76
  }
82
- exports.default = DashboardUserConfigValidator;
77
+ //# sourceMappingURL=UserConfigValidator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserConfigValidator.js","sourceRoot":"./src/","sources":["validators/dashboard/UserConfigValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,2BAA2B,EAC5B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,cAAc,MAAM,6CAA6C,CAAC;AACzE,OAAO,6BAA6B,MAAM,+DAA+D,CAAC;AAC1G,OAAO,UAAU,MAAM,qBAAqB,CAAC;AAE7C,MAAM,CAAC,OAAO,OAAO,4BAA6B,SAAQ,UAA+B;IACvF,KAAK,CAAC,iBAAiB,CAAC,aAAkC;QACxD,kDAAkD;QAClD,MAAM,UAAU,GAAG,6BAA6B,CAAC,OAAO,EAAE,CAAC;QAC3D,MAAM,cAAc,GAAG,MAAM,UAAU,CAAC,GAAG,CAAC;YAC1C,MAAM,EAAE,aAAa,CAAC,MAAM;SAC7B,CAAC,CAAC;QACH,IAAI,cAAc,EAAE,CAAC;YACnB,UAAU,CAAC,UAAU,CACnB,mCAAmC,aAAa,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,EACpE,aAAa,CACd,CAAC;QACJ,CAAC;QACD,MAAM,QAAQ,GAAG,cAAc,CAAC,OAAO,EAAE,CAAC;QAC1C,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,aAAa,CAAC,MAAM,EAAE,CAAC,CAAC;QAC/D,IAAI,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