@chevre/domain 22.3.0-alpha.13 → 22.3.0-alpha.14
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.
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
// const project = { id: String(process.env.PROJECT_ID) };
|
|
7
|
+
|
|
8
|
+
// tslint:disable-next-line:max-func-body-length
|
|
9
|
+
async function main() {
|
|
10
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
11
|
+
|
|
12
|
+
const eventSeriesRepo = await chevre.repository.EventSeries.createInstance(mongoose.connection);
|
|
13
|
+
|
|
14
|
+
const cursor = eventSeriesRepo.getCursor(
|
|
15
|
+
{
|
|
16
|
+
typeOf: { $eq: chevre.factory.eventType.ScreeningEventSeries }
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
_id: 1,
|
|
20
|
+
startDate: 1,
|
|
21
|
+
project: 1,
|
|
22
|
+
typeOf: 1
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
console.log('docs found');
|
|
26
|
+
|
|
27
|
+
let i = 0;
|
|
28
|
+
let updateCount = 0;
|
|
29
|
+
await cursor.eachAsync(async (doc) => {
|
|
30
|
+
i += 1;
|
|
31
|
+
const eventSeries: Pick<chevre.factory.event.screeningEventSeries.IEvent, 'id' | 'startDate' | 'project' | 'typeOf'> =
|
|
32
|
+
doc.toObject();
|
|
33
|
+
const alreadyMigrated = false;
|
|
34
|
+
if (alreadyMigrated) {
|
|
35
|
+
console.log(
|
|
36
|
+
'already exist.',
|
|
37
|
+
eventSeries.project.id,
|
|
38
|
+
eventSeries.typeOf,
|
|
39
|
+
eventSeries.id,
|
|
40
|
+
eventSeries.startDate, i, updateCount
|
|
41
|
+
);
|
|
42
|
+
} else {
|
|
43
|
+
updateCount += 1;
|
|
44
|
+
console.log(
|
|
45
|
+
'updating...',
|
|
46
|
+
eventSeries.project.id,
|
|
47
|
+
eventSeries.typeOf,
|
|
48
|
+
eventSeries.id,
|
|
49
|
+
eventSeries.startDate, i, updateCount
|
|
50
|
+
);
|
|
51
|
+
await eventSeriesRepo.sync2secondary({
|
|
52
|
+
id: eventSeries.id
|
|
53
|
+
});
|
|
54
|
+
console.log(
|
|
55
|
+
'updated.',
|
|
56
|
+
eventSeries.project.id,
|
|
57
|
+
eventSeries.typeOf,
|
|
58
|
+
eventSeries.id,
|
|
59
|
+
eventSeries.startDate, i, updateCount
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
console.log(i, 'docs checked');
|
|
65
|
+
console.log(updateCount, 'docs updated');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
main()
|
|
69
|
+
.then()
|
|
70
|
+
.catch(console.error);
|
package/lib/chevre/repo/event.js
CHANGED
|
@@ -777,7 +777,7 @@ class EventRepo {
|
|
|
777
777
|
findAnyEventById(params) {
|
|
778
778
|
var _a;
|
|
779
779
|
return __awaiter(this, void 0, void 0, function* () {
|
|
780
|
-
const doc = yield this.eventModel.findOne(Object.assign({ _id: { $eq: params.id.$eq }, 'project.id': { $eq: params.project.id.$eq } }, (typeof ((_a = params.organizer) === null || _a === void 0 ? void 0 : _a.id.$eq) === 'string')
|
|
780
|
+
const doc = yield this.eventModel.findOne(Object.assign({ _id: { $eq: params.id.$eq }, 'project.id': { $eq: params.project.id.$eq }, typeOf: { $in: [factory.eventType.Event, factory.eventType.ScreeningEvent] } }, (typeof ((_a = params.organizer) === null || _a === void 0 ? void 0 : _a.id.$eq) === 'string')
|
|
781
781
|
? { 'organizer.id': { $exists: true, $eq: params.organizer.id.$eq } }
|
|
782
782
|
: undefined), {
|
|
783
783
|
__v: 0,
|
|
@@ -1,6 +1,31 @@
|
|
|
1
|
+
/// <reference types="mongoose/types/aggregate" />
|
|
2
|
+
/// <reference types="mongoose/types/callback" />
|
|
3
|
+
/// <reference types="mongoose/types/collection" />
|
|
4
|
+
/// <reference types="mongoose/types/connection" />
|
|
5
|
+
/// <reference types="mongoose/types/cursor" />
|
|
6
|
+
/// <reference types="mongoose/types/document" />
|
|
7
|
+
/// <reference types="mongoose/types/error" />
|
|
8
|
+
/// <reference types="mongoose/types/expressions" />
|
|
9
|
+
/// <reference types="mongoose/types/helpers" />
|
|
10
|
+
/// <reference types="mongoose/types/middlewares" />
|
|
11
|
+
/// <reference types="mongoose/types/indexes" />
|
|
12
|
+
/// <reference types="mongoose/types/models" />
|
|
13
|
+
/// <reference types="mongoose/types/mongooseoptions" />
|
|
14
|
+
/// <reference types="mongoose/types/pipelinestage" />
|
|
15
|
+
/// <reference types="mongoose/types/populate" />
|
|
16
|
+
/// <reference types="mongoose/types/query" />
|
|
17
|
+
/// <reference types="mongoose/types/schemaoptions" />
|
|
18
|
+
/// <reference types="mongoose/types/schematypes" />
|
|
19
|
+
/// <reference types="mongoose/types/session" />
|
|
20
|
+
/// <reference types="mongoose/types/types" />
|
|
21
|
+
/// <reference types="mongoose/types/utility" />
|
|
22
|
+
/// <reference types="mongoose/types/validation" />
|
|
23
|
+
/// <reference types="mongoose/types/virtuals" />
|
|
24
|
+
/// <reference types="mongoose/types/inferschematype" />
|
|
1
25
|
import type { BulkWriteResult } from 'mongodb';
|
|
2
|
-
import type { Connection, FilterQuery } from 'mongoose';
|
|
26
|
+
import type { Connection, Document, FilterQuery } from 'mongoose';
|
|
3
27
|
import * as factory from '../factory';
|
|
28
|
+
import { IDocType } from './mongoose/schemas/event';
|
|
4
29
|
type ISearchConditions = Omit<factory.event.ISearchConditions<factory.eventType.ScreeningEventSeries>, 'typeOfIn' | 'hasOfferCatalog'>;
|
|
5
30
|
type IKeyOfProjection = Exclude<keyof factory.event.IEvent<factory.eventType.ScreeningEventSeries>, 'id'>;
|
|
6
31
|
type IUnset = {
|
|
@@ -107,5 +132,34 @@ export declare class EventSeriesRepo {
|
|
|
107
132
|
sync2secondary(params: {
|
|
108
133
|
id: string;
|
|
109
134
|
}): Promise<void>;
|
|
135
|
+
getCursor(conditions: FilterQuery<any>, projection: any): import("mongoose").Cursor<Document<unknown, {}, IDocType> & Omit<(import("@chevre/factory/lib/event/anyEvent").IAttributes & {
|
|
136
|
+
_id: string;
|
|
137
|
+
} & Required<{
|
|
138
|
+
_id: string;
|
|
139
|
+
}>) | (import("@chevre/factory/lib/event/screeningEvent").IAttributes & {
|
|
140
|
+
_id: string;
|
|
141
|
+
alternateName?: any;
|
|
142
|
+
aggregateOffer?: import("@chevre/factory/lib/event/anyEvent").IAggregateOffer | undefined;
|
|
143
|
+
} & Required<{
|
|
144
|
+
_id: string;
|
|
145
|
+
}>) | (import("@chevre/factory/lib/event/screeningEventSeries").IAttributes & {
|
|
146
|
+
_id: string;
|
|
147
|
+
} & Required<{
|
|
148
|
+
_id: string;
|
|
149
|
+
}>), never>, import("mongoose").QueryOptions<Document<unknown, {}, IDocType> & Omit<(import("@chevre/factory/lib/event/anyEvent").IAttributes & {
|
|
150
|
+
_id: string;
|
|
151
|
+
} & Required<{
|
|
152
|
+
_id: string;
|
|
153
|
+
}>) | (import("@chevre/factory/lib/event/screeningEvent").IAttributes & {
|
|
154
|
+
_id: string;
|
|
155
|
+
alternateName?: any;
|
|
156
|
+
aggregateOffer?: import("@chevre/factory/lib/event/anyEvent").IAggregateOffer | undefined;
|
|
157
|
+
} & Required<{
|
|
158
|
+
_id: string;
|
|
159
|
+
}>) | (import("@chevre/factory/lib/event/screeningEventSeries").IAttributes & {
|
|
160
|
+
_id: string;
|
|
161
|
+
} & Required<{
|
|
162
|
+
_id: string;
|
|
163
|
+
}>), never>>>;
|
|
110
164
|
}
|
|
111
165
|
export {};
|
|
@@ -645,5 +645,10 @@ class EventSeriesRepo {
|
|
|
645
645
|
}
|
|
646
646
|
});
|
|
647
647
|
}
|
|
648
|
+
getCursor(conditions, projection) {
|
|
649
|
+
return this.eventModel.find(conditions, projection)
|
|
650
|
+
.sort({ startDate: factory.sortType.Descending })
|
|
651
|
+
.cursor();
|
|
652
|
+
}
|
|
648
653
|
}
|
|
649
654
|
exports.EventSeriesRepo = EventSeriesRepo;
|
package/package.json
CHANGED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console
|
|
2
|
-
import * as mongoose from 'mongoose';
|
|
3
|
-
|
|
4
|
-
import { chevre } from '../../../lib/index';
|
|
5
|
-
|
|
6
|
-
// const project = { id: String(process.env.PROJECT_ID) };
|
|
7
|
-
|
|
8
|
-
const NEW_ROLE_NAME = 'sellerAdmin';
|
|
9
|
-
|
|
10
|
-
// tslint:disable-next-line:max-func-body-length
|
|
11
|
-
async function main() {
|
|
12
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
13
|
-
|
|
14
|
-
const memberRepo = await chevre.repository.Member.createInstance(mongoose.connection);
|
|
15
|
-
|
|
16
|
-
const cursor = memberRepo.getCursor(
|
|
17
|
-
{
|
|
18
|
-
'member.memberOf.typeOf': { $eq: chevre.factory.organizationType.Project },
|
|
19
|
-
'member.hasRole.roleName': { $eq: 'inventoryManager' }
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
}
|
|
23
|
-
);
|
|
24
|
-
console.log('members found');
|
|
25
|
-
|
|
26
|
-
let i = 0;
|
|
27
|
-
let updateCount = 0;
|
|
28
|
-
await cursor.eachAsync(async (doc) => {
|
|
29
|
-
i += 1;
|
|
30
|
-
const inventoryManager: chevre.factory.iam.IMember = doc.toObject();
|
|
31
|
-
const alreadyMigrated = inventoryManager.member.hasRole.some(({ roleName }) => roleName === NEW_ROLE_NAME);
|
|
32
|
-
if (alreadyMigrated) {
|
|
33
|
-
console.log(
|
|
34
|
-
'already exist.',
|
|
35
|
-
inventoryManager.project.id,
|
|
36
|
-
inventoryManager.member.memberOf.typeOf, inventoryManager.member.memberOf.id, i, updateCount
|
|
37
|
-
);
|
|
38
|
-
} else {
|
|
39
|
-
updateCount += 1;
|
|
40
|
-
const newHasRole: chevre.factory.iam.IMemberRole[] = [
|
|
41
|
-
...inventoryManager.member.hasRole.map(({ roleName }) => {
|
|
42
|
-
return { typeOf: chevre.factory.iam.RoleType.OrganizationRole, roleName };
|
|
43
|
-
}),
|
|
44
|
-
{ typeOf: chevre.factory.iam.RoleType.OrganizationRole, roleName: NEW_ROLE_NAME }
|
|
45
|
-
].sort((a, b) => (a.roleName > b.roleName) ? 1 : -1);
|
|
46
|
-
console.log(
|
|
47
|
-
'updating...',
|
|
48
|
-
inventoryManager.project.id,
|
|
49
|
-
inventoryManager.member.memberOf.typeOf, inventoryManager.member.memberOf.id, i, updateCount, newHasRole
|
|
50
|
-
);
|
|
51
|
-
await memberRepo.updateByMemberId({
|
|
52
|
-
project: { id: inventoryManager.project.id },
|
|
53
|
-
member: {
|
|
54
|
-
id: inventoryManager.member.id,
|
|
55
|
-
memberOf: inventoryManager.member.memberOf,
|
|
56
|
-
hasRole: newHasRole
|
|
57
|
-
},
|
|
58
|
-
$unset: {}
|
|
59
|
-
});
|
|
60
|
-
console.log(
|
|
61
|
-
'updated.',
|
|
62
|
-
inventoryManager.project.id,
|
|
63
|
-
inventoryManager.member.memberOf.typeOf, inventoryManager.member.memberOf.id, i, updateCount
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
console.log(i, 'members checked');
|
|
69
|
-
console.log(updateCount, 'members updated');
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
main()
|
|
73
|
-
.then()
|
|
74
|
-
.catch(console.error);
|