@aneuhold/be-ts-db-lib 4.1.2 → 4.2.0

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 (161) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +1 -0
  3. package/lib/repositories/BaseRepository.d.ts +8 -1
  4. package/lib/repositories/BaseRepository.d.ts.map +1 -1
  5. package/lib/repositories/BaseRepository.js +13 -1
  6. package/lib/repositories/BaseRepository.js.map +1 -1
  7. package/lib/repositories/BaseRepository.ts +14 -1
  8. package/lib/repositories/common/UserRepository.d.ts.map +1 -1
  9. package/lib/repositories/common/UserRepository.js +12 -0
  10. package/lib/repositories/common/UserRepository.js.map +1 -1
  11. package/lib/repositories/common/UserRepository.ts +12 -0
  12. package/lib/repositories/dashboard/DashboardBaseWithUserIdRepository.d.ts +20 -0
  13. package/lib/repositories/dashboard/DashboardBaseWithUserIdRepository.d.ts.map +1 -1
  14. package/lib/repositories/dashboard/DashboardBaseWithUserIdRepository.js +36 -4
  15. package/lib/repositories/dashboard/DashboardBaseWithUserIdRepository.js.map +1 -1
  16. package/lib/repositories/dashboard/DashboardBaseWithUserIdRepository.ts +39 -4
  17. package/lib/repositories/dashboard/DashboardNonogramKatanaItemRepository.d.ts.map +1 -1
  18. package/lib/repositories/dashboard/DashboardNonogramKatanaItemRepository.js +2 -12
  19. package/lib/repositories/dashboard/DashboardNonogramKatanaItemRepository.js.map +1 -1
  20. package/lib/repositories/dashboard/DashboardNonogramKatanaItemRepository.ts +2 -16
  21. package/lib/repositories/dashboard/DashboardNonogramKatanaUpgradeRepository.d.ts.map +1 -1
  22. package/lib/repositories/dashboard/DashboardNonogramKatanaUpgradeRepository.js +2 -12
  23. package/lib/repositories/dashboard/DashboardNonogramKatanaUpgradeRepository.js.map +1 -1
  24. package/lib/repositories/dashboard/DashboardNonogramKatanaUpgradeRepository.ts +2 -16
  25. package/lib/repositories/dashboard/DashboardTaskRepository.d.ts +14 -0
  26. package/lib/repositories/dashboard/DashboardTaskRepository.d.ts.map +1 -1
  27. package/lib/repositories/dashboard/DashboardTaskRepository.js +33 -35
  28. package/lib/repositories/dashboard/DashboardTaskRepository.js.map +1 -1
  29. package/lib/repositories/dashboard/DashboardTaskRepository.ts +41 -45
  30. package/lib/repositories/dashboard/DashboardUserConfigRepository.d.ts +14 -0
  31. package/lib/repositories/dashboard/DashboardUserConfigRepository.d.ts.map +1 -1
  32. package/lib/repositories/dashboard/DashboardUserConfigRepository.js +26 -15
  33. package/lib/repositories/dashboard/DashboardUserConfigRepository.js.map +1 -1
  34. package/lib/repositories/dashboard/DashboardUserConfigRepository.ts +38 -21
  35. package/lib/repositories/workout/WorkoutBaseRepository.d.ts +22 -0
  36. package/lib/repositories/workout/WorkoutBaseRepository.d.ts.map +1 -0
  37. package/lib/repositories/workout/WorkoutBaseRepository.js +53 -0
  38. package/lib/repositories/workout/WorkoutBaseRepository.js.map +1 -0
  39. package/lib/repositories/workout/WorkoutBaseRepository.ts +85 -0
  40. package/lib/repositories/workout/WorkoutBaseWithUserIdRepository.d.ts +40 -0
  41. package/lib/repositories/workout/WorkoutBaseWithUserIdRepository.d.ts.map +1 -0
  42. package/lib/repositories/workout/WorkoutBaseWithUserIdRepository.js +96 -0
  43. package/lib/repositories/workout/WorkoutBaseWithUserIdRepository.js.map +1 -0
  44. package/lib/repositories/workout/WorkoutBaseWithUserIdRepository.ts +134 -0
  45. package/lib/repositories/workout/WorkoutEquipmentTypeRepository.d.ts +17 -0
  46. package/lib/repositories/workout/WorkoutEquipmentTypeRepository.d.ts.map +1 -0
  47. package/lib/repositories/workout/WorkoutEquipmentTypeRepository.js +34 -0
  48. package/lib/repositories/workout/WorkoutEquipmentTypeRepository.js.map +1 -0
  49. package/lib/repositories/workout/WorkoutEquipmentTypeRepository.ts +40 -0
  50. package/lib/repositories/workout/WorkoutExerciseCalibrationRepository.d.ts +31 -0
  51. package/lib/repositories/workout/WorkoutExerciseCalibrationRepository.d.ts.map +1 -0
  52. package/lib/repositories/workout/WorkoutExerciseCalibrationRepository.js +70 -0
  53. package/lib/repositories/workout/WorkoutExerciseCalibrationRepository.js.map +1 -0
  54. package/lib/repositories/workout/WorkoutExerciseCalibrationRepository.ts +84 -0
  55. package/lib/repositories/workout/WorkoutExerciseRepository.d.ts +14 -0
  56. package/lib/repositories/workout/WorkoutExerciseRepository.d.ts.map +1 -0
  57. package/lib/repositories/workout/WorkoutExerciseRepository.js +34 -0
  58. package/lib/repositories/workout/WorkoutExerciseRepository.js.map +1 -0
  59. package/lib/repositories/workout/WorkoutExerciseRepository.ts +40 -0
  60. package/lib/repositories/workout/WorkoutMesocycleRepository.d.ts +14 -0
  61. package/lib/repositories/workout/WorkoutMesocycleRepository.d.ts.map +1 -0
  62. package/lib/repositories/workout/WorkoutMesocycleRepository.js +34 -0
  63. package/lib/repositories/workout/WorkoutMesocycleRepository.js.map +1 -0
  64. package/lib/repositories/workout/WorkoutMesocycleRepository.ts +40 -0
  65. package/lib/repositories/workout/WorkoutMicrocycleRepository.d.ts +31 -0
  66. package/lib/repositories/workout/WorkoutMicrocycleRepository.d.ts.map +1 -0
  67. package/lib/repositories/workout/WorkoutMicrocycleRepository.js +72 -0
  68. package/lib/repositories/workout/WorkoutMicrocycleRepository.js.map +1 -0
  69. package/lib/repositories/workout/WorkoutMicrocycleRepository.ts +86 -0
  70. package/lib/repositories/workout/WorkoutMuscleGroupRepository.d.ts +20 -0
  71. package/lib/repositories/workout/WorkoutMuscleGroupRepository.d.ts.map +1 -0
  72. package/lib/repositories/workout/WorkoutMuscleGroupRepository.js +37 -0
  73. package/lib/repositories/workout/WorkoutMuscleGroupRepository.js.map +1 -0
  74. package/lib/repositories/workout/WorkoutMuscleGroupRepository.ts +43 -0
  75. package/lib/repositories/workout/WorkoutSessionExerciseRepository.d.ts +31 -0
  76. package/lib/repositories/workout/WorkoutSessionExerciseRepository.d.ts.map +1 -0
  77. package/lib/repositories/workout/WorkoutSessionExerciseRepository.js +72 -0
  78. package/lib/repositories/workout/WorkoutSessionExerciseRepository.js.map +1 -0
  79. package/lib/repositories/workout/WorkoutSessionExerciseRepository.ts +86 -0
  80. package/lib/repositories/workout/WorkoutSessionRepository.d.ts +31 -0
  81. package/lib/repositories/workout/WorkoutSessionRepository.d.ts.map +1 -0
  82. package/lib/repositories/workout/WorkoutSessionRepository.js +72 -0
  83. package/lib/repositories/workout/WorkoutSessionRepository.js.map +1 -0
  84. package/lib/repositories/workout/WorkoutSessionRepository.ts +86 -0
  85. package/lib/repositories/workout/WorkoutSetRepository.d.ts +31 -0
  86. package/lib/repositories/workout/WorkoutSetRepository.d.ts.map +1 -0
  87. package/lib/repositories/workout/WorkoutSetRepository.js +69 -0
  88. package/lib/repositories/workout/WorkoutSetRepository.js.map +1 -0
  89. package/lib/repositories/workout/WorkoutSetRepository.ts +89 -0
  90. package/lib/util/DbSchemaUpdater.d.ts.map +1 -1
  91. package/lib/util/DbSchemaUpdater.js +25 -0
  92. package/lib/util/DbSchemaUpdater.js.map +1 -1
  93. package/lib/util/DbSchemaUpdater.ts +27 -0
  94. package/lib/util/DocumentCleaner.d.ts +2 -1
  95. package/lib/util/DocumentCleaner.d.ts.map +1 -1
  96. package/lib/util/DocumentCleaner.js +5 -0
  97. package/lib/util/DocumentCleaner.js.map +1 -1
  98. package/lib/util/DocumentCleaner.ts +14 -1
  99. package/lib/util/globalTestVariables.d.ts +8 -0
  100. package/lib/util/globalTestVariables.d.ts.map +1 -0
  101. package/lib/util/globalTestVariables.js +8 -0
  102. package/lib/util/globalTestVariables.js.map +1 -0
  103. package/lib/{tests → util}/globalTestVariables.ts +3 -0
  104. package/lib/validators/common/UserValidator.js +1 -1
  105. package/lib/validators/common/UserValidator.js.map +1 -1
  106. package/lib/validators/common/UserValidator.ts +1 -1
  107. package/lib/validators/workout/EquipmentTypeValidator.d.ts +9 -0
  108. package/lib/validators/workout/EquipmentTypeValidator.d.ts.map +1 -0
  109. package/lib/validators/workout/EquipmentTypeValidator.js +43 -0
  110. package/lib/validators/workout/EquipmentTypeValidator.js.map +1 -0
  111. package/lib/validators/workout/EquipmentTypeValidator.ts +56 -0
  112. package/lib/validators/workout/ExerciseCalibrationValidator.d.ts +9 -0
  113. package/lib/validators/workout/ExerciseCalibrationValidator.d.ts.map +1 -0
  114. package/lib/validators/workout/ExerciseCalibrationValidator.js +65 -0
  115. package/lib/validators/workout/ExerciseCalibrationValidator.js.map +1 -0
  116. package/lib/validators/workout/ExerciseCalibrationValidator.ts +85 -0
  117. package/lib/validators/workout/ExerciseValidator.d.ts +9 -0
  118. package/lib/validators/workout/ExerciseValidator.d.ts.map +1 -0
  119. package/lib/validators/workout/ExerciseValidator.js +117 -0
  120. package/lib/validators/workout/ExerciseValidator.js.map +1 -0
  121. package/lib/validators/workout/ExerciseValidator.ts +156 -0
  122. package/lib/validators/workout/MesocycleValidator.d.ts +9 -0
  123. package/lib/validators/workout/MesocycleValidator.d.ts.map +1 -0
  124. package/lib/validators/workout/MesocycleValidator.js +56 -0
  125. package/lib/validators/workout/MesocycleValidator.js.map +1 -0
  126. package/lib/validators/workout/MesocycleValidator.ts +73 -0
  127. package/lib/validators/workout/MicrocycleValidator.d.ts +9 -0
  128. package/lib/validators/workout/MicrocycleValidator.d.ts.map +1 -0
  129. package/lib/validators/workout/MicrocycleValidator.js +73 -0
  130. package/lib/validators/workout/MicrocycleValidator.js.map +1 -0
  131. package/lib/validators/workout/MicrocycleValidator.ts +91 -0
  132. package/lib/validators/workout/MuscleGroupValidator.d.ts +9 -0
  133. package/lib/validators/workout/MuscleGroupValidator.d.ts.map +1 -0
  134. package/lib/validators/workout/MuscleGroupValidator.js +43 -0
  135. package/lib/validators/workout/MuscleGroupValidator.js.map +1 -0
  136. package/lib/validators/workout/MuscleGroupValidator.ts +53 -0
  137. package/lib/validators/workout/SessionExerciseValidator.d.ts +9 -0
  138. package/lib/validators/workout/SessionExerciseValidator.d.ts.map +1 -0
  139. package/lib/validators/workout/SessionExerciseValidator.js +94 -0
  140. package/lib/validators/workout/SessionExerciseValidator.js.map +1 -0
  141. package/lib/validators/workout/SessionExerciseValidator.ts +117 -0
  142. package/lib/validators/workout/SessionValidator.d.ts +9 -0
  143. package/lib/validators/workout/SessionValidator.d.ts.map +1 -0
  144. package/lib/validators/workout/SessionValidator.js +73 -0
  145. package/lib/validators/workout/SessionValidator.js.map +1 -0
  146. package/lib/validators/workout/SessionValidator.ts +89 -0
  147. package/lib/validators/workout/SetValidator.d.ts +9 -0
  148. package/lib/validators/workout/SetValidator.d.ts.map +1 -0
  149. package/lib/validators/workout/SetValidator.js +69 -0
  150. package/lib/validators/workout/SetValidator.js.map +1 -0
  151. package/lib/validators/workout/SetValidator.ts +88 -0
  152. package/package.json +6 -5
  153. package/lib/tests/globalTestVariables.d.ts +0 -5
  154. package/lib/tests/globalTestVariables.d.ts.map +0 -1
  155. package/lib/tests/globalTestVariables.js +0 -5
  156. package/lib/tests/globalTestVariables.js.map +0 -1
  157. package/lib/tests/testsUtil.d.ts +0 -34
  158. package/lib/tests/testsUtil.d.ts.map +0 -1
  159. package/lib/tests/testsUtil.js +0 -60
  160. package/lib/tests/testsUtil.js.map +0 -1
  161. package/lib/tests/testsUtil.ts +0 -68
