@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
|
@@ -1,25 +1,36 @@
|
|
|
1
1
|
import { DashboardUserConfig, User } from '@aneuhold/core-ts-db-lib';
|
|
2
2
|
import { ObjectId } from 'bson';
|
|
3
3
|
import { BulkWriteResult, UpdateResult } 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 DashboardUserConfig} documents.
|
|
8
8
|
*/
|
|
9
9
|
export default class DashboardUserConfigRepository extends DashboardBaseRepository<DashboardUserConfig> {
|
|
10
10
|
private static singletonInstance?;
|
|
11
|
+
/**
|
|
12
|
+
* Private constructor to enforce singleton pattern.
|
|
13
|
+
*/
|
|
11
14
|
private constructor();
|
|
15
|
+
/**
|
|
16
|
+
* Gets the listeners for the user repository.
|
|
17
|
+
*
|
|
18
|
+
* @returns The listeners for the user repository.
|
|
19
|
+
*/
|
|
12
20
|
static getListenersForUserRepo(): RepoListeners<User>;
|
|
13
21
|
protected setupSubscribers(): void;
|
|
14
22
|
/**
|
|
15
23
|
* Gets the singleton instance of the {@link DashboardUserConfigRepository}.
|
|
24
|
+
*
|
|
25
|
+
* @returns The singleton instance.
|
|
16
26
|
*/
|
|
17
27
|
static getRepo(): DashboardUserConfigRepository;
|
|
18
28
|
/**
|
|
19
29
|
* Inserts a new config for a user. If the user has collaborators, those
|
|
20
30
|
* collaborators will have the current user added to their collaborators list.
|
|
21
31
|
*
|
|
22
|
-
* @
|
|
32
|
+
* @param newDoc The new {@link DashboardUserConfig} document to insert.
|
|
33
|
+
* @returns The inserted document or null if insertion failed.
|
|
23
34
|
*/
|
|
24
35
|
insertNew(newDoc: DashboardUserConfig): Promise<DashboardUserConfig | null>;
|
|
25
36
|
/**
|
|
@@ -27,20 +38,31 @@ export default class DashboardUserConfigRepository extends DashboardBaseReposito
|
|
|
27
38
|
* those collaborators will have the current user added to their collaborators
|
|
28
39
|
* list.
|
|
29
40
|
*
|
|
30
|
-
* @
|
|
41
|
+
* @param newDocs The list of new {@link DashboardUserConfig} documents to insert.
|
|
42
|
+
* @returns The list of inserted documents.
|
|
31
43
|
*/
|
|
32
44
|
insertMany(newDocs: DashboardUserConfig[]): Promise<DashboardUserConfig[]>;
|
|
33
45
|
/**
|
|
34
46
|
* Updates a user config. If the user has collaborators, those collaborators
|
|
35
47
|
* will have the current user added to their collaborators list.
|
|
36
48
|
*
|
|
37
|
-
* @
|
|
49
|
+
* @param updatedDoc The updated {@link DashboardUserConfig} document.
|
|
50
|
+
* @returns The result of the update operation.
|
|
38
51
|
*/
|
|
39
52
|
update(updatedDoc: Partial<DashboardUserConfig>): Promise<UpdateResult<DashboardUserConfig>>;
|
|
53
|
+
/**
|
|
54
|
+
* Updates multiple user configs. If the users have collaborators, those collaborators
|
|
55
|
+
* will have the current user added to their collaborators list.
|
|
56
|
+
*
|
|
57
|
+
* @param updatedDocs The list of updated {@link DashboardUserConfig} documents.
|
|
58
|
+
* @returns The result of the bulk update operation.
|
|
59
|
+
*/
|
|
40
60
|
updateMany(updatedDocs: Partial<DashboardUserConfig>[]): Promise<BulkWriteResult>;
|
|
41
61
|
/**
|
|
42
62
|
* Gets the config for a given user.
|
|
63
|
+
*
|
|
43
64
|
* @param userId The ID of the user to get the config for.
|
|
65
|
+
* @returns The user config or null if not found.
|
|
44
66
|
*/
|
|
45
67
|
getForUser(userId: ObjectId): Promise<DashboardUserConfig | null>;
|
|
46
68
|
/**
|
|
@@ -52,6 +74,8 @@ export default class DashboardUserConfigRepository extends DashboardBaseReposito
|
|
|
52
74
|
*
|
|
53
75
|
* If a collaborator is added to a user config, the collaborator will have
|
|
54
76
|
* the user added to their collaborators list.
|
|
77
|
+
*
|
|
78
|
+
* @param docSets The array of document sets containing original and updated documents.
|
|
55
79
|
*/
|
|
56
80
|
private updateCollaboratorsIfNeeded;
|
|
57
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DashboardUserConfigRepository.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"DashboardUserConfigRepository.d.ts","sourceRoot":"./src/","sources":["repositories/dashboard/DashboardUserConfigRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,EAEL,eAAe,EAEf,YAAY,EACb,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,aAAa,EAAE,MAAM,2CAA2C,CAAC;AAG1E,OAAO,uBAAuB,MAAM,8BAA8B,CAAC;AAEnE;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,6BAA8B,SAAQ,uBAAuB,CAAC,mBAAmB,CAAC;IACrG,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAgC;IAEjE;;OAEG;IACH,OAAO;IAQP;;;;OAIG;IACH,MAAM,CAAC,uBAAuB,IAAI,aAAa,CAAC,IAAI,CAAC;IAoCrD,SAAS,CAAC,gBAAgB,IAAI,IAAI;IAElC;;;;OAIG;WACW,OAAO,IAAI,6BAA6B;IAQtD;;;;;;OAMG;IACG,SAAS,CACb,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;IAatC;;;;;;;OAOG;IACG,UAAU,CACd,OAAO,EAAE,mBAAmB,EAAE,GAC7B,OAAO,CAAC,mBAAmB,EAAE,CAAC;IAYjC;;;;;;OAMG;IACG,MAAM,CACV,UAAU,EAAE,OAAO,CAAC,mBAAmB,CAAC,GACvC,OAAO,CAAC,YAAY,CAAC,mBAAmB,CAAC,CAAC;IAY7C;;;;;;OAMG;IACG,UAAU,CACd,WAAW,EAAE,OAAO,CAAC,mBAAmB,CAAC,EAAE,GAC1C,OAAO,CAAC,eAAe,CAAC;IAkB3B;;;;;OAKG;IACG,UAAU,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;IAMvE;;;;;;;;;;;OAWG;YACW,2BAA2B;CAmD1C"}
|
|
@@ -1,20 +1,23 @@
|
|
|
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 UserConfigValidator_1 = __importDefault(require("../../validators/dashboard/UserConfigValidator"));
|
|
9
|
-
const DocumentCleaner_1 = __importDefault(require("../../util/DocumentCleaner"));
|
|
1
|
+
import { DashboardUserConfig } from '@aneuhold/core-ts-db-lib';
|
|
2
|
+
import CleanDocument from '../../util/DocumentCleaner.js';
|
|
3
|
+
import DashboardUserConfigValidator from '../../validators/dashboard/UserConfigValidator.js';
|
|
4
|
+
import DashboardBaseRepository from './DashboardBaseRepository.js';
|
|
10
5
|
/**
|
|
11
6
|
* The repository that contains {@link DashboardUserConfig} documents.
|
|
12
7
|
*/
|
|
13
|
-
class DashboardUserConfigRepository extends
|
|
8
|
+
export default class DashboardUserConfigRepository extends DashboardBaseRepository {
|
|
14
9
|
static singletonInstance;
|
|
10
|
+
/**
|
|
11
|
+
* Private constructor to enforce singleton pattern.
|
|
12
|
+
*/
|
|
15
13
|
constructor() {
|
|
16
|
-
super(
|
|
14
|
+
super(DashboardUserConfig.docType, new DashboardUserConfigValidator(), CleanDocument.userId);
|
|
17
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Gets the listeners for the user repository.
|
|
18
|
+
*
|
|
19
|
+
* @returns The listeners for the user repository.
|
|
20
|
+
*/
|
|
18
21
|
static getListenersForUserRepo() {
|
|
19
22
|
const userConfigRepo = DashboardUserConfigRepository.getRepo();
|
|
20
23
|
return {
|
|
@@ -34,18 +37,20 @@ class DashboardUserConfigRepository extends DashboardBaseRepository_1.default {
|
|
|
34
37
|
},
|
|
35
38
|
insertNew: async (user) => {
|
|
36
39
|
if (user.projectAccess.dashboard) {
|
|
37
|
-
await userConfigRepo.insertNew(new
|
|
40
|
+
await userConfigRepo.insertNew(new DashboardUserConfig(user._id));
|
|
38
41
|
}
|
|
39
42
|
},
|
|
40
43
|
insertMany: async (users) => {
|
|
41
44
|
const usersThatNeedConfig = users.filter((user) => user.projectAccess.dashboard);
|
|
42
|
-
await userConfigRepo.insertMany(usersThatNeedConfig.map((user) => new
|
|
45
|
+
await userConfigRepo.insertMany(usersThatNeedConfig.map((user) => new DashboardUserConfig(user._id)));
|
|
43
46
|
}
|
|
44
47
|
};
|
|
45
48
|
}
|
|
46
49
|
setupSubscribers() { }
|
|
47
50
|
/**
|
|
48
51
|
* Gets the singleton instance of the {@link DashboardUserConfigRepository}.
|
|
52
|
+
*
|
|
53
|
+
* @returns The singleton instance.
|
|
49
54
|
*/
|
|
50
55
|
static getRepo() {
|
|
51
56
|
if (!DashboardUserConfigRepository.singletonInstance) {
|
|
@@ -58,14 +63,15 @@ class DashboardUserConfigRepository extends DashboardBaseRepository_1.default {
|
|
|
58
63
|
* Inserts a new config for a user. If the user has collaborators, those
|
|
59
64
|
* collaborators will have the current user added to their collaborators list.
|
|
60
65
|
*
|
|
61
|
-
* @
|
|
66
|
+
* @param newDoc The new {@link DashboardUserConfig} document to insert.
|
|
67
|
+
* @returns The inserted document or null if insertion failed.
|
|
62
68
|
*/
|
|
63
69
|
async insertNew(newDoc) {
|
|
64
70
|
const result = await super.insertNew(newDoc);
|
|
65
71
|
if (newDoc.collaborators.length > 0) {
|
|
66
72
|
await this.updateCollaboratorsIfNeeded([
|
|
67
73
|
{
|
|
68
|
-
originalDoc: new
|
|
74
|
+
originalDoc: new DashboardUserConfig(newDoc.userId),
|
|
69
75
|
updatedDoc: newDoc
|
|
70
76
|
}
|
|
71
77
|
]);
|
|
@@ -77,13 +83,14 @@ class DashboardUserConfigRepository extends DashboardBaseRepository_1.default {
|
|
|
77
83
|
* those collaborators will have the current user added to their collaborators
|
|
78
84
|
* list.
|
|
79
85
|
*
|
|
80
|
-
* @
|
|
86
|
+
* @param newDocs The list of new {@link DashboardUserConfig} documents to insert.
|
|
87
|
+
* @returns The list of inserted documents.
|
|
81
88
|
*/
|
|
82
89
|
async insertMany(newDocs) {
|
|
83
90
|
const result = await super.insertMany(newDocs);
|
|
84
91
|
// Simulate having no collaborators originally.
|
|
85
92
|
await this.updateCollaboratorsIfNeeded(newDocs.map((doc) => ({
|
|
86
|
-
originalDoc: new
|
|
93
|
+
originalDoc: new DashboardUserConfig(doc.userId),
|
|
87
94
|
updatedDoc: doc
|
|
88
95
|
})));
|
|
89
96
|
return result;
|
|
@@ -92,7 +99,8 @@ class DashboardUserConfigRepository extends DashboardBaseRepository_1.default {
|
|
|
92
99
|
* Updates a user config. If the user has collaborators, those collaborators
|
|
93
100
|
* will have the current user added to their collaborators list.
|
|
94
101
|
*
|
|
95
|
-
* @
|
|
102
|
+
* @param updatedDoc The updated {@link DashboardUserConfig} document.
|
|
103
|
+
* @returns The result of the update operation.
|
|
96
104
|
*/
|
|
97
105
|
async update(updatedDoc) {
|
|
98
106
|
// Get the config before the update
|
|
@@ -105,6 +113,13 @@ class DashboardUserConfigRepository extends DashboardBaseRepository_1.default {
|
|
|
105
113
|
}
|
|
106
114
|
return result;
|
|
107
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Updates multiple user configs. If the users have collaborators, those collaborators
|
|
118
|
+
* will have the current user added to their collaborators list.
|
|
119
|
+
*
|
|
120
|
+
* @param updatedDocs The list of updated {@link DashboardUserConfig} documents.
|
|
121
|
+
* @returns The result of the bulk update operation.
|
|
122
|
+
*/
|
|
108
123
|
async updateMany(updatedDocs) {
|
|
109
124
|
const docIds = [];
|
|
110
125
|
updatedDocs.forEach((doc) => {
|
|
@@ -122,7 +137,9 @@ class DashboardUserConfigRepository extends DashboardBaseRepository_1.default {
|
|
|
122
137
|
}
|
|
123
138
|
/**
|
|
124
139
|
* Gets the config for a given user.
|
|
140
|
+
*
|
|
125
141
|
* @param userId The ID of the user to get the config for.
|
|
142
|
+
* @returns The user config or null if not found.
|
|
126
143
|
*/
|
|
127
144
|
async getForUser(userId) {
|
|
128
145
|
const collection = await this.getCollection();
|
|
@@ -138,6 +155,8 @@ class DashboardUserConfigRepository extends DashboardBaseRepository_1.default {
|
|
|
138
155
|
*
|
|
139
156
|
* If a collaborator is added to a user config, the collaborator will have
|
|
140
157
|
* the user added to their collaborators list.
|
|
158
|
+
*
|
|
159
|
+
* @param docSets The array of document sets containing original and updated documents.
|
|
141
160
|
*/
|
|
142
161
|
async updateCollaboratorsIfNeeded(docSets) {
|
|
143
162
|
const bulkOps = [];
|
|
@@ -181,4 +200,4 @@ class DashboardUserConfigRepository extends DashboardBaseRepository_1.default {
|
|
|
181
200
|
}
|
|
182
201
|
}
|
|
183
202
|
}
|
|
184
|
-
|
|
203
|
+
//# sourceMappingURL=DashboardUserConfigRepository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DashboardUserConfigRepository.js","sourceRoot":"./src/","sources":["repositories/dashboard/DashboardUserConfigRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAQ,MAAM,0BAA0B,CAAC;AASrE,OAAO,aAAa,MAAM,+BAA+B,CAAC;AAC1D,OAAO,4BAA4B,MAAM,mDAAmD,CAAC;AAC7F,OAAO,uBAAuB,MAAM,8BAA8B,CAAC;AAEnE;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,6BAA8B,SAAQ,uBAA4C;IAC7F,MAAM,CAAC,iBAAiB,CAAiC;IAEjE;;OAEG;IACH;QACE,KAAK,CACH,mBAAmB,CAAC,OAAO,EAC3B,IAAI,4BAA4B,EAAE,EAClC,aAAa,CAAC,MAAM,CACrB,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,uBAAuB;QAC5B,MAAM,cAAc,GAAG,6BAA6B,CAAC,OAAO,EAAE,CAAC;QAC/D,OAAO;YACL,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;gBAC1B,MAAM,UAAU,GAAG,MAAM,cAAc,CAAC,aAAa,EAAE,CAAC;gBACxD,MAAM,UAAU,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;gBACvC,MAAM,UAAU,CAAC,UAAU,CACzB,EAAE,aAAa,EAAE,MAAM,EAAE,EACzB,EAAE,KAAK,EAAE,EAAE,aAAa,EAAE,MAAM,EAAE,EAAE,CACrC,CAAC;YACJ,CAAC;YACD,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;g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
|
|
5
|
+
BulkWriteResult,
|
|
6
|
+
UpdateFilter,
|
|
7
|
+
UpdateResult
|
|
8
|
+
} from 'mongodb';
|
|
9
|
+
import { RepoListeners } from '../../services/RepoSubscriptionService.js';
|
|
10
|
+
import CleanDocument from '../../util/DocumentCleaner.js';
|
|
11
|
+
import DashboardUserConfigValidator from '../../validators/dashboard/UserConfigValidator.js';
|
|
12
|
+
import DashboardBaseRepository from './DashboardBaseRepository.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The repository that contains {@link DashboardUserConfig} documents.
|
|
16
|
+
*/
|
|
17
|
+
export default class DashboardUserConfigRepository extends DashboardBaseRepository<DashboardUserConfig> {
|
|
18
|
+
private static singletonInstance?: DashboardUserConfigRepository;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Private constructor to enforce singleton pattern.
|
|
22
|
+
*/
|
|
23
|
+
private constructor() {
|
|
24
|
+
super(
|
|
25
|
+
DashboardUserConfig.docType,
|
|
26
|
+
new DashboardUserConfigValidator(),
|
|
27
|
+
CleanDocument.userId
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Gets the listeners for the user repository.
|
|
33
|
+
*
|
|
34
|
+
* @returns The listeners for the user repository.
|
|
35
|
+
*/
|
|
36
|
+
static getListenersForUserRepo(): RepoListeners<User> {
|
|
37
|
+
const userConfigRepo = DashboardUserConfigRepository.getRepo();
|
|
38
|
+
return {
|
|
39
|
+
deleteOne: async (userId) => {
|
|
40
|
+
const collection = await userConfigRepo.getCollection();
|
|
41
|
+
await collection.deleteOne({ userId });
|
|
42
|
+
await collection.updateMany(
|
|
43
|
+
{ collaborators: userId },
|
|
44
|
+
{ $pull: { collaborators: userId } }
|
|
45
|
+
);
|
|
46
|
+
},
|
|
47
|
+
deleteList: async (userIds) => {
|
|
48
|
+
const collection = await userConfigRepo.getCollection();
|
|
49
|
+
await collection.deleteMany({
|
|
50
|
+
userId: { $in: userIds }
|
|
51
|
+
});
|
|
52
|
+
await collection.updateMany({ collaborators: { $in: userIds } }, {
|
|
53
|
+
$pull: { collaborators: { $in: userIds } }
|
|
54
|
+
} as UpdateFilter<DashboardUserConfig>);
|
|
55
|
+
},
|
|
56
|
+
insertNew: async (user) => {
|
|
57
|
+
if (user.projectAccess.dashboard) {
|
|
58
|
+
await userConfigRepo.insertNew(new DashboardUserConfig(user._id));
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
insertMany: async (users) => {
|
|
62
|
+
const usersThatNeedConfig = users.filter(
|
|
63
|
+
(user) => user.projectAccess.dashboard
|
|
64
|
+
);
|
|
65
|
+
await userConfigRepo.insertMany(
|
|
66
|
+
usersThatNeedConfig.map((user) => new DashboardUserConfig(user._id))
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
protected setupSubscribers(): void {}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Gets the singleton instance of the {@link DashboardUserConfigRepository}.
|
|
76
|
+
*
|
|
77
|
+
* @returns The singleton instance.
|
|
78
|
+
*/
|
|
79
|
+
public static getRepo(): DashboardUserConfigRepository {
|
|
80
|
+
if (!DashboardUserConfigRepository.singletonInstance) {
|
|
81
|
+
DashboardUserConfigRepository.singletonInstance =
|
|
82
|
+
new DashboardUserConfigRepository();
|
|
83
|
+
}
|
|
84
|
+
return DashboardUserConfigRepository.singletonInstance;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Inserts a new config for a user. If the user has collaborators, those
|
|
89
|
+
* collaborators will have the current user added to their collaborators list.
|
|
90
|
+
*
|
|
91
|
+
* @param newDoc The new {@link DashboardUserConfig} document to insert.
|
|
92
|
+
* @returns The inserted document or null if insertion failed.
|
|
93
|
+
*/
|
|
94
|
+
async insertNew(
|
|
95
|
+
newDoc: DashboardUserConfig
|
|
96
|
+
): Promise<DashboardUserConfig | null> {
|
|
97
|
+
const result = await super.insertNew(newDoc);
|
|
98
|
+
if (newDoc.collaborators.length > 0) {
|
|
99
|
+
await this.updateCollaboratorsIfNeeded([
|
|
100
|
+
{
|
|
101
|
+
originalDoc: new DashboardUserConfig(newDoc.userId),
|
|
102
|
+
updatedDoc: newDoc
|
|
103
|
+
}
|
|
104
|
+
]);
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Inserts a list of new configs for users. If the users have collaborators,
|
|
111
|
+
* those collaborators will have the current user added to their collaborators
|
|
112
|
+
* list.
|
|
113
|
+
*
|
|
114
|
+
* @param newDocs The list of new {@link DashboardUserConfig} documents to insert.
|
|
115
|
+
* @returns The list of inserted documents.
|
|
116
|
+
*/
|
|
117
|
+
async insertMany(
|
|
118
|
+
newDocs: DashboardUserConfig[]
|
|
119
|
+
): Promise<DashboardUserConfig[]> {
|
|
120
|
+
const result = await super.insertMany(newDocs);
|
|
121
|
+
// Simulate having no collaborators originally.
|
|
122
|
+
await this.updateCollaboratorsIfNeeded(
|
|
123
|
+
newDocs.map((doc) => ({
|
|
124
|
+
originalDoc: new DashboardUserConfig(doc.userId),
|
|
125
|
+
updatedDoc: doc
|
|
126
|
+
}))
|
|
127
|
+
);
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Updates a user config. If the user has collaborators, those collaborators
|
|
133
|
+
* will have the current user added to their collaborators list.
|
|
134
|
+
*
|
|
135
|
+
* @param updatedDoc The updated {@link DashboardUserConfig} document.
|
|
136
|
+
* @returns The result of the update operation.
|
|
137
|
+
*/
|
|
138
|
+
async update(
|
|
139
|
+
updatedDoc: Partial<DashboardUserConfig>
|
|
140
|
+
): Promise<UpdateResult<DashboardUserConfig>> {
|
|
141
|
+
// Get the config before the update
|
|
142
|
+
const originalDoc = await super.get({ _id: updatedDoc._id });
|
|
143
|
+
const result = await super.update(updatedDoc);
|
|
144
|
+
if (originalDoc) {
|
|
145
|
+
await this.updateCollaboratorsIfNeeded([
|
|
146
|
+
{ originalDoc, updatedDoc: updatedDoc as DashboardUserConfig }
|
|
147
|
+
]);
|
|
148
|
+
}
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Updates multiple user configs. If the users have collaborators, those collaborators
|
|
154
|
+
* will have the current user added to their collaborators list.
|
|
155
|
+
*
|
|
156
|
+
* @param updatedDocs The list of updated {@link DashboardUserConfig} documents.
|
|
157
|
+
* @returns The result of the bulk update operation.
|
|
158
|
+
*/
|
|
159
|
+
async updateMany(
|
|
160
|
+
updatedDocs: Partial<DashboardUserConfig>[]
|
|
161
|
+
): Promise<BulkWriteResult> {
|
|
162
|
+
const docIds: ObjectId[] = [];
|
|
163
|
+
updatedDocs.forEach((doc) => {
|
|
164
|
+
if (doc._id) {
|
|
165
|
+
docIds.push(doc._id);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
const originalDocs = await super.getList(docIds);
|
|
169
|
+
const result = await super.updateMany(updatedDocs);
|
|
170
|
+
await this.updateCollaboratorsIfNeeded(
|
|
171
|
+
originalDocs.map((originalDoc, index) => ({
|
|
172
|
+
originalDoc,
|
|
173
|
+
updatedDoc: updatedDocs[index] as DashboardUserConfig
|
|
174
|
+
}))
|
|
175
|
+
);
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Gets the config for a given user.
|
|
181
|
+
*
|
|
182
|
+
* @param userId The ID of the user to get the config for.
|
|
183
|
+
* @returns The user config or null if not found.
|
|
184
|
+
*/
|
|
185
|
+
async getForUser(userId: ObjectId): Promise<DashboardUserConfig | null> {
|
|
186
|
+
const collection = await this.getCollection();
|
|
187
|
+
const result = await collection.findOne({ userId });
|
|
188
|
+
return result as DashboardUserConfig | null;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Updates the user configs for the collaborators of the provided user
|
|
193
|
+
* configs.
|
|
194
|
+
*
|
|
195
|
+
* If a collaborator is removed from a user config, the collaborator will
|
|
196
|
+
* have the user removed from their collaborators list.
|
|
197
|
+
*
|
|
198
|
+
* If a collaborator is added to a user config, the collaborator will have
|
|
199
|
+
* the user added to their collaborators list.
|
|
200
|
+
*
|
|
201
|
+
* @param docSets The array of document sets containing original and updated documents.
|
|
202
|
+
*/
|
|
203
|
+
private async updateCollaboratorsIfNeeded(
|
|
204
|
+
docSets: Array<{
|
|
205
|
+
originalDoc: DashboardUserConfig;
|
|
206
|
+
updatedDoc: Partial<DashboardUserConfig>;
|
|
207
|
+
}>
|
|
208
|
+
) {
|
|
209
|
+
const bulkOps: AnyBulkWriteOperation<DashboardUserConfig>[] = [];
|
|
210
|
+
// For each set of documents
|
|
211
|
+
docSets.forEach((docSet) => {
|
|
212
|
+
const originalCollaborators = docSet.originalDoc.collaborators;
|
|
213
|
+
const updatedCollaborators = docSet.updatedDoc.collaborators;
|
|
214
|
+
if (
|
|
215
|
+
updatedCollaborators &&
|
|
216
|
+
!this.objectIdArraysAreEqual(
|
|
217
|
+
originalCollaborators,
|
|
218
|
+
updatedCollaborators
|
|
219
|
+
)
|
|
220
|
+
) {
|
|
221
|
+
// For each original collaborator, if they are not in the updated list,
|
|
222
|
+
// remove the user from their collaborators list
|
|
223
|
+
originalCollaborators.forEach((collaboratorId) => {
|
|
224
|
+
if (!updatedCollaborators.includes(collaboratorId)) {
|
|
225
|
+
bulkOps.push({
|
|
226
|
+
updateOne: {
|
|
227
|
+
filter: { userId: collaboratorId },
|
|
228
|
+
update: { $pull: { collaborators: docSet.originalDoc.userId } }
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
// For each updated collaborator, if they are not in the original list,
|
|
234
|
+
// add the user to their collaborators list
|
|
235
|
+
updatedCollaborators.forEach((collaboratorId) => {
|
|
236
|
+
if (!originalCollaborators.includes(collaboratorId)) {
|
|
237
|
+
bulkOps.push({
|
|
238
|
+
updateOne: {
|
|
239
|
+
filter: { userId: collaboratorId },
|
|
240
|
+
update: {
|
|
241
|
+
$addToSet: { collaborators: docSet.originalDoc.userId }
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
if (bulkOps.length !== 0) {
|
|
250
|
+
const collection = await this.getCollection();
|
|
251
|
+
await collection.bulkWrite(bulkOps);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MigrationService.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"MigrationService.d.ts","sourceRoot":"./src/","sources":["services/MigrationService.ts"],"names":[],"mappings":"AAKA;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAgB;IACnC;;;;;;;;OAQG;WACU,SAAS,CAAC,MAAM,UAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;CA6BtD"}
|
|
@@ -1,12 +1,7 @@
|
|
|
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
1
|
/* eslint-disable */
|
|
7
2
|
// @ts-nocheck
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
import { Logger } from '@aneuhold/core-ts-lib';
|
|
4
|
+
import UserRepository from '../repositories/common/UserRepository.js';
|
|
10
5
|
/**
|
|
11
6
|
* A service for migrating the DB to a new state after an existing document
|
|
12
7
|
* change.
|
|
@@ -14,7 +9,7 @@ const UserRepository_1 = __importDefault(require("../repositories/common/UserRep
|
|
|
14
9
|
* This entire class is ignored from ESLint and TypeScript to allow for
|
|
15
10
|
* manipulating the DB in any way necessary.
|
|
16
11
|
*/
|
|
17
|
-
class MigrationService {
|
|
12
|
+
export default class MigrationService {
|
|
18
13
|
/**
|
|
19
14
|
* A function that can be used to migrate the DB to a new state after an
|
|
20
15
|
* existing document change.
|
|
@@ -25,12 +20,12 @@ class MigrationService {
|
|
|
25
20
|
* @param dryRun Whether or not to actually make the changes or just log them.
|
|
26
21
|
*/
|
|
27
22
|
static async migrateDb(dryRun = false) {
|
|
28
|
-
const userRepo =
|
|
23
|
+
const userRepo = UserRepository.getRepo();
|
|
29
24
|
const allUsers = (await userRepo.getAll());
|
|
30
25
|
const updatedUsers = [];
|
|
31
26
|
allUsers.forEach((user) => {
|
|
32
27
|
if (user.password) {
|
|
33
|
-
|
|
28
|
+
Logger.error(`User with ID: ${user._id} has a password in the wrong spot.`);
|
|
34
29
|
user.auth.password = user.password;
|
|
35
30
|
delete user.password;
|
|
36
31
|
updatedUsers.push(user);
|
|
@@ -38,20 +33,20 @@ class MigrationService {
|
|
|
38
33
|
});
|
|
39
34
|
if (dryRun) {
|
|
40
35
|
if (updatedUsers.length > 0) {
|
|
41
|
-
|
|
36
|
+
Logger.info(`Would update ${updatedUsers.length} users.`);
|
|
42
37
|
}
|
|
43
38
|
else {
|
|
44
|
-
|
|
39
|
+
Logger.success('No changes to make.');
|
|
45
40
|
}
|
|
46
41
|
return;
|
|
47
42
|
}
|
|
48
43
|
if (updatedUsers.length > 0) {
|
|
49
|
-
|
|
44
|
+
Logger.info(`Updating ${updatedUsers.length} users.`);
|
|
50
45
|
await userRepo.updateMany(updatedUsers);
|
|
51
46
|
}
|
|
52
47
|
else {
|
|
53
|
-
|
|
48
|
+
Logger.success('No changes to make.');
|
|
54
49
|
}
|
|
55
50
|
}
|
|
56
51
|
}
|
|
57
|
-
|
|
52
|
+
//# sourceMappingURL=MigrationService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MigrationService.js","sourceRoot":"./src/","sources":["services/MigrationService.ts"],"names":[],"mappings":"AAAA,oBAAoB;AAC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AAC;aAAM,CAAC;YACN,MAAM,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
import { Logger } from '@aneuhold/core-ts-lib';
|
|
4
|
+
import UserRepository from '../repositories/common/UserRepository.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A service for migrating the DB to a new state after an existing document
|
|
8
|
+
* change.
|
|
9
|
+
*
|
|
10
|
+
* This entire class is ignored from ESLint and TypeScript to allow for
|
|
11
|
+
* manipulating the DB in any way necessary.
|
|
12
|
+
*/
|
|
13
|
+
export default class MigrationService {
|
|
14
|
+
/**
|
|
15
|
+
* A function that can be used to migrate the DB to a new state after an
|
|
16
|
+
* existing document change.
|
|
17
|
+
*
|
|
18
|
+
* ❗️ BEWARE!!! ❗️
|
|
19
|
+
* TRIPLE CHECK THAT THIS IS WHAT YOU WANT TO DO BEFORE RUNNING THIS FUNCTION.
|
|
20
|
+
*
|
|
21
|
+
* @param dryRun Whether or not to actually make the changes or just log them.
|
|
22
|
+
*/
|
|
23
|
+
static async migrateDb(dryRun = false): Promise<void> {
|
|
24
|
+
const userRepo = UserRepository.getRepo();
|
|
25
|
+
const allUsers = (await userRepo.getAll()) as any;
|
|
26
|
+
const updatedUsers = [];
|
|
27
|
+
allUsers.forEach((user) => {
|
|
28
|
+
if (user.password) {
|
|
29
|
+
Logger.error(
|
|
30
|
+
`User with ID: ${user._id} has a password in the wrong spot.`
|
|
31
|
+
);
|
|
32
|
+
user.auth.password = user.password;
|
|
33
|
+
delete user.password;
|
|
34
|
+
updatedUsers.push(user);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
if (dryRun) {
|
|
38
|
+
if (updatedUsers.length > 0) {
|
|
39
|
+
Logger.info(`Would update ${updatedUsers.length} users.`);
|
|
40
|
+
} else {
|
|
41
|
+
Logger.success('No changes to make.');
|
|
42
|
+
}
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (updatedUsers.length > 0) {
|
|
46
|
+
Logger.info(`Updating ${updatedUsers.length} users.`);
|
|
47
|
+
await userRepo.updateMany(updatedUsers);
|
|
48
|
+
} else {
|
|
49
|
+
Logger.success('No changes to make.');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RepoSubscriptionService.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"RepoSubscriptionService.d.ts","sourceRoot":"./src/","sources":["services/RepoSubscriptionService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAEhC,MAAM,MAAM,eAAe,CAAC,QAAQ,SAAS,YAAY,IAAI;IAC3D,SAAS,EAAE,mBAAmB,CAAC,QAAQ,CAAC,EAAE,CAAC;IAC3C,UAAU,EAAE,oBAAoB,CAAC,QAAQ,CAAC,EAAE,CAAC;IAC7C,SAAS,EAAE,mBAAmB,CAAC,QAAQ,CAAC,EAAE,CAAC;IAC3C,UAAU,EAAE,oBAAoB,CAAC,QAAQ,CAAC,EAAE,CAAC;IAC7C,SAAS,EAAE,mBAAmB,EAAE,CAAC;IACjC,UAAU,EAAE,oBAAoB,EAAE,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,aAAa,CAAC,QAAQ,SAAS,YAAY,IAAI;IACzD,SAAS,CAAC,EAAE,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IAC1C,UAAU,CAAC,EAAE,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IAC5C,SAAS,CAAC,EAAE,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IAC1C,UAAU,CAAC,EAAE,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IAC5C,SAAS,CAAC,EAAE,mBAAmB,CAAC;IAChC,UAAU,CAAC,EAAE,oBAAoB,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,mBAAmB,CAAC,QAAQ,SAAS,YAAY,IAAI,CAC/D,GAAG,EAAE,QAAQ,KACV,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnB,MAAM,MAAM,oBAAoB,CAAC,QAAQ,SAAS,YAAY,IAAI,CAChE,IAAI,EAAE,QAAQ,EAAE,KACb,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnB,MAAM,MAAM,mBAAmB,CAAC,QAAQ,SAAS,YAAY,IAAI,CAC/D,GAAG,EAAE,OAAO,CAAC,QAAQ,CAAC,KACnB,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnB,MAAM,MAAM,oBAAoB,CAAC,QAAQ,SAAS,YAAY,IAAI,CAChE,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,KACtB,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnB,MAAM,MAAM,mBAAmB,GAAG,CAAC,KAAK,EAAE,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAErE,MAAM,MAAM,oBAAoB,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzE;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,uBAAuB;IAC1C;;;OAGG;IACH,MAAM,CAAC,qBAAqB,CAC1B,QAAQ,SAAS,YAAY,KAC1B,eAAe,CAAC,QAAQ,CAAC;CAU/B"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
1
|
/**
|
|
4
2
|
* A subscription service that allows repositories to subscribe to events
|
|
5
3
|
* that happen in other repositories.
|
|
6
4
|
*/
|
|
7
|
-
class RepoSubscriptionService {
|
|
5
|
+
export default class RepoSubscriptionService {
|
|
8
6
|
/**
|
|
9
7
|
* A utility method to get a default empty set of subscribers for a
|
|
10
8
|
* repository.
|
|
@@ -20,4 +18,4 @@ class RepoSubscriptionService {
|
|
|
20
18
|
};
|
|
21
19
|
}
|
|
22
20
|
}
|
|
23
|
-
|
|
21
|
+
//# sourceMappingURL=RepoSubscriptionService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RepoSubscriptionService.js","sourceRoot":"./src/","sources":["services/RepoSubscriptionService.ts"],"names":[],"mappings":"AAyCA;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,uBAAuB;IAC1C;;;OAGG;IACH,MAAM,CAAC,qBAAqB;QAG1B,OAAO;YACL,SAAS,EAAE,EAAE;YACb,UAAU,EAAE,EAAE;YACd,SAAS,EAAE,EAAE;YACb,UAAU,EAAE,EAAE;YACd,SAAS,EAAE,EAAE;YACb,UAAU,EAAE,EAAE;SACf,CAAC;IACJ,CAAC;CACF"}
|