@aneuhold/be-ts-db-lib 1.0.114 → 2.0.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.
- package/LICENSE +21 -0
- package/README.md +46 -10
- package/lib/index.d.ts +8 -8
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +10 -20
- package/lib/index.js.map +1 -0
- package/lib/index.ts +21 -0
- package/lib/repositories/BaseRepository.d.ts +84 -11
- package/lib/repositories/BaseRepository.d.ts.map +1 -1
- package/lib/repositories/BaseRepository.js +89 -21
- package/lib/repositories/BaseRepository.js.map +1 -0
- package/lib/repositories/BaseRepository.ts +339 -0
- package/lib/repositories/common/ApiKeyRepository.d.ts +2 -2
- package/lib/repositories/common/ApiKeyRepository.d.ts.map +1 -1
- package/lib/repositories/common/ApiKeyRepository.js +8 -13
- package/lib/repositories/common/ApiKeyRepository.js.map +1 -0
- package/lib/repositories/common/ApiKeyRepository.ts +55 -0
- package/lib/repositories/common/UserRepository.d.ts +1 -1
- package/lib/repositories/common/UserRepository.d.ts.map +1 -1
- package/lib/repositories/common/UserRepository.js +15 -20
- package/lib/repositories/common/UserRepository.js.map +1 -0
- package/lib/repositories/common/UserRepository.ts +65 -0
- package/lib/repositories/dashboard/DashboardBaseRepository.d.ts +2 -2
- package/lib/repositories/dashboard/DashboardBaseRepository.d.ts.map +1 -1
- package/lib/repositories/dashboard/DashboardBaseRepository.js +6 -11
- package/lib/repositories/dashboard/DashboardBaseRepository.js.map +1 -0
- package/lib/repositories/dashboard/DashboardBaseRepository.ts +31 -0
- package/lib/repositories/dashboard/DashboardNonogramKatanaItemRepository.d.ts +2 -2
- package/lib/repositories/dashboard/DashboardNonogramKatanaItemRepository.d.ts.map +1 -1
- package/lib/repositories/dashboard/DashboardNonogramKatanaItemRepository.js +7 -12
- package/lib/repositories/dashboard/DashboardNonogramKatanaItemRepository.js.map +1 -0
- package/lib/repositories/dashboard/DashboardNonogramKatanaItemRepository.ts +64 -0
- package/lib/repositories/dashboard/DashboardNonogramKatanaUpgradeRepository.d.ts +2 -2
- package/lib/repositories/dashboard/DashboardNonogramKatanaUpgradeRepository.d.ts.map +1 -1
- package/lib/repositories/dashboard/DashboardNonogramKatanaUpgradeRepository.js +7 -12
- package/lib/repositories/dashboard/DashboardNonogramKatanaUpgradeRepository.js.map +1 -0
- package/lib/repositories/dashboard/DashboardNonogramKatanaUpgradeRepository.ts +66 -0
- package/lib/repositories/dashboard/DashboardTaskRepository.d.ts +17 -4
- package/lib/repositories/dashboard/DashboardTaskRepository.d.ts.map +1 -1
- package/lib/repositories/dashboard/DashboardTaskRepository.js +26 -18
- package/lib/repositories/dashboard/DashboardTaskRepository.js.map +1 -0
- package/lib/repositories/dashboard/DashboardTaskRepository.ts +166 -0
- package/lib/repositories/dashboard/DashboardUserConfigRepository.d.ts +29 -5
- package/lib/repositories/dashboard/DashboardUserConfigRepository.d.ts.map +1 -1
- package/lib/repositories/dashboard/DashboardUserConfigRepository.js +38 -19
- package/lib/repositories/dashboard/DashboardUserConfigRepository.js.map +1 -0
- package/lib/repositories/dashboard/DashboardUserConfigRepository.ts +254 -0
- package/lib/services/MigrationService.d.ts.map +1 -1
- package/lib/services/MigrationService.js +10 -15
- package/lib/services/MigrationService.js.map +1 -0
- package/lib/services/MigrationService.ts +52 -0
- package/lib/services/RepoSubscriptionService.d.ts.map +1 -1
- package/lib/services/RepoSubscriptionService.js +2 -4
- package/lib/services/RepoSubscriptionService.js.map +1 -0
- package/lib/services/RepoSubscriptionService.ts +63 -0
- package/lib/tests/globalTestVariables.d.ts +5 -0
- package/lib/tests/globalTestVariables.d.ts.map +1 -0
- package/lib/tests/globalTestVariables.js +5 -0
- package/lib/tests/globalTestVariables.js.map +1 -0
- package/lib/tests/globalTestVariables.ts +4 -0
- package/lib/tests/repositories/BaseRepository.spec.ts +61 -0
- package/lib/tests/repositories/common/UserRepository.spec.ts +113 -0
- package/lib/tests/repositories/dashboard/NonogramKatanaItemRepository.spec.ts +55 -0
- package/lib/tests/repositories/dashboard/NonogramKatanaUpgradeRepository.spec.ts +14 -0
- package/lib/tests/repositories/dashboard/TaskRepository.spec.ts +101 -0
- package/lib/tests/repositories/dashboard/UserConfigRepository.spec.ts +155 -0
- package/lib/tests/testsUtil.d.ts +20 -4
- package/lib/tests/testsUtil.d.ts.map +1 -1
- package/lib/tests/testsUtil.js +29 -20
- package/lib/tests/testsUtil.js.map +1 -0
- package/lib/tests/testsUtil.ts +68 -0
- package/lib/util/DbSchemaUpdater.d.ts.map +1 -1
- package/lib/util/DbSchemaUpdater.js +10 -15
- package/lib/util/DbSchemaUpdater.js.map +1 -0
- package/lib/util/DbSchemaUpdater.ts +16 -0
- package/lib/util/DocumentCleaner.d.ts.map +1 -1
- package/lib/util/DocumentCleaner.js +2 -4
- package/lib/util/DocumentCleaner.js.map +1 -0
- package/lib/util/DocumentCleaner.ts +31 -0
- package/lib/util/DocumentDb.d.ts +4 -1
- package/lib/util/DocumentDb.d.ts.map +1 -1
- package/lib/util/DocumentDb.js +11 -10
- package/lib/util/DocumentDb.js.map +1 -0
- package/lib/util/DocumentDb.ts +47 -0
- package/lib/validators/BaseValidator.d.ts +11 -0
- package/lib/validators/BaseValidator.d.ts.map +1 -1
- package/lib/validators/BaseValidator.js +26 -18
- package/lib/validators/BaseValidator.js.map +1 -0
- package/lib/validators/BaseValidator.ts +150 -0
- package/lib/validators/common/ApiKeyValidator.d.ts +1 -1
- package/lib/validators/common/ApiKeyValidator.d.ts.map +1 -1
- package/lib/validators/common/ApiKeyValidator.js +16 -21
- package/lib/validators/common/ApiKeyValidator.js.map +1 -0
- package/lib/validators/common/ApiKeyValidator.ts +67 -0
- package/lib/validators/common/UserValidator.d.ts +14 -1
- package/lib/validators/common/UserValidator.d.ts.map +1 -1
- package/lib/validators/common/UserValidator.js +29 -21
- package/lib/validators/common/UserValidator.js.map +1 -0
- package/lib/validators/common/UserValidator.ts +98 -0
- package/lib/validators/dashboard/NonogramKatanaItemValidator.d.ts +1 -1
- package/lib/validators/dashboard/NonogramKatanaItemValidator.d.ts.map +1 -1
- package/lib/validators/dashboard/NonogramKatanaItemValidator.js +16 -21
- package/lib/validators/dashboard/NonogramKatanaItemValidator.js.map +1 -0
- package/lib/validators/dashboard/NonogramKatanaItemValidator.ts +78 -0
- package/lib/validators/dashboard/NonogramKatanaUpgradeValidator.d.ts +1 -1
- package/lib/validators/dashboard/NonogramKatanaUpgradeValidator.d.ts.map +1 -1
- package/lib/validators/dashboard/NonogramKatanaUpgradeValidator.js +16 -21
- package/lib/validators/dashboard/NonogramKatanaUpgradeValidator.js.map +1 -0
- package/lib/validators/dashboard/NonogramKatanaUpgradeValidator.ts +78 -0
- package/lib/validators/dashboard/TaskValidator.d.ts +1 -1
- package/lib/validators/dashboard/TaskValidator.d.ts.map +1 -1
- package/lib/validators/dashboard/TaskValidator.js +15 -20
- package/lib/validators/dashboard/TaskValidator.js.map +1 -0
- package/lib/validators/dashboard/TaskValidator.ts +105 -0
- package/lib/validators/dashboard/UserConfigValidator.d.ts +1 -1
- package/lib/validators/dashboard/UserConfigValidator.d.ts.map +1 -1
- package/lib/validators/dashboard/UserConfigValidator.js +19 -24
- package/lib/validators/dashboard/UserConfigValidator.js.map +1 -0
- package/lib/validators/dashboard/UserConfigValidator.ts +112 -0
- package/package.json +44 -38
- package/lib/scripts/migrate.d.ts +0 -2
- package/lib/scripts/migrate.d.ts.map +0 -1
- package/lib/scripts/migrate.js +0 -7
- package/lib/scripts/migrateDry.d.ts +0 -2
- package/lib/scripts/migrateDry.d.ts.map +0 -1
- package/lib/scripts/migrateDry.js +0 -7
- package/lib/scripts/validateSchema.d.ts +0 -2
- package/lib/scripts/validateSchema.d.ts.map +0 -1
- package/lib/scripts/validateSchema.js +0 -9
- package/lib/scripts/validateSchemaDryRun.d.ts +0 -2
- package/lib/scripts/validateSchemaDryRun.d.ts.map +0 -1
- package/lib/scripts/validateSchemaDryRun.js +0 -9
- package/lib/tests/repositories/BaseRepository.spec.d.ts +0 -2
- package/lib/tests/repositories/BaseRepository.spec.d.ts.map +0 -1
- package/lib/tests/repositories/BaseRepository.spec.js +0 -52
- package/lib/tests/repositories/common/UserRepository.spec.d.ts +0 -2
- package/lib/tests/repositories/common/UserRepository.spec.d.ts.map +0 -1
- package/lib/tests/repositories/common/UserRepository.spec.js +0 -108
- package/lib/tests/repositories/dashboard/NonogramKatanaItemRepository.spec.d.ts +0 -2
- package/lib/tests/repositories/dashboard/NonogramKatanaItemRepository.spec.d.ts.map +0 -1
- package/lib/tests/repositories/dashboard/NonogramKatanaItemRepository.spec.js +0 -39
- package/lib/tests/repositories/dashboard/NonogramKatanaUpgradeRepository.spec.d.ts +0 -2
- package/lib/tests/repositories/dashboard/NonogramKatanaUpgradeRepository.spec.d.ts.map +0 -1
- package/lib/tests/repositories/dashboard/NonogramKatanaUpgradeRepository.spec.js +0 -16
- package/lib/tests/repositories/dashboard/TaskRepository.spec.d.ts +0 -2
- package/lib/tests/repositories/dashboard/TaskRepository.spec.d.ts.map +0 -1
- package/lib/tests/repositories/dashboard/TaskRepository.spec.js +0 -84
- package/lib/tests/repositories/dashboard/UserConfigRepository.spec.d.ts +0 -2
- package/lib/tests/repositories/dashboard/UserConfigRepository.spec.d.ts.map +0 -1
- package/lib/tests/repositories/dashboard/UserConfigRepository.spec.js +0 -115
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { BaseDocumentWithType } from '@aneuhold/core-ts-db-lib';
|
|
2
|
+
import CleanDocument from '../../util/DocumentCleaner.js';
|
|
3
|
+
import IValidator from '../../validators/BaseValidator.js';
|
|
4
|
+
import BaseRepository from '../BaseRepository.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A base repository for the `dashboard` collection.
|
|
8
|
+
*/
|
|
9
|
+
export default abstract class DashboardBaseRepository<
|
|
10
|
+
TBaseType extends BaseDocumentWithType
|
|
11
|
+
> extends BaseRepository<TBaseType> {
|
|
12
|
+
private static COLLECTION_NAME = 'dashboard';
|
|
13
|
+
|
|
14
|
+
constructor(
|
|
15
|
+
docType: string,
|
|
16
|
+
validator: IValidator<TBaseType>,
|
|
17
|
+
updateCleaner?: (doc: Partial<TBaseType>) => Partial<TBaseType>
|
|
18
|
+
) {
|
|
19
|
+
const defaultUpdateCleaner = (updatedDoc: Partial<TBaseType>) =>
|
|
20
|
+
updateCleaner
|
|
21
|
+
? updateCleaner(CleanDocument.docType(updatedDoc))
|
|
22
|
+
: CleanDocument.docType(updatedDoc);
|
|
23
|
+
const defaultFilter = { docType } as Partial<TBaseType>;
|
|
24
|
+
super(
|
|
25
|
+
DashboardBaseRepository.COLLECTION_NAME,
|
|
26
|
+
validator,
|
|
27
|
+
defaultFilter,
|
|
28
|
+
defaultUpdateCleaner
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NonogramKatanaItem, User } from '@aneuhold/core-ts-db-lib';
|
|
2
2
|
import { ObjectId } from 'bson';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import { RepoListeners } from '../../services/RepoSubscriptionService.js';
|
|
4
|
+
import DashboardBaseRepository from './DashboardBaseRepository.js';
|
|
5
5
|
/**
|
|
6
6
|
* The repository that contains {@link NonogramKatanaItem} documents.
|
|
7
7
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DashboardNonogramKatanaItemRepository.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"DashboardNonogramKatanaItemRepository.d.ts","sourceRoot":"./src/","sources":["repositories/dashboard/DashboardNonogramKatanaItemRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,2CAA2C,CAAC;AAG1E,OAAO,uBAAuB,MAAM,8BAA8B,CAAC;AAEnE;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,qCAAsC,SAAQ,uBAAuB,CAAC,kBAAkB,CAAC;IAC5G,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAwC;IAEzE,OAAO;IAQP,MAAM,CAAC,uBAAuB,IAAI,aAAa,CAAC,IAAI,CAAC;IAgBrD,SAAS,CAAC,gBAAgB,IAAI,IAAI;IAElC;;OAEG;WACW,OAAO,IAAI,qCAAqC;IAQ9D;;;;OAIG;IACG,aAAa,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;CAQrE"}
|
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const core_ts_db_lib_1 = require("@aneuhold/core-ts-db-lib");
|
|
7
|
-
const DashboardBaseRepository_1 = __importDefault(require("./DashboardBaseRepository"));
|
|
8
|
-
const DocumentCleaner_1 = __importDefault(require("../../util/DocumentCleaner"));
|
|
9
|
-
const NonogramKatanaItemValidator_1 = __importDefault(require("../../validators/dashboard/NonogramKatanaItemValidator"));
|
|
1
|
+
import { NonogramKatanaItem } from '@aneuhold/core-ts-db-lib';
|
|
2
|
+
import CleanDocument from '../../util/DocumentCleaner.js';
|
|
3
|
+
import DashboardNonogramKatanaItemValidator from '../../validators/dashboard/NonogramKatanaItemValidator.js';
|
|
4
|
+
import DashboardBaseRepository from './DashboardBaseRepository.js';
|
|
10
5
|
/**
|
|
11
6
|
* The repository that contains {@link NonogramKatanaItem} documents.
|
|
12
7
|
*/
|
|
13
|
-
class DashboardNonogramKatanaItemRepository extends
|
|
8
|
+
export default class DashboardNonogramKatanaItemRepository extends DashboardBaseRepository {
|
|
14
9
|
static singletonInstance;
|
|
15
10
|
constructor() {
|
|
16
|
-
super(
|
|
11
|
+
super(NonogramKatanaItem.docType, new DashboardNonogramKatanaItemValidator(), CleanDocument.userId);
|
|
17
12
|
}
|
|
18
13
|
static getListenersForUserRepo() {
|
|
19
14
|
const nonogramKatanaRepo = DashboardNonogramKatanaItemRepository.getRepo();
|
|
@@ -53,4 +48,4 @@ class DashboardNonogramKatanaItemRepository extends DashboardBaseRepository_1.de
|
|
|
53
48
|
return result;
|
|
54
49
|
}
|
|
55
50
|
}
|
|
56
|
-
|
|
51
|
+
//# sourceMappingURL=DashboardNonogramKatanaItemRepository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DashboardNonogramKatanaItemRepository.js","sourceRoot":"./src/","sources":["repositories/dashboard/DashboardNonogramKatanaItemRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAQ,MAAM,0BAA0B,CAAC;AAGpE,OAAO,aAAa,MAAM,+BAA+B,CAAC;AAC1D,OAAO,oCAAoC,MAAM,2DAA2D,CAAC;AAC7G,OAAO,uBAAuB,MAAM,8BAA8B,CAAC;AAEnE;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,qCAAsC,SAAQ,uBAA2C;IACpG,MAAM,CAAC,iBAAiB,CAAyC;IAEzE;QACE,KAAK,CACH,kBAAkB,CAAC,OAAO,EAC1B,IAAI,oCAAoC,EAAE,EAC1C,aAAa,CAAC,MAAM,CACrB,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,uBAAuB;QAC5B,MAAM,kBAAkB,GAAG,qCAAqC,CAAC,OAAO,EAAE,CAAC;QAC3E,OAAO;YACL,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;gBAC1B,MAAM,CAAC,MAAM,kBAAkB,CAAC,aAAa,EAAE,CAAC,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;YAC1E,CAAC;YACD,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;gBAC5B,MAAM,CACJ,MAAM,kBAAkB,CAAC,aAAa,EAAE,CACzC,CAAC,UAAU,CAAC;oBACX,MAAM,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE;iBACzB,CAAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC;IAES,gBAAgB,KAAU,CAAC;IAErC;;OAEG;IACI,MAAM,CAAC,OAAO;QACnB,IAAI,CAAC,qCAAqC,CAAC,iBAAiB,EAAE,CAAC;YAC7D,qCAAqC,CAAC,iBAAiB;gBACrD,IAAI,qCAAqC,EAAE,CAAC;QAChD,CAAC;QACD,OAAO,qCAAqC,CAAC,iBAAiB,CAAC;IACjE,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,aAAa,CAAC,MAAgB;QAClC,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;QAC9C,MAAM,MAAM,GAAG;YACb,IAAI,EAAE,CAAC,IAAI,CAAC,oBAAoB,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC;SAChD,CAAC;QACF,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC;QACvD,OAAO,MAA8B,CAAC;IACxC,CAAC;CACF"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { NonogramKatanaItem, User } from '@aneuhold/core-ts-db-lib';
|
|
2
|
+
import { ObjectId } from 'bson';
|
|
3
|
+
import { RepoListeners } from '../../services/RepoSubscriptionService.js';
|
|
4
|
+
import CleanDocument from '../../util/DocumentCleaner.js';
|
|
5
|
+
import DashboardNonogramKatanaItemValidator from '../../validators/dashboard/NonogramKatanaItemValidator.js';
|
|
6
|
+
import DashboardBaseRepository from './DashboardBaseRepository.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The repository that contains {@link NonogramKatanaItem} documents.
|
|
10
|
+
*/
|
|
11
|
+
export default class DashboardNonogramKatanaItemRepository extends DashboardBaseRepository<NonogramKatanaItem> {
|
|
12
|
+
private static singletonInstance?: DashboardNonogramKatanaItemRepository;
|
|
13
|
+
|
|
14
|
+
private constructor() {
|
|
15
|
+
super(
|
|
16
|
+
NonogramKatanaItem.docType,
|
|
17
|
+
new DashboardNonogramKatanaItemValidator(),
|
|
18
|
+
CleanDocument.userId
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static getListenersForUserRepo(): RepoListeners<User> {
|
|
23
|
+
const nonogramKatanaRepo = DashboardNonogramKatanaItemRepository.getRepo();
|
|
24
|
+
return {
|
|
25
|
+
deleteOne: async (userId) => {
|
|
26
|
+
await (await nonogramKatanaRepo.getCollection()).deleteMany({ userId });
|
|
27
|
+
},
|
|
28
|
+
deleteList: async (userIds) => {
|
|
29
|
+
await (
|
|
30
|
+
await nonogramKatanaRepo.getCollection()
|
|
31
|
+
).deleteMany({
|
|
32
|
+
userId: { $in: userIds }
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
protected setupSubscribers(): void {}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Gets the singleton instance of the {@link DashboardNonogramKatanaItemRepository}.
|
|
42
|
+
*/
|
|
43
|
+
public static getRepo(): DashboardNonogramKatanaItemRepository {
|
|
44
|
+
if (!DashboardNonogramKatanaItemRepository.singletonInstance) {
|
|
45
|
+
DashboardNonogramKatanaItemRepository.singletonInstance =
|
|
46
|
+
new DashboardNonogramKatanaItemRepository();
|
|
47
|
+
}
|
|
48
|
+
return DashboardNonogramKatanaItemRepository.singletonInstance;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Gets all Nonogram Katana items for a given user.
|
|
53
|
+
*
|
|
54
|
+
* @param userId The ID of the user to get items for.
|
|
55
|
+
*/
|
|
56
|
+
async getAllForUser(userId: ObjectId): Promise<NonogramKatanaItem[]> {
|
|
57
|
+
const collection = await this.getCollection();
|
|
58
|
+
const filter = {
|
|
59
|
+
$and: [this.getFilterWithDefault(), { userId }]
|
|
60
|
+
};
|
|
61
|
+
const result = await collection.find(filter).toArray();
|
|
62
|
+
return result as NonogramKatanaItem[];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NonogramKatanaUpgrade, User } from '@aneuhold/core-ts-db-lib';
|
|
2
2
|
import { ObjectId } from 'bson';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import { RepoListeners } from '../../services/RepoSubscriptionService.js';
|
|
4
|
+
import DashboardBaseRepository from './DashboardBaseRepository.js';
|
|
5
5
|
/**
|
|
6
6
|
* The repository that contains {@link NonogramKatanaUpgrade} documents.
|
|
7
7
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DashboardNonogramKatanaUpgradeRepository.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"DashboardNonogramKatanaUpgradeRepository.d.ts","sourceRoot":"./src/","sources":["repositories/dashboard/DashboardNonogramKatanaUpgradeRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,2CAA2C,CAAC;AAG1E,OAAO,uBAAuB,MAAM,8BAA8B,CAAC;AAEnE;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,wCAAyC,SAAQ,uBAAuB,CAAC,qBAAqB,CAAC;IAClH,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAElB;IAEd,OAAO;IAQP,MAAM,CAAC,uBAAuB,IAAI,aAAa,CAAC,IAAI,CAAC;IAgBrD,SAAS,CAAC,gBAAgB,IAAI,IAAI;IAElC;;OAEG;WACW,OAAO,IAAI,wCAAwC;IAQjE;;;;OAIG;IACG,aAAa,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,qBAAqB,EAAE,CAAC;CAQxE"}
|
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const core_ts_db_lib_1 = require("@aneuhold/core-ts-db-lib");
|
|
7
|
-
const DashboardBaseRepository_1 = __importDefault(require("./DashboardBaseRepository"));
|
|
8
|
-
const DocumentCleaner_1 = __importDefault(require("../../util/DocumentCleaner"));
|
|
9
|
-
const NonogramKatanaUpgradeValidator_1 = __importDefault(require("../../validators/dashboard/NonogramKatanaUpgradeValidator"));
|
|
1
|
+
import { NonogramKatanaUpgrade } from '@aneuhold/core-ts-db-lib';
|
|
2
|
+
import CleanDocument from '../../util/DocumentCleaner.js';
|
|
3
|
+
import DashboardNonogramKatanaUpgradeValidator from '../../validators/dashboard/NonogramKatanaUpgradeValidator.js';
|
|
4
|
+
import DashboardBaseRepository from './DashboardBaseRepository.js';
|
|
10
5
|
/**
|
|
11
6
|
* The repository that contains {@link NonogramKatanaUpgrade} documents.
|
|
12
7
|
*/
|
|
13
|
-
class DashboardNonogramKatanaUpgradeRepository extends
|
|
8
|
+
export default class DashboardNonogramKatanaUpgradeRepository extends DashboardBaseRepository {
|
|
14
9
|
static singletonInstance;
|
|
15
10
|
constructor() {
|
|
16
|
-
super(
|
|
11
|
+
super(NonogramKatanaUpgrade.docType, new DashboardNonogramKatanaUpgradeValidator(), CleanDocument.userId);
|
|
17
12
|
}
|
|
18
13
|
static getListenersForUserRepo() {
|
|
19
14
|
const upgradeRepo = DashboardNonogramKatanaUpgradeRepository.getRepo();
|
|
@@ -53,4 +48,4 @@ class DashboardNonogramKatanaUpgradeRepository extends DashboardBaseRepository_1
|
|
|
53
48
|
return result;
|
|
54
49
|
}
|
|
55
50
|
}
|
|
56
|
-
|
|
51
|
+
//# sourceMappingURL=DashboardNonogramKatanaUpgradeRepository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DashboardNonogramKatanaUpgradeRepository.js","sourceRoot":"./src/","sources":["repositories/dashboard/Dash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G,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;QAC9C,MAAM,MAAM,GAAG;YACb,IAAI,EAAE,CAAC,IAAI,CAAC,oBAAoB,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC;SAChD,CAAC;QACF,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC;QACvD,OAAO,MAAiC,CAAC;IAC3C,CAAC;CACF"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { NonogramKatanaUpgrade, User } from '@aneuhold/core-ts-db-lib';
|
|
2
|
+
import { ObjectId } from 'bson';
|
|
3
|
+
import { RepoListeners } from '../../services/RepoSubscriptionService.js';
|
|
4
|
+
import CleanDocument from '../../util/DocumentCleaner.js';
|
|
5
|
+
import DashboardNonogramKatanaUpgradeValidator from '../../validators/dashboard/NonogramKatanaUpgradeValidator.js';
|
|
6
|
+
import DashboardBaseRepository from './DashboardBaseRepository.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The repository that contains {@link NonogramKatanaUpgrade} documents.
|
|
10
|
+
*/
|
|
11
|
+
export default class DashboardNonogramKatanaUpgradeRepository extends DashboardBaseRepository<NonogramKatanaUpgrade> {
|
|
12
|
+
private static singletonInstance:
|
|
13
|
+
| DashboardNonogramKatanaUpgradeRepository
|
|
14
|
+
| undefined;
|
|
15
|
+
|
|
16
|
+
private constructor() {
|
|
17
|
+
super(
|
|
18
|
+
NonogramKatanaUpgrade.docType,
|
|
19
|
+
new DashboardNonogramKatanaUpgradeValidator(),
|
|
20
|
+
CleanDocument.userId
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static getListenersForUserRepo(): RepoListeners<User> {
|
|
25
|
+
const upgradeRepo = DashboardNonogramKatanaUpgradeRepository.getRepo();
|
|
26
|
+
return {
|
|
27
|
+
deleteOne: async (userId) => {
|
|
28
|
+
await (await upgradeRepo.getCollection()).deleteMany({ userId });
|
|
29
|
+
},
|
|
30
|
+
deleteList: async (userIds) => {
|
|
31
|
+
await (
|
|
32
|
+
await upgradeRepo.getCollection()
|
|
33
|
+
).deleteMany({
|
|
34
|
+
userId: { $in: userIds }
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
protected setupSubscribers(): void {}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Gets the singleton instance of the {@link DashboardNonogramKatanaUpgradeRepository}.
|
|
44
|
+
*/
|
|
45
|
+
public static getRepo(): DashboardNonogramKatanaUpgradeRepository {
|
|
46
|
+
if (!DashboardNonogramKatanaUpgradeRepository.singletonInstance) {
|
|
47
|
+
DashboardNonogramKatanaUpgradeRepository.singletonInstance =
|
|
48
|
+
new DashboardNonogramKatanaUpgradeRepository();
|
|
49
|
+
}
|
|
50
|
+
return DashboardNonogramKatanaUpgradeRepository.singletonInstance;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Gets all Nonogram Katana upgrades for a given user.
|
|
55
|
+
*
|
|
56
|
+
* @param userId The ID of the user to get upgrades for.
|
|
57
|
+
*/
|
|
58
|
+
async getAllForUser(userId: ObjectId): Promise<NonogramKatanaUpgrade[]> {
|
|
59
|
+
const collection = await this.getCollection();
|
|
60
|
+
const filter = {
|
|
61
|
+
$and: [this.getFilterWithDefault(), { userId }]
|
|
62
|
+
};
|
|
63
|
+
const result = await collection.find(filter).toArray();
|
|
64
|
+
return result as NonogramKatanaUpgrade[];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -1,35 +1,44 @@
|
|
|
1
1
|
import { DashboardTask, User } from '@aneuhold/core-ts-db-lib';
|
|
2
2
|
import { ObjectId } from 'bson';
|
|
3
3
|
import { DeleteResult } from 'mongodb';
|
|
4
|
-
import
|
|
5
|
-
import
|
|
4
|
+
import { RepoListeners } from '../../services/RepoSubscriptionService.js';
|
|
5
|
+
import DashboardBaseRepository from './DashboardBaseRepository.js';
|
|
6
6
|
/**
|
|
7
7
|
* The repository that contains {@link DashboardTask} documents.
|
|
8
8
|
*/
|
|
9
9
|
export default class DashboardTaskRepository extends DashboardBaseRepository<DashboardTask> {
|
|
10
10
|
private static singletonInstance?;
|
|
11
|
+
/**
|
|
12
|
+
* Private constructor to enforce singleton pattern.
|
|
13
|
+
*/
|
|
11
14
|
private constructor();
|
|
12
15
|
/**
|
|
13
16
|
* Doesn't handle removing sharedWith references, as that should be handled
|
|
14
17
|
* by the User Config updates.
|
|
18
|
+
*
|
|
19
|
+
* @returns The repository listeners for user repository.
|
|
15
20
|
*/
|
|
16
21
|
static getListenersForUserRepo(): RepoListeners<User>;
|
|
17
22
|
protected setupSubscribers(): void;
|
|
18
23
|
/**
|
|
19
24
|
* Gets the singleton instance of the {@link DashboardTaskRepository}.
|
|
25
|
+
*
|
|
26
|
+
* @returns The singleton instance of the repository.
|
|
20
27
|
*/
|
|
21
28
|
static getRepo(): DashboardTaskRepository;
|
|
22
29
|
/**
|
|
23
30
|
* Deletes a task and removes the reference to this task from any other tasks
|
|
24
31
|
* that have it as a parent.
|
|
25
32
|
*
|
|
26
|
-
* @
|
|
33
|
+
* @param docId The ID of the document to delete.
|
|
34
|
+
* @returns The result of the delete operation.
|
|
27
35
|
*/
|
|
28
36
|
delete(docId: ObjectId): Promise<DeleteResult>;
|
|
29
37
|
/**
|
|
30
38
|
* Deletes a list of tasks and all children of those tasks.
|
|
31
39
|
*
|
|
32
|
-
* @
|
|
40
|
+
* @param docIds The IDs of the documents to delete.
|
|
41
|
+
* @returns The result of the delete operation.
|
|
33
42
|
*/
|
|
34
43
|
deleteList(docIds: ObjectId[]): Promise<DeleteResult>;
|
|
35
44
|
/**
|
|
@@ -38,11 +47,15 @@ export default class DashboardTaskRepository extends DashboardBaseRepository<Das
|
|
|
38
47
|
* will be returned.
|
|
39
48
|
*
|
|
40
49
|
* @param userId The ID of the user to get tasks for.
|
|
50
|
+
* @returns The list of tasks for the user.
|
|
41
51
|
*/
|
|
42
52
|
getAllForUser(userId: ObjectId): Promise<DashboardTask[]>;
|
|
43
53
|
/**
|
|
44
54
|
* Gets all the task IDs that need to be deleted if the provided list of
|
|
45
55
|
* tasks is deleted.
|
|
56
|
+
*
|
|
57
|
+
* @param taskIds The IDs of the tasks to delete.
|
|
58
|
+
* @returns The list of task IDs to delete.
|
|
46
59
|
*/
|
|
47
60
|
private getAllTaskIDsToDelete;
|
|
48
61
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DashboardTaskRepository.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"DashboardTaskRepository.d.ts","sourceRoot":"./src/","sources":["repositories/dashboard/DashboardTaskRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,IAAI,EACL,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,2CAA2C,CAAC;AAG1E,OAAO,uBAAuB,MAAM,8BAA8B,CAAC;AAGnE;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,uBAAuB,CAAC,aAAa,CAAC;IACzF,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAA0B;IAE3D;;OAEG;IACH,OAAO;IAaP;;;;;OAKG;IACH,MAAM,CAAC,uBAAuB,IAAI,aAAa,CAAC,IAAI,CAAC;IA4BrD,SAAS,CAAC,gBAAgB,IAAI,IAAI;IAElC;;;;OAIG;WACW,OAAO,IAAI,uBAAuB;IAOhD;;;;;;OAMG;IACG,MAAM,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,YAAY,CAAC;IAMpD;;;;;OAKG;IACG,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,YAAY,CAAC;IAM3D;;;;;;;OAOG;IACG,aAAa,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAyB/D;;;;;;OAMG;YACW,qBAAqB;CAiBpC"}
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const core_ts_db_lib_1 = require("@aneuhold/core-ts-db-lib");
|
|
7
|
-
const DashboardBaseRepository_1 = __importDefault(require("./DashboardBaseRepository"));
|
|
8
|
-
const DocumentCleaner_1 = __importDefault(require("../../util/DocumentCleaner"));
|
|
9
|
-
const TaskValidator_1 = __importDefault(require("../../validators/dashboard/TaskValidator"));
|
|
10
|
-
const DashboardUserConfigRepository_1 = __importDefault(require("./DashboardUserConfigRepository"));
|
|
1
|
+
import { DashboardTask, DashboardTaskService } from '@aneuhold/core-ts-db-lib';
|
|
2
|
+
import CleanDocument from '../../util/DocumentCleaner.js';
|
|
3
|
+
import DashboardTaskValidator from '../../validators/dashboard/TaskValidator.js';
|
|
4
|
+
import DashboardBaseRepository from './DashboardBaseRepository.js';
|
|
5
|
+
import DashboardUserConfigRepository from './DashboardUserConfigRepository.js';
|
|
11
6
|
/**
|
|
12
7
|
* The repository that contains {@link DashboardTask} documents.
|
|
13
8
|
*/
|
|
14
|
-
class DashboardTaskRepository extends
|
|
9
|
+
export default class DashboardTaskRepository extends DashboardBaseRepository {
|
|
15
10
|
static singletonInstance;
|
|
11
|
+
/**
|
|
12
|
+
* Private constructor to enforce singleton pattern.
|
|
13
|
+
*/
|
|
16
14
|
constructor() {
|
|
17
|
-
super(
|
|
18
|
-
const docCopy =
|
|
15
|
+
super(DashboardTask.docType, new DashboardTaskValidator(), (task) => {
|
|
16
|
+
const docCopy = CleanDocument.userId(task);
|
|
19
17
|
delete docCopy.createdDate;
|
|
20
18
|
docCopy.lastUpdatedDate = new Date();
|
|
21
19
|
return docCopy;
|
|
@@ -24,6 +22,8 @@ class DashboardTaskRepository extends DashboardBaseRepository_1.default {
|
|
|
24
22
|
/**
|
|
25
23
|
* Doesn't handle removing sharedWith references, as that should be handled
|
|
26
24
|
* by the User Config updates.
|
|
25
|
+
*
|
|
26
|
+
* @returns The repository listeners for user repository.
|
|
27
27
|
*/
|
|
28
28
|
static getListenersForUserRepo() {
|
|
29
29
|
const taskRepo = DashboardTaskRepository.getRepo();
|
|
@@ -49,6 +49,8 @@ class DashboardTaskRepository extends DashboardBaseRepository_1.default {
|
|
|
49
49
|
setupSubscribers() { }
|
|
50
50
|
/**
|
|
51
51
|
* Gets the singleton instance of the {@link DashboardTaskRepository}.
|
|
52
|
+
*
|
|
53
|
+
* @returns The singleton instance of the repository.
|
|
52
54
|
*/
|
|
53
55
|
static getRepo() {
|
|
54
56
|
if (!DashboardTaskRepository.singletonInstance) {
|
|
@@ -60,7 +62,8 @@ class DashboardTaskRepository extends DashboardBaseRepository_1.default {
|
|
|
60
62
|
* Deletes a task and removes the reference to this task from any other tasks
|
|
61
63
|
* that have it as a parent.
|
|
62
64
|
*
|
|
63
|
-
* @
|
|
65
|
+
* @param docId The ID of the document to delete.
|
|
66
|
+
* @returns The result of the delete operation.
|
|
64
67
|
*/
|
|
65
68
|
async delete(docId) {
|
|
66
69
|
const docIdsToDelete = await this.getAllTaskIDsToDelete([docId]);
|
|
@@ -70,7 +73,8 @@ class DashboardTaskRepository extends DashboardBaseRepository_1.default {
|
|
|
70
73
|
/**
|
|
71
74
|
* Deletes a list of tasks and all children of those tasks.
|
|
72
75
|
*
|
|
73
|
-
* @
|
|
76
|
+
* @param docIds The IDs of the documents to delete.
|
|
77
|
+
* @returns The result of the delete operation.
|
|
74
78
|
*/
|
|
75
79
|
async deleteList(docIds) {
|
|
76
80
|
const docIdsToDelete = await this.getAllTaskIDsToDelete(docIds);
|
|
@@ -83,9 +87,10 @@ class DashboardTaskRepository extends DashboardBaseRepository_1.default {
|
|
|
83
87
|
* will be returned.
|
|
84
88
|
*
|
|
85
89
|
* @param userId The ID of the user to get tasks for.
|
|
90
|
+
* @returns The list of tasks for the user.
|
|
86
91
|
*/
|
|
87
92
|
async getAllForUser(userId) {
|
|
88
|
-
const userConfigRepo =
|
|
93
|
+
const userConfigRepo = DashboardUserConfigRepository.getRepo();
|
|
89
94
|
const userConfig = await userConfigRepo.get({ userId });
|
|
90
95
|
if (!userConfig) {
|
|
91
96
|
return [];
|
|
@@ -111,6 +116,9 @@ class DashboardTaskRepository extends DashboardBaseRepository_1.default {
|
|
|
111
116
|
/**
|
|
112
117
|
* Gets all the task IDs that need to be deleted if the provided list of
|
|
113
118
|
* tasks is deleted.
|
|
119
|
+
*
|
|
120
|
+
* @param taskIds The IDs of the tasks to delete.
|
|
121
|
+
* @returns The list of task IDs to delete.
|
|
114
122
|
*/
|
|
115
123
|
async getAllTaskIDsToDelete(taskIds) {
|
|
116
124
|
if (taskIds.length === 0) {
|
|
@@ -121,8 +129,8 @@ class DashboardTaskRepository extends DashboardBaseRepository_1.default {
|
|
|
121
129
|
return taskIds;
|
|
122
130
|
}
|
|
123
131
|
const allUserTasks = await this.getAllForUser(initialTask.userId);
|
|
124
|
-
const childrenIds =
|
|
132
|
+
const childrenIds = DashboardTaskService.getChildrenIds(allUserTasks, taskIds);
|
|
125
133
|
return [...taskIds, ...childrenIds];
|
|
126
134
|
}
|
|
127
135
|
}
|
|
128
|
-
|
|
136
|
+
//# sourceMappingURL=DashboardTaskRepository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DashboardTaskRepository.js","sourceRoot":"./src/","sources":["repositories/dashboard/DashboardTaskRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,oBAAoB,EAErB,MAAM,0BAA0B,CAAC;AAIlC,OAAO,aAAa,MAAM,+BAA+B,CAAC;AAC1D,OAAO,sBAAsB,MAAM,6CAA6C,CAAC;AACjF,OAAO,uBAAuB,MAAM,8BAA8B,CAAC;AACnE,OAAO,6BAA6B,MAAM,oCAAoC,CAAC;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,MAAM,MAAM,GAAG;YACb,IAAI,EAAE;gBACJ,IAAI,CAAC,oBAAoB,EAAE;gBAC3B;oBACE,GAAG,EAAE;wBACH,EAAE,MAAM,EAAE;wBACV;4BACE,IAAI,EAAE,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,aAAa,EAAE,EAAE,CAAC;yBACnE;qBACF;iBACF;aACF;SACF,CAAC;QACF,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC;QACvD,OAAO,MAAyB,CAAC;IACnC,CAAC;IAED;;;;;;OAMG;IACK,KAAK,CAAC,qBAAqB,CACjC,OAAmB;QAEnB,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACxD,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAClE,MAAM,WAAW,GAAG,oBAAoB,CAAC,cAAc,CACrD,YAAY,EACZ,OAAO,CACR,CAAC;QACF,OAAO,CAAC,GAAG,OAAO,EAAE,GAAG,WAAW,CAAC,CAAC;IACtC,CAAC;CACF"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DashboardTask,
|
|
3
|
+
DashboardTaskService,
|
|
4
|
+
User
|
|
5
|
+
} from '@aneuhold/core-ts-db-lib';
|
|
6
|
+
import { ObjectId } from 'bson';
|
|
7
|
+
import { DeleteResult } from 'mongodb';
|
|
8
|
+
import { RepoListeners } from '../../services/RepoSubscriptionService.js';
|
|
9
|
+
import CleanDocument from '../../util/DocumentCleaner.js';
|
|
10
|
+
import DashboardTaskValidator from '../../validators/dashboard/TaskValidator.js';
|
|
11
|
+
import DashboardBaseRepository from './DashboardBaseRepository.js';
|
|
12
|
+
import DashboardUserConfigRepository from './DashboardUserConfigRepository.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The repository that contains {@link DashboardTask} documents.
|
|
16
|
+
*/
|
|
17
|
+
export default class DashboardTaskRepository extends DashboardBaseRepository<DashboardTask> {
|
|
18
|
+
private static singletonInstance?: DashboardTaskRepository;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Private constructor to enforce singleton pattern.
|
|
22
|
+
*/
|
|
23
|
+
private constructor() {
|
|
24
|
+
super(
|
|
25
|
+
DashboardTask.docType,
|
|
26
|
+
new DashboardTaskValidator(),
|
|
27
|
+
(task: Partial<DashboardTask>) => {
|
|
28
|
+
const docCopy = CleanDocument.userId(task);
|
|
29
|
+
delete docCopy.createdDate;
|
|
30
|
+
docCopy.lastUpdatedDate = new Date();
|
|
31
|
+
return docCopy;
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Doesn't handle removing sharedWith references, as that should be handled
|
|
38
|
+
* by the User Config updates.
|
|
39
|
+
*
|
|
40
|
+
* @returns The repository listeners for user repository.
|
|
41
|
+
*/
|
|
42
|
+
static getListenersForUserRepo(): RepoListeners<User> {
|
|
43
|
+
const taskRepo = DashboardTaskRepository.getRepo();
|
|
44
|
+
return {
|
|
45
|
+
deleteOne: async (userId) => {
|
|
46
|
+
const taskCollection = await taskRepo.getCollection();
|
|
47
|
+
// Remove all tasks for the user
|
|
48
|
+
await taskCollection.deleteMany({ userId });
|
|
49
|
+
// Remove all assignedTo references for the user
|
|
50
|
+
await taskCollection.updateMany(
|
|
51
|
+
{ assignedTo: userId },
|
|
52
|
+
{ $set: { assignedTo: undefined } }
|
|
53
|
+
);
|
|
54
|
+
},
|
|
55
|
+
deleteList: async (userIds) => {
|
|
56
|
+
const taskCollection = await taskRepo.getCollection();
|
|
57
|
+
// Remove all tasks for the users
|
|
58
|
+
await taskCollection.deleteMany({
|
|
59
|
+
userId: { $in: userIds }
|
|
60
|
+
});
|
|
61
|
+
// Remove all assignedTo references for the users
|
|
62
|
+
await taskCollection.updateMany(
|
|
63
|
+
{ assignedTo: { $in: userIds } },
|
|
64
|
+
{ $set: { assignedTo: undefined } }
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
protected setupSubscribers(): void {}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Gets the singleton instance of the {@link DashboardTaskRepository}.
|
|
74
|
+
*
|
|
75
|
+
* @returns The singleton instance of the repository.
|
|
76
|
+
*/
|
|
77
|
+
public static getRepo(): DashboardTaskRepository {
|
|
78
|
+
if (!DashboardTaskRepository.singletonInstance) {
|
|
79
|
+
DashboardTaskRepository.singletonInstance = new DashboardTaskRepository();
|
|
80
|
+
}
|
|
81
|
+
return DashboardTaskRepository.singletonInstance;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Deletes a task and removes the reference to this task from any other tasks
|
|
86
|
+
* that have it as a parent.
|
|
87
|
+
*
|
|
88
|
+
* @param docId The ID of the document to delete.
|
|
89
|
+
* @returns The result of the delete operation.
|
|
90
|
+
*/
|
|
91
|
+
async delete(docId: ObjectId): Promise<DeleteResult> {
|
|
92
|
+
const docIdsToDelete = await this.getAllTaskIDsToDelete([docId]);
|
|
93
|
+
const deleteResult = await super.deleteList(docIdsToDelete);
|
|
94
|
+
return deleteResult;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Deletes a list of tasks and all children of those tasks.
|
|
99
|
+
*
|
|
100
|
+
* @param docIds The IDs of the documents to delete.
|
|
101
|
+
* @returns The result of the delete operation.
|
|
102
|
+
*/
|
|
103
|
+
async deleteList(docIds: ObjectId[]): Promise<DeleteResult> {
|
|
104
|
+
const docIdsToDelete = await this.getAllTaskIDsToDelete(docIds);
|
|
105
|
+
const result = await super.deleteList(docIdsToDelete);
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Gets all tasks for a given user. Only the tasks that are owned by the user
|
|
111
|
+
* or shared with the user, while they have the user ID as a collaborator,
|
|
112
|
+
* will be returned.
|
|
113
|
+
*
|
|
114
|
+
* @param userId The ID of the user to get tasks for.
|
|
115
|
+
* @returns The list of tasks for the user.
|
|
116
|
+
*/
|
|
117
|
+
async getAllForUser(userId: ObjectId): Promise<DashboardTask[]> {
|
|
118
|
+
const userConfigRepo = DashboardUserConfigRepository.getRepo();
|
|
119
|
+
const userConfig = await userConfigRepo.get({ userId });
|
|
120
|
+
if (!userConfig) {
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
const { collaborators } = userConfig;
|
|
124
|
+
const collection = await this.getCollection();
|
|
125
|
+
const filter = {
|
|
126
|
+
$and: [
|
|
127
|
+
this.getFilterWithDefault(),
|
|
128
|
+
{
|
|
129
|
+
$or: [
|
|
130
|
+
{ userId },
|
|
131
|
+
{
|
|
132
|
+
$and: [{ sharedWith: userId }, { userId: { $in: collaborators } }]
|
|
133
|
+
}
|
|
134
|
+
]
|
|
135
|
+
}
|
|
136
|
+
]
|
|
137
|
+
};
|
|
138
|
+
const result = await collection.find(filter).toArray();
|
|
139
|
+
return result as DashboardTask[];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Gets all the task IDs that need to be deleted if the provided list of
|
|
144
|
+
* tasks is deleted.
|
|
145
|
+
*
|
|
146
|
+
* @param taskIds The IDs of the tasks to delete.
|
|
147
|
+
* @returns The list of task IDs to delete.
|
|
148
|
+
*/
|
|
149
|
+
private async getAllTaskIDsToDelete(
|
|
150
|
+
taskIds: ObjectId[]
|
|
151
|
+
): Promise<ObjectId[]> {
|
|
152
|
+
if (taskIds.length === 0) {
|
|
153
|
+
return taskIds;
|
|
154
|
+
}
|
|
155
|
+
const initialTask = await this.get({ _id: taskIds[0] });
|
|
156
|
+
if (!initialTask) {
|
|
157
|
+
return taskIds;
|
|
158
|
+
}
|
|
159
|
+
const allUserTasks = await this.getAllForUser(initialTask.userId);
|
|
160
|
+
const childrenIds = DashboardTaskService.getChildrenIds(
|
|
161
|
+
allUserTasks,
|
|
162
|
+
taskIds
|
|
163
|
+
);
|
|
164
|
+
return [...taskIds, ...childrenIds];
|
|
165
|
+
}
|
|
166
|
+
}
|