@@ -0,0 +1,73 @@
1
+ import { WorkoutSessionSchema } from '@aneuhold/core-ts-db-lib';
2
+ import { DR, ErrorUtils } from '@aneuhold/core-ts-lib';
3
+ import UserRepository from '../../repositories/common/UserRepository.js';
4
+ import WorkoutMicrocycleRepository from '../../repositories/workout/WorkoutMicrocycleRepository.js';
5
+ import WorkoutSessionRepository from '../../repositories/workout/WorkoutSessionRepository.js';
6
+ import IValidator from '../BaseValidator.js';
7
+ export default class WorkoutSessionValidator extends IValidator {
8
+ constructor() {
9
+ super(WorkoutSessionSchema, WorkoutSessionSchema.partial());
10
+ }
11
+ async validateNewObjectBusinessLogic(newSession) {
12
+ // Validate that the microcycle exists if workoutMicrocycleId is provided
13
+ if (newSession.workoutMicrocycleId) {
14
+ const microcycleRepo = WorkoutMicrocycleRepository.getRepo();
15
+ const microcycle = await microcycleRepo.get({ _id: newSession.workoutMicrocycleId });
16
+ if (!microcycle) {
17
+ ErrorUtils.throwError(`Microcycle with ID ${newSession.workoutMicrocycleId} does not exist`, newSession);
18
+ }
19
+ }
20
+ }
21
+ async validateUpdateObjectBusinessLogic(updatedSession) {
22
+ const errors = [];
23
+ if (!updatedSession._id) {
24
+ errors.push('No _id defined for WorkoutSession update.');
25
+ }
26
+ // Validate microcycle if being updated
27
+ if (updatedSession.workoutMicrocycleId) {
28
+ const microcycleRepo = WorkoutMicrocycleRepository.getRepo();
29
+ const microcycle = await microcycleRepo.get({ _id: updatedSession.workoutMicrocycleId });
30
+ if (!microcycle) {
31
+ errors.push(`Microcycle with ID ${updatedSession.workoutMicrocycleId} does not exist`);
32
+ }
33
+ }
34
+ if (errors.length > 0) {
35
+ ErrorUtils.throwErrorList(errors, updatedSession);
36
+ }
37
+ }
38
+ async validateRepositoryInDb(dryRun) {
39
+ const sessionRepo = WorkoutSessionRepository.getRepo();
40
+ const allSessions = await sessionRepo.getAll();
41
+ const allUserIds = await UserRepository.getRepo().getAllIdsAsHash();
42
+ const allMicrocycleIds = await WorkoutMicrocycleRepository.getRepo().getAllIdsAsHash();
43
+ await this.runStandardValidationForRepository({
44
+ dryRun,
45
+ docName: 'Workout Session',
46
+ allDocs: allSessions,
47
+ shouldDelete: (session) => {
48
+ if (!allUserIds[session.userId]) {
49
+ DR.logger.error(`Workout Session with ID: ${session._id} has no valid associated user.`);
50
+ return true;
51
+ }
52
+ return false;
53
+ },
54
+ additionalValidation: (session) => {
55
+ const updatedDoc = { ...session };
56
+ const errors = [];
57
+ // Check microcycle if it exists
58
+ if (session.workoutMicrocycleId && !allMicrocycleIds[session.workoutMicrocycleId]) {
59
+ errors.push(`Microcycle with ID: ${session.workoutMicrocycleId} does not exist.`);
60
+ updatedDoc.workoutMicrocycleId = null;
61
+ }
62
+ return { updatedDoc, errors };
63
+ },
64
+ deletionFunction: async (docIdsToDelete) => {
65
+ await sessionRepo.deleteList(docIdsToDelete);
66
+ },
67
+ updateFunction: async (docsToUpdate) => {
68
+ await sessionRepo.updateMany(docsToUpdate);
69
+ }
70
+ });
71
+ }
72
+ }
73
+ //# sourceMappingURL=SessionValidator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SessionValidator.js","sourceRoot":"","sources":["../../../src/validators/workout/SessionValidator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,cAAc,MAAM,6CAA6C,CAAC;AACzE,OAAO,2BAA2B,MAAM,2DAA2D,CAAC;AACpG,OAAO,wBAAwB,MAAM,wDAAwD,CAAC;AAC9F,OAAO,UAAU,MAAM,qBAAqB,CAAC;AAE7C,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,UAA0B;IAC7E;QACE,KAAK,CAAC,oBAAoB,EAAE,oBAAoB,CAAC,OAAO,EAAE,CAAC,CAAC;IAC9D,CAAC;IAES,KAAK,CAAC,8BAA8B,CAAC,UAA0B;QACvE,yEAAyE;QACzE,IAAI,UAAU,CAAC,mBAAmB,EAAE,CAAC;YACnC,MAAM,cAAc,GAAG,2BAA2B,CAAC,OAAO,EAAE,CAAC;YAC7D,MAAM,UAAU,GAAG,MAAM,cAAc,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,UAAU,CAAC,mBAAmB,EAAE,CAAC,CAAC;YACrF,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChB,UAAU,CAAC,UAAU,CACnB,sBAAsB,UAAU,CAAC,mBAAmB,iBAAiB,EACrE,UAAU,CACX,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAES,KAAK,CAAC,iCAAiC,CAC/C,cAAuC;QAEvC,MAAM,MAAM,GAAa,EAAE,CAAC;QAE5B,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,C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ACD,OAAO,KAAK,CAAC;YACf,CAAC;YACD,oBAAoB,EAAE,CAAC,OAAuB,EAAE,EAAE;gBAChD,MAAM,UAAU,GAAG,EAAE,GAAG,OAAO,EAAE,CAAC;gBAClC,MAAM,MAAM,GAAa,EAAE,CAAC;gBAE5B,gCAAgC;gBAChC,IAAI,OAAO,CAAC,mBAAmB,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,mBAAmB,CAAC,EAAE,CAAC;oBAClF,MAAM,CAAC,IAAI,CAAC,uBAAuB,OAAO,CAAC,mBAAmB,kBAAkB,CAAC,CAAC;oBAClF,UAAU,CAAC,mBAAmB,GAAG,IAAI,CAAC;gBACxC,CAAC;gBAED,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;YAChC,CAAC;YACD,gBAAgB,EAAE,KAAK,EAAE,cAAsB,EAAE,EAAE;gBACjD,MAAM,WAAW,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;YAC/C,CAAC;YACD,cAAc,EAAE,KAAK,EAAE,YAA8B,EAAE,EAAE;gBACvD,MAAM,WAAW,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;YAC7C,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,89 @@
1
+ import type { WorkoutSession } from '@aneuhold/core-ts-db-lib';
2
+ import { WorkoutSessionSchema } from '@aneuhold/core-ts-db-lib';
3
+ import { DR, ErrorUtils } from '@aneuhold/core-ts-lib';
4
+ import type { UUID } from 'crypto';
5
+ import UserRepository from '../../repositories/common/UserRepository.js';
6
+ import WorkoutMicrocycleRepository from '../../repositories/workout/WorkoutMicrocycleRepository.js';
7
+ import WorkoutSessionRepository from '../../repositories/workout/WorkoutSessionRepository.js';
8
+ import IValidator from '../BaseValidator.js';
9
+
10
+ export default class WorkoutSessionValidator extends IValidator<WorkoutSession> {
11
+ constructor() {
12
+ super(WorkoutSessionSchema, WorkoutSessionSchema.partial());
13
+ }
14
+
15
+ protected async validateNewObjectBusinessLogic(newSession: WorkoutSession): Promise<void> {
16
+ // Validate that the microcycle exists if workoutMicrocycleId is provided
17
+ if (newSession.workoutMicrocycleId) {
18
+ const microcycleRepo = WorkoutMicrocycleRepository.getRepo();
19
+ const microcycle = await microcycleRepo.get({ _id: newSession.workoutMicrocycleId });
20
+ if (!microcycle) {
21
+ ErrorUtils.throwError(
22
+ `Microcycle with ID ${newSession.workoutMicrocycleId} does not exist`,
23
+ newSession
24
+ );
25
+ }
26
+ }
27
+ }
28
+
29
+ protected async validateUpdateObjectBusinessLogic(
30
+ updatedSession: Partial<WorkoutSession>
31
+ ): Promise<void> {
32
+ const errors: string[] = [];
33
+
34
+ if (!updatedSession._id) {
35
+ errors.push('No _id defined for WorkoutSession update.');
36
+ }
37
+
38
+ // Validate microcycle if being updated
39
+ if (updatedSession.workoutMicrocycleId) {
40
+ const microcycleRepo = WorkoutMicrocycleRepository.getRepo();
41
+ const microcycle = await microcycleRepo.get({ _id: updatedSession.workoutMicrocycleId });
42
+ if (!microcycle) {
43
+ errors.push(`Microcycle with ID ${updatedSession.workoutMicrocycleId} does not exist`);
44
+ }
45
+ }
46
+
47
+ if (errors.length > 0) {
48
+ ErrorUtils.throwErrorList(errors, updatedSession);
49
+ }
50
+ }
51
+
52
+ async validateRepositoryInDb(dryRun: boolean): Promise<void> {
53
+ const sessionRepo = WorkoutSessionRepository.getRepo();
54
+ const allSessions = await sessionRepo.getAll();
55
+ const allUserIds = await UserRepository.getRepo().getAllIdsAsHash();
56
+ const allMicrocycleIds = await WorkoutMicrocycleRepository.getRepo().getAllIdsAsHash();
57
+
58
+ await this.runStandardValidationForRepository({
59
+ dryRun,
60
+ docName: 'Workout Session',
61
+ allDocs: allSessions,
62
+ shouldDelete: (session: WorkoutSession) => {
63
+ if (!allUserIds[session.userId]) {
64
+ DR.logger.error(`Workout Session with ID: ${session._id} has no valid associated user.`);
65
+ return true;
66
+ }
67
+ return false;
68
+ },
69
+ additionalValidation: (session: WorkoutSession) => {
70
+ const updatedDoc = { ...session };
71
+ const errors: string[] = [];
72
+
73
+ // Check microcycle if it exists
74
+ if (session.workoutMicrocycleId && !allMicrocycleIds[session.workoutMicrocycleId]) {
75
+ errors.push(`Microcycle with ID: ${session.workoutMicrocycleId} does not exist.`);
76
+ updatedDoc.workoutMicrocycleId = null;
77
+ }
78
+
79
+ return { updatedDoc, errors };
80
+ },
81
+ deletionFunction: async (docIdsToDelete: UUID[]) => {
82
+ await sessionRepo.deleteList(docIdsToDelete);
83
+ },
84
+ updateFunction: async (docsToUpdate: WorkoutSession[]) => {
85
+ await sessionRepo.updateMany(docsToUpdate);
86
+ }
87
+ });
88
+ }
89
+ }
@@ -0,0 +1,9 @@
1
+ import type { WorkoutSet } from '@aneuhold/core-ts-db-lib';
2
+ import IValidator from '../BaseValidator.js';
3
+ export default class WorkoutSetValidator extends IValidator<WorkoutSet> {
4
+ constructor();
5
+ protected validateNewObjectBusinessLogic(newSet: WorkoutSet): Promise<void>;
6
+ protected validateUpdateObjectBusinessLogic(updatedSet: Partial<WorkoutSet>): Promise<void>;
7
+ validateRepositoryInDb(dryRun: boolean): Promise<void>;
8
+ }
9
+ //# sourceMappingURL=SetValidator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SetValidator.d.ts","sourceRoot":"","sources":["../../../src/validators/workout/SetValidator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAO3D,OAAO,UAAU,MAAM,qBAAqB,CAAC;AAE7C,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,UAAU,CAAC,UAAU,CAAC;;cAKrD,8BAA8B,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;cAcjE,iCAAiC,CAC/C,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC,GAC9B,OAAO,CAAC,IAAI,CAAC;IAyBV,sBAAsB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAgC7D"}
@@ -0,0 +1,69 @@
1
+ import { WorkoutSetSchema } from '@aneuhold/core-ts-db-lib';
2
+ import { DR, ErrorUtils } from '@aneuhold/core-ts-lib';
3
+ import UserRepository from '../../repositories/common/UserRepository.js';
4
+ import WorkoutSessionExerciseRepository from '../../repositories/workout/WorkoutSessionExerciseRepository.js';
5
+ import WorkoutSetRepository from '../../repositories/workout/WorkoutSetRepository.js';
6
+ import IValidator from '../BaseValidator.js';
7
+ export default class WorkoutSetValidator extends IValidator {
8
+ constructor() {
9
+ super(WorkoutSetSchema, WorkoutSetSchema.partial());
10
+ }
11
+ async validateNewObjectBusinessLogic(newSet) {
12
+ // Validate that the session exercise exists
13
+ const sessionExerciseRepo = WorkoutSessionExerciseRepository.getRepo();
14
+ const sessionExercise = await sessionExerciseRepo.get({
15
+ _id: newSet.workoutSessionExerciseId
16
+ });
17
+ if (!sessionExercise) {
18
+ ErrorUtils.throwError(`Session exercise with ID ${newSet.workoutSessionExerciseId} does not exist`, newSet);
19
+ }
20
+ }
21
+ async validateUpdateObjectBusinessLogic(updatedSet) {
22
+ const errors = [];
23
+ if (!updatedSet._id) {
24
+ errors.push('No _id defined for WorkoutSet update.');
25
+ }
26
+ // Validate session exercise if being updated
27
+ if (updatedSet.workoutSessionExerciseId) {
28
+ const sessionExerciseRepo = WorkoutSessionExerciseRepository.getRepo();
29
+ const sessionExercise = await sessionExerciseRepo.get({
30
+ _id: updatedSet.workoutSessionExerciseId
31
+ });
32
+ if (!sessionExercise) {
33
+ errors.push(`Session exercise with ID ${updatedSet.workoutSessionExerciseId} does not exist`);
34
+ }
35
+ }
36
+ if (errors.length > 0) {
37
+ ErrorUtils.throwErrorList(errors, updatedSet);
38
+ }
39
+ }
40
+ async validateRepositoryInDb(dryRun) {
41
+ const setRepo = WorkoutSetRepository.getRepo();
42
+ const allSets = await setRepo.getAll();
43
+ const allUserIds = await UserRepository.getRepo().getAllIdsAsHash();
44
+ const allSessionExerciseIds = await WorkoutSessionExerciseRepository.getRepo().getAllIdsAsHash();
45
+ await this.runStandardValidationForRepository({
46
+ dryRun,
47
+ docName: 'Workout Set',
48
+ allDocs: allSets,
49
+ shouldDelete: (set) => {
50
+ if (!allUserIds[set.userId]) {
51
+ DR.logger.error(`Workout Set with ID: ${set._id} has no valid associated user.`);
52
+ return true;
53
+ }
54
+ if (!allSessionExerciseIds[set.workoutSessionExerciseId]) {
55
+ DR.logger.error(`Workout Set with ID: ${set._id} has no valid associated session exercise.`);
56
+ return true;
57
+ }
58
+ return false;
59
+ },
60
+ deletionFunction: async (docIdsToDelete) => {
61
+ await setRepo.deleteList(docIdsToDelete);
62
+ },
63
+ updateFunction: async (docsToUpdate) => {
64
+ await setRepo.updateMany(docsToUpdate);
65
+ }
66
+ });
67
+ }
68
+ }
69
+ //# sourceMappingURL=SetValidator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SetValidator.js","sourceRoot":"","sources":["../../../src/validators/workout/SetValidator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,cAAc,MAAM,6CAA6C,CAAC;AACzE,OAAO,gCAAgC,MAAM,gEAAgE,CAAC;AAC9G,OAAO,oBAAoB,MAAM,oDAAoD,CAAC;AACtF,OAAO,UAAU,MAAM,qBAAqB,CAAC;AAE7C,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,UAAsB;IACrE;QACE,KAAK,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,OAAO,EAAE,CAAC,CAAC;IACtD,CAAC;IAES,KAAK,CAAC,8BAA8B,CAAC,MAAkB;QAC/D,4CAA4C;QAC5C,MAAM,mBAAmB,GAAG,gCAAgC,CAAC,OAAO,EAAE,CAAC;QACvE,MAAM,eAAe,GAAG,MAAM,mBAAmB,CAAC,GAAG,CAAC;YACpD,GAAG,EAAE,MAAM,CAA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5C,MAAM;YACN,OAAO,EAAE,aAAa;YACtB,OAAO,EAAE,OAAO;YAChB,YAAY,EAAE,CAAC,GAAe,EAAE,EAAE;gBAChC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;oBAC5B,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,wBAAwB,GAAG,CAAC,GAAG,gCAAgC,CAAC,CAAC;oBACjF,OAAO,IAAI,CAAC;gBACd,CAAC;gBACD,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,wBAAwB,CAAC,EAAE,CAAC;oBACzD,EAAE,CAAC,MAAM,CAAC,KAAK,CACb,wBAAwB,GAAG,CAAC,GAAG,4CAA4C,CAC5E,CAAC;oBACF,OAAO,IAAI,CAAC;gBACd,CAAC;gBACD,OAAO,KAAK,CAAC;YACf,CAAC;YACD,gBAAgB,EAAE,KAAK,EAAE,cAAsB,EAAE,EAAE;gBACjD,MAAM,OAAO,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;YAC3C,CAAC;YACD,cAAc,EAAE,KAAK,EAAE,YAA0B,EAAE,EAAE;gBACnD,MAAM,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;YACzC,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,88 @@
1
+ import type { WorkoutSet } from '@aneuhold/core-ts-db-lib';
2
+ import { WorkoutSetSchema } from '@aneuhold/core-ts-db-lib';
3
+ import { DR, ErrorUtils } from '@aneuhold/core-ts-lib';
4
+ import type { UUID } from 'crypto';
5
+ import UserRepository from '../../repositories/common/UserRepository.js';
6
+ import WorkoutSessionExerciseRepository from '../../repositories/workout/WorkoutSessionExerciseRepository.js';
7
+ import WorkoutSetRepository from '../../repositories/workout/WorkoutSetRepository.js';
8
+ import IValidator from '../BaseValidator.js';
9
+
10
+ export default class WorkoutSetValidator extends IValidator<WorkoutSet> {
11
+ constructor() {
12
+ super(WorkoutSetSchema, WorkoutSetSchema.partial());
13
+ }
14
+
15
+ protected async validateNewObjectBusinessLogic(newSet: WorkoutSet): Promise<void> {
16
+ // Validate that the session exercise exists
17
+ const sessionExerciseRepo = WorkoutSessionExerciseRepository.getRepo();
18
+ const sessionExercise = await sessionExerciseRepo.get({
19
+ _id: newSet.workoutSessionExerciseId
20
+ });
21
+ if (!sessionExercise) {
22
+ ErrorUtils.throwError(
23
+ `Session exercise with ID ${newSet.workoutSessionExerciseId} does not exist`,
24
+ newSet
25
+ );
26
+ }
27
+ }
28
+
29
+ protected async validateUpdateObjectBusinessLogic(
30
+ updatedSet: Partial<WorkoutSet>
31
+ ): Promise<void> {
32
+ const errors: string[] = [];
33
+
34
+ if (!updatedSet._id) {
35
+ errors.push('No _id defined for WorkoutSet update.');
36
+ }
37
+
38
+ // Validate session exercise if being updated
39
+ if (updatedSet.workoutSessionExerciseId) {
40
+ const sessionExerciseRepo = WorkoutSessionExerciseRepository.getRepo();
41
+ const sessionExercise = await sessionExerciseRepo.get({
42
+ _id: updatedSet.workoutSessionExerciseId
43
+ });
44
+ if (!sessionExercise) {
45
+ errors.push(
46
+ `Session exercise with ID ${updatedSet.workoutSessionExerciseId} does not exist`
47
+ );
48
+ }
49
+ }
50
+
51
+ if (errors.length > 0) {
52
+ ErrorUtils.throwErrorList(errors, updatedSet);
53
+ }
54
+ }
55
+
56
+ async validateRepositoryInDb(dryRun: boolean): Promise<void> {
57
+ const setRepo = WorkoutSetRepository.getRepo();
58
+ const allSets = await setRepo.getAll();
59
+ const allUserIds = await UserRepository.getRepo().getAllIdsAsHash();
60
+ const allSessionExerciseIds =
61
+ await WorkoutSessionExerciseRepository.getRepo().getAllIdsAsHash();
62
+
63
+ await this.runStandardValidationForRepository({
64
+ dryRun,
65
+ docName: 'Workout Set',
66
+ allDocs: allSets,
67
+ shouldDelete: (set: WorkoutSet) => {
68
+ if (!allUserIds[set.userId]) {
69
+ DR.logger.error(`Workout Set with ID: ${set._id} has no valid associated user.`);
70
+ return true;
71
+ }
72
+ if (!allSessionExerciseIds[set.workoutSessionExerciseId]) {
73
+ DR.logger.error(
74
+ `Workout Set with ID: ${set._id} has no valid associated session exercise.`
75
+ );
76
+ return true;
77
+ }
78
+ return false;
79
+ },
80
+ deletionFunction: async (docIdsToDelete: UUID[]) => {
81
+ await setRepo.deleteList(docIdsToDelete);
82
+ },
83
+ updateFunction: async (docsToUpdate: WorkoutSet[]) => {
84
+ await setRepo.updateMany(docsToUpdate);
85
+ }
86
+ });
87
+ }
88
+ }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@aneuhold/be-ts-db-lib",
3
3
  "author": "Anton G. Neuhold Jr.",
4
4
  "license": "MIT",
5
- "version": "4.1.2",
5
+ "version": "4.2.0",
6
6
  "description": "A backend database library meant to actually interact with various databases in personal projects",
7
7
  "packageManager": "pnpm@10.25.0",
8
8
  "type": "module",
@@ -13,6 +13,7 @@
13
13
  "watch": "nodemon --ignore lib/ -e ts --exec \"pnpm build:withoutClean && local-npm publish\"",
14
14
  "unpub:local": "local-npm unpublish || true",
15
15
  "lint": "eslint",
16
+ "check": "tsc --noEmit",
16
17
  "test": "vitest run --coverage && pnpm validate:dry",
17
18
  "preparePkg": "tb pkg prepare",
18
19
  "validate": "tsx ./scripts/validateSchema.ts",
@@ -57,16 +58,16 @@
57
58
  "MongoDB"
58
59
  ],
59
60
  "dependencies": {
60
- "@aneuhold/be-ts-lib": "^3.0.9",
61
- "@aneuhold/core-ts-db-lib": "^4.0.4",
62
- "@aneuhold/core-ts-lib": "^2.3.16",
61
+ "@aneuhold/be-ts-lib": "^3.0.10",
62
+ "@aneuhold/core-ts-db-lib": "^4.1.0",
63
+ "@aneuhold/core-ts-lib": "^2.3.17",
63
64
  "bson": "^7.0.0",
64
65
  "mongodb": "^7.0.0",
65
66
  "uuid": "^13.0.0",
66
67
  "zod": "^4.1.13"
67
68
  },
68
69
  "devDependencies": {
69
- "@aneuhold/local-npm-registry": "^0.2.23",
70
+ "@aneuhold/local-npm-registry": "^0.2.24",
70
71
  "@aneuhold/main-scripts": "^2.8.0",
71
72
  "@types/node": "^25.0.2",
72
73
  "@types/node-fetch": "^2.6.13",
@@ -1,5 +0,0 @@
1
- /**
2
- * A random series of characters for tests to help identify test users.
3
- */
4
- export declare const TEST_USER_NAME_PREFIX = "lkahwsetpiohweat";
5
- //# sourceMappingURL=globalTestVariables.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"globalTestVariables.d.ts","sourceRoot":"","sources":["../../src/tests/globalTestVariables.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,qBAAqB,qBAAqB,CAAC"}
@@ -1,5 +0,0 @@
1
- /**
2
- * A random series of characters for tests to help identify test users.
3
- */
4
- export const TEST_USER_NAME_PREFIX = 'lkahwsetpiohweat';
5
- //# sourceMappingURL=globalTestVariables.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"globalTestVariables.js","sourceRoot":"","sources":["../../src/tests/globalTestVariables.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,kBAAkB,CAAC"}
@@ -1,34 +0,0 @@
1
- import type { BaseDocument } from '@aneuhold/core-ts-db-lib';
2
- import BaseRepository from '../repositories/BaseRepository.js';
3
- /**
4
- * Asserts that the provided asynchronous function throws an error.
5
- *
6
- * @param func - The asynchronous function expected to throw an error.
7
- */
8
- export declare function expectToThrow(func: () => Promise<void>): Promise<void>;
9
- /**
10
- * Gets a test user name with a standardized prefix so that they can all be
11
- * identified and deleted if anything goes wrong in the tests.
12
- *
13
- * @param username - The username to use as a base for the test user name.
14
- * @returns The test user name.
15
- */
16
- export declare function getTestUserName(username?: string): string;
17
- /**
18
- * Cleans up a document by deleting it from the repository and verifying its deletion.
19
- *
20
- * @template TDocType - The type of the document extending {@link BaseDocument}.
21
- * @param repo - The repository from which the document will be deleted.
22
- * @param doc - The document to be deleted.
23
- */
24
- export declare function cleanupDoc<TDocType extends BaseDocument>(repo: BaseRepository<TDocType>, doc: TDocType): Promise<void>;
25
- /**
26
- * Cleans up the specified documents from the repository.
27
- *
28
- * @template TDocType - The type of the documents.
29
- * @param repo - The repository from which to delete the documents.
30
- * @param docs - The documents to be deleted.
31
- * @returns A promise that resolves when the cleanup is complete.
32
- */
33
- export declare function cleanupDocs<TDocType extends BaseDocument>(repo: BaseRepository<TDocType>, docs: TDocType[]): Promise<void>;
34
- //# sourceMappingURL=testsUtil.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"testsUtil.d.ts","sourceRoot":"","sources":["../../src/tests/testsUtil.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAG7D,OAAO,cAAc,MAAM,mCAAmC,CAAC;AAG/D;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,iBAQ5D;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAGzD;AAED;;;;;;GAMG;AACH,wBAAsB,UAAU,CAAC,QAAQ,SAAS,YAAY,EAC5D,IAAI,EAAE,cAAc,CAAC,QAAQ,CAAC,EAC9B,GAAG,EAAE,QAAQ,iBAMd;AAED;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAAC,QAAQ,SAAS,YAAY,EAC7D,IAAI,EAAE,cAAc,CAAC,QAAQ,CAAC,EAC9B,IAAI,EAAE,QAAQ,EAAE,iBAOjB"}
@@ -1,60 +0,0 @@
1
- import crypto from 'crypto';
2
- import { expect } from 'vitest';
3
- import BaseRepository from '../repositories/BaseRepository.js';
4
- import { TEST_USER_NAME_PREFIX } from './globalTestVariables.js';
5
- /**
6
- * Asserts that the provided asynchronous function throws an error.
7
- *
8
- * @param func - The asynchronous function expected to throw an error.
9
- */
10
- export async function expectToThrow(func) {
11
- let threwError = false;
12
- try {
13
- await func();
14
- }
15
- catch {
16
- threwError = true;
17
- }
18
- expect(threwError).toBeTruthy();
19
- }
20
- /**
21
- * Gets a test user name with a standardized prefix so that they can all be
22
- * identified and deleted if anything goes wrong in the tests.
23
- *
24
- * @param username - The username to use as a base for the test user name.
25
- * @returns The test user name.
26
- */
27
- export function getTestUserName(username) {
28
- if (!username)
29
- return `${TEST_USER_NAME_PREFIX}-${crypto.randomUUID()}`;
30
- return `${TEST_USER_NAME_PREFIX}-${username}`;
31
- }
32
- /**
33
- * Cleans up a document by deleting it from the repository and verifying its deletion.
34
- *
35
- * @template TDocType - The type of the document extending {@link BaseDocument}.
36
- * @param repo - The repository from which the document will be deleted.
37
- * @param doc - The document to be deleted.
38
- */
39
- export async function cleanupDoc(repo, doc) {
40
- const deleteResult = await repo.delete(doc._id);
41
- expect(deleteResult.acknowledged).toBeTruthy();
42
- const findResult = await repo.get({ _id: doc._id });
43
- expect(findResult).toBeNull();
44
- }
45
- /**
46
- * Cleans up the specified documents from the repository.
47
- *
48
- * @template TDocType - The type of the documents.
49
- * @param repo - The repository from which to delete the documents.
50
- * @param docs - The documents to be deleted.
51
- * @returns A promise that resolves when the cleanup is complete.
52
- */
53
- export async function cleanupDocs(repo, docs) {
54
- const idsToDelete = docs.map((doc) => doc._id);
55
- const deleteResult = await repo.deleteList(idsToDelete);
56
- expect(deleteResult.acknowledged).toBeTruthy();
57
- const findResult = await repo.getList(idsToDelete);
58
- expect(findResult.length).toBe(0);
59
- }
60
- //# sourceMappingURL=testsUtil.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"testsUtil.js","sourceRoot":"","sources":["../../src/tests/testsUtil.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,cAAc,MAAM,mCAAmC,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEjE;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,IA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AW,CAAC,CAAC;IACnD,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpC,CAAC"}
@@ -1,68 +0,0 @@
1
- import type { BaseDocument } from '@aneuhold/core-ts-db-lib';
2
- import crypto from 'crypto';
3
- import { expect } from 'vitest';
4
- import BaseRepository from '../repositories/BaseRepository.js';
5
- import { TEST_USER_NAME_PREFIX } from './globalTestVariables.js';
6
-
7
- /**
8
- * Asserts that the provided asynchronous function throws an error.
9
- *
10
- * @param func - The asynchronous function expected to throw an error.
11
- */
12
- export async function expectToThrow(func: () => Promise<void>) {
13
- let threwError = false;
14
- try {
15
- await func();
16
- } catch {
17
- threwError = true;
18
- }
19
- expect(threwError).toBeTruthy();
20
- }
21
-
22
- /**
23
- * Gets a test user name with a standardized prefix so that they can all be
24
- * identified and deleted if anything goes wrong in the tests.
25
- *
26
- * @param username - The username to use as a base for the test user name.
27
- * @returns The test user name.
28
- */
29
- export function getTestUserName(username?: string): string {
30
- if (!username) return `${TEST_USER_NAME_PREFIX}-${crypto.randomUUID()}`;
31
- return `${TEST_USER_NAME_PREFIX}-${username}`;
32
- }
33
-
34
- /**
35
- * Cleans up a document by deleting it from the repository and verifying its deletion.
36
- *
37
- * @template TDocType - The type of the document extending {@link BaseDocument}.
38
- * @param repo - The repository from which the document will be deleted.
39
- * @param doc - The document to be deleted.
40
- */
41
- export async function cleanupDoc<TDocType extends BaseDocument>(
42
- repo: BaseRepository<TDocType>,
43
- doc: TDocType
44
- ) {
45
- const deleteResult = await repo.delete(doc._id);
46
- expect(deleteResult.acknowledged).toBeTruthy();
47
- const findResult = await repo.get({ _id: doc._id } as Partial<TDocType>);
48
- expect(findResult).toBeNull();
49
- }
50
-
51
- /**
52
- * Cleans up the specified documents from the repository.
53
- *
54
- * @template TDocType - The type of the documents.
55
- * @param repo - The repository from which to delete the documents.
56
- * @param docs - The documents to be deleted.
57
- * @returns A promise that resolves when the cleanup is complete.
58
- */
59
- export async function cleanupDocs<TDocType extends BaseDocument>(
60
- repo: BaseRepository<TDocType>,
61
- docs: TDocType[]
62
- ) {
63
- const idsToDelete = docs.map((doc) => doc._id);
64
- const deleteResult = await repo.deleteList(idsToDelete);
65
- expect(deleteResult.acknowledged).toBeTruthy();
66
- const findResult = await repo.getList(idsToDelete);
67
- expect(findResult.length).toBe(0);
68
- }