@chevre/domain 22.13.0-alpha.3 → 22.13.0-alpha.5
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/example/src/chevre/event/migrateEventIdentifier4ttts.ts +96 -0
- package/lib/chevre/repo/event.d.ts +12 -5
- package/lib/chevre/repo/event.js +18 -6
- package/lib/chevre/service/event.d.ts +6 -7
- package/lib/chevre/service/event.js +15 -7
- package/lib/chevre/service/task/createEvent/createEventBySchedule.js +7 -7
- package/package.json +1 -1
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// tslint:disable:no-console no-magic-numbers
|
|
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 eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
|
|
13
|
+
|
|
14
|
+
const cursor = eventRepo.getCursor(
|
|
15
|
+
{
|
|
16
|
+
_id: { $eq: 'blwz44aee' },
|
|
17
|
+
'project.id': { $eq: project.id }
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
_id: 1,
|
|
21
|
+
startDate: 1,
|
|
22
|
+
project: 1,
|
|
23
|
+
identifier: 1,
|
|
24
|
+
additionalProperty: 1,
|
|
25
|
+
typeOf: 1
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
console.log('events found');
|
|
29
|
+
|
|
30
|
+
let i = 0;
|
|
31
|
+
let updateCount = 0;
|
|
32
|
+
await cursor.eachAsync(async (doc) => {
|
|
33
|
+
i += 1;
|
|
34
|
+
const event: Pick<
|
|
35
|
+
chevre.factory.event.screeningEvent.IEvent,
|
|
36
|
+
'id' | 'identifier' | 'startDate' | 'project' | 'additionalProperty' | 'typeOf'
|
|
37
|
+
> = doc.toObject();
|
|
38
|
+
|
|
39
|
+
console.log(
|
|
40
|
+
'alreadyMigrated?', event.project.id, event.id, event.startDate, i);
|
|
41
|
+
const isValidProject = event.project.id.substring(0, 5) === 'ttts-';
|
|
42
|
+
if (!isValidProject) {
|
|
43
|
+
throw new Error(`${event.project.id} ${event.id} invalid project.`);
|
|
44
|
+
}
|
|
45
|
+
const eventIdentifier = event.identifier;
|
|
46
|
+
const oldEventId = event.additionalProperty?.find(({ name }) => name === 'oldEventId')?.value;
|
|
47
|
+
const tourNumber = event.additionalProperty?.find(({ name }) => name === 'tourNumber')?.value;
|
|
48
|
+
if (typeof oldEventId !== 'string' || oldEventId === '') {
|
|
49
|
+
throw new Error(`${event.project.id} ${event.id} oldEventId required: ${oldEventId}`);
|
|
50
|
+
}
|
|
51
|
+
if (typeof tourNumber !== 'string' || tourNumber === '') {
|
|
52
|
+
throw new Error(`${event.project.id} ${event.id} tourNumber required: ${tourNumber}`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const alreadyMigrated = typeof eventIdentifier === 'string' && eventIdentifier === oldEventId;
|
|
56
|
+
|
|
57
|
+
if (alreadyMigrated) {
|
|
58
|
+
console.log(
|
|
59
|
+
'already migrated.', event.project.id, event.id, event.startDate, i);
|
|
60
|
+
} else {
|
|
61
|
+
console.log(
|
|
62
|
+
'updating... oldEventId:',
|
|
63
|
+
oldEventId, event.project.id, event.id, event.startDate, i);
|
|
64
|
+
// await eventRepo.updatePartiallyById({
|
|
65
|
+
// project: { id: event.project.id },
|
|
66
|
+
// id: event.id,
|
|
67
|
+
// attributes: {
|
|
68
|
+
// typeOf: event.typeOf,
|
|
69
|
+
// ...{
|
|
70
|
+
// identifier: oldEventId
|
|
71
|
+
// }
|
|
72
|
+
// }
|
|
73
|
+
// });
|
|
74
|
+
updateCount += 1;
|
|
75
|
+
console.log(
|
|
76
|
+
'updated.',
|
|
77
|
+
event.project.id, event.id, event.startDate, i);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
console.log(i, 'events checked');
|
|
82
|
+
console.log(updateCount, 'events updated');
|
|
83
|
+
|
|
84
|
+
// await eventRepo.projectEventFields<chevre.factory.eventType.ScreeningEvent>(
|
|
85
|
+
// {
|
|
86
|
+
// project: { id: { $eq: project.id } },
|
|
87
|
+
// typeOf: chevre.factory.eventType.ScreeningEvent,
|
|
88
|
+
// // id
|
|
89
|
+
// },
|
|
90
|
+
// ['identifier']
|
|
91
|
+
// );
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
main()
|
|
95
|
+
.then()
|
|
96
|
+
.catch(console.error);
|
|
@@ -56,6 +56,7 @@ type IKeyOfProjection4minimizedEvent<T extends AvailableEventType> = T extends f
|
|
|
56
56
|
type IUnset<T extends AvailableEventType> = {
|
|
57
57
|
[key in keyof factory.event.IEvent<T>]?: 1;
|
|
58
58
|
};
|
|
59
|
+
export type ICreatingEvent4ttts = Pick<factory.event.IAttributes<factory.eventType.ScreeningEvent>, 'additionalProperty' | 'doorTime' | 'endDate' | 'eventStatus' | 'location' | 'name' | 'offers' | 'organizer' | 'project' | 'startDate' | 'superEvent' | 'typeOf'>;
|
|
59
60
|
/**
|
|
60
61
|
* イベントリポジトリ
|
|
61
62
|
*/
|
|
@@ -128,15 +129,21 @@ export declare class EventRepo {
|
|
|
128
129
|
}): Promise<{
|
|
129
130
|
id: string;
|
|
130
131
|
}>;
|
|
131
|
-
|
|
132
|
+
/**
|
|
133
|
+
* sskts専用
|
|
134
|
+
*/
|
|
135
|
+
saveManyEvents(params: {
|
|
132
136
|
id: string;
|
|
133
|
-
attributes: factory.event.IAttributes<
|
|
134
|
-
$unset?: IUnset<
|
|
137
|
+
attributes: factory.event.IAttributes<factory.eventType.ScreeningEvent>;
|
|
138
|
+
$unset?: IUnset<factory.eventType.ScreeningEvent>;
|
|
135
139
|
upsert: boolean;
|
|
136
140
|
}[]): Promise<void>;
|
|
137
|
-
|
|
141
|
+
/**
|
|
142
|
+
* tttsイベントを識別子によって冪等作成する
|
|
143
|
+
*/
|
|
144
|
+
saveEventByIdentifier4ttts(params: {
|
|
138
145
|
oldEventId: string;
|
|
139
|
-
attributes:
|
|
146
|
+
attributes: ICreatingEvent4ttts;
|
|
140
147
|
}): Promise<{
|
|
141
148
|
id: string;
|
|
142
149
|
}>;
|
package/lib/chevre/repo/event.js
CHANGED
|
@@ -553,6 +553,9 @@ class EventRepo {
|
|
|
553
553
|
return { id: savedEventId }; // optimize(2024-07-31~)
|
|
554
554
|
});
|
|
555
555
|
}
|
|
556
|
+
/**
|
|
557
|
+
* sskts専用
|
|
558
|
+
*/
|
|
556
559
|
saveManyEvents(params) {
|
|
557
560
|
return __awaiter(this, void 0, void 0, function* () {
|
|
558
561
|
const bulkWriteOps = [];
|
|
@@ -586,10 +589,14 @@ class EventRepo {
|
|
|
586
589
|
}
|
|
587
590
|
});
|
|
588
591
|
}
|
|
589
|
-
|
|
592
|
+
/**
|
|
593
|
+
* tttsイベントを識別子によって冪等作成する
|
|
594
|
+
*/
|
|
595
|
+
saveEventByIdentifier4ttts(params) {
|
|
590
596
|
return __awaiter(this, void 0, void 0, function* () {
|
|
591
|
-
|
|
592
|
-
const _a = params.attributes, {
|
|
597
|
+
const { oldEventId } = params;
|
|
598
|
+
const _a = params.attributes, { project, typeOf } = _a, updateFields = __rest(_a, ["project", "typeOf"]);
|
|
599
|
+
const identifier = oldEventId;
|
|
593
600
|
const uniqid = yield Promise.resolve().then(() => require('uniqid'));
|
|
594
601
|
const id = uniqid();
|
|
595
602
|
const doc = yield this.eventModel.findOneAndUpdate({
|
|
@@ -598,13 +605,18 @@ class EventRepo {
|
|
|
598
605
|
// 追加特性をキーに更新
|
|
599
606
|
additionalProperty: {
|
|
600
607
|
$exists: true,
|
|
601
|
-
$all: [{ name: 'oldEventId', value:
|
|
608
|
+
$all: [{ name: 'oldEventId', value: oldEventId }]
|
|
602
609
|
}
|
|
603
610
|
},
|
|
604
611
|
// upsertの場合、createがありうるので属性を除外しない
|
|
605
612
|
{
|
|
606
|
-
$setOnInsert:
|
|
607
|
-
|
|
613
|
+
$setOnInsert: {
|
|
614
|
+
_id: id,
|
|
615
|
+
typeOf,
|
|
616
|
+
project,
|
|
617
|
+
identifier // イベントコードを必ず追加(2025-09-03~)
|
|
618
|
+
// ...(typeof identifier === 'string' && identifier !== '') ? { identifier } : undefined
|
|
619
|
+
},
|
|
608
620
|
$set: updateFields
|
|
609
621
|
}, { upsert: true, new: true, projection: { _id: 1 } })
|
|
610
622
|
.lean()
|
|
@@ -5,7 +5,7 @@ import type * as COA from '@motionpicture/coa-service';
|
|
|
5
5
|
import type { ActionRepo } from '../repo/action';
|
|
6
6
|
import type { CategoryCodeRepo } from '../repo/categoryCode';
|
|
7
7
|
import type { CreativeWorkRepo } from '../repo/creativeWork';
|
|
8
|
-
import type { EventRepo } from '../repo/event';
|
|
8
|
+
import type { EventRepo, ICreatingEvent4ttts } from '../repo/event';
|
|
9
9
|
import type { EventSeriesRepo } from '../repo/eventSeries';
|
|
10
10
|
import type { MovieTheaterRepo } from '../repo/place/movieTheater';
|
|
11
11
|
import type { ScreeningRoomRepo } from '../repo/place/screeningRoom';
|
|
@@ -63,6 +63,9 @@ export declare function createScreeningEventIdFromCOA(params: {
|
|
|
63
63
|
screenCode: string;
|
|
64
64
|
timeBegin: string;
|
|
65
65
|
}): string;
|
|
66
|
+
/**
|
|
67
|
+
* イベントコード指定でtttsイベントを冪等更新する
|
|
68
|
+
*/
|
|
66
69
|
export declare function updateEvent4ttts(params: {
|
|
67
70
|
/**
|
|
68
71
|
* 旧イベントID
|
|
@@ -71,14 +74,10 @@ export declare function updateEvent4ttts(params: {
|
|
|
71
74
|
/**
|
|
72
75
|
* イベント属性
|
|
73
76
|
*/
|
|
74
|
-
attributes:
|
|
77
|
+
attributes: ICreatingEvent4ttts;
|
|
75
78
|
project: {
|
|
76
79
|
id: string;
|
|
77
80
|
};
|
|
78
|
-
/**
|
|
79
|
-
* 更新者
|
|
80
|
-
*/
|
|
81
|
-
agent: factory.action.IParticipant;
|
|
82
81
|
}): (repos: {
|
|
83
82
|
action: ActionRepo;
|
|
84
83
|
event: EventRepo;
|
|
@@ -87,4 +86,4 @@ export declare function updateEvent4ttts(params: {
|
|
|
87
86
|
setting: SettingRepo;
|
|
88
87
|
task: TaskRepo;
|
|
89
88
|
}) => Promise<void>;
|
|
90
|
-
export {};
|
|
89
|
+
export { ICreatingEvent4ttts };
|
|
@@ -858,23 +858,32 @@ function createScreeningRoomFromCOA(project, seller, screenFromCOA) {
|
|
|
858
858
|
parentOrganization: { id: seller.id, typeOf: factory.organizationType.Corporation }
|
|
859
859
|
};
|
|
860
860
|
}
|
|
861
|
+
/**
|
|
862
|
+
* イベントコード指定でtttsイベントを冪等更新する
|
|
863
|
+
*/
|
|
861
864
|
function updateEvent4ttts(params) {
|
|
862
865
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
863
|
-
const
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
866
|
+
const updateObject = {
|
|
867
|
+
id: params.oldEventId,
|
|
868
|
+
identifier: params.oldEventId, // support identifier(2025-09-03~)
|
|
869
|
+
typeOf: factory.eventType.ScreeningEvent
|
|
870
|
+
};
|
|
871
|
+
const actionAttributes = {
|
|
872
|
+
project: { typeOf: factory.organizationType.Project, id: params.project.id },
|
|
873
|
+
typeOf: factory.actionType.UpdateAction,
|
|
874
|
+
agent: { typeOf: factory.organizationType.Project, id: params.project.id },
|
|
875
|
+
object: updateObject,
|
|
867
876
|
// replacee: reservation,
|
|
868
877
|
// replacer: params.attributes, // $unsetもありうるのでいったん保留
|
|
869
878
|
targetCollection: {
|
|
870
879
|
id: params.oldEventId,
|
|
871
880
|
typeOf: factory.eventType.ScreeningEvent
|
|
872
881
|
}
|
|
873
|
-
}
|
|
882
|
+
};
|
|
874
883
|
const action = yield repos.action.start(actionAttributes);
|
|
875
884
|
let savedEvent;
|
|
876
885
|
try {
|
|
877
|
-
savedEvent = yield repos.event.
|
|
886
|
+
savedEvent = yield repos.event.saveEventByIdentifier4ttts({
|
|
878
887
|
oldEventId: params.oldEventId,
|
|
879
888
|
attributes: params.attributes
|
|
880
889
|
});
|
|
@@ -888,7 +897,6 @@ function updateEvent4ttts(params) {
|
|
|
888
897
|
}
|
|
889
898
|
throw error;
|
|
890
899
|
}
|
|
891
|
-
// アクション完了
|
|
892
900
|
yield repos.action.completeWithVoid({ typeOf: action.typeOf, id: action.id, result: { id: savedEvent.id } });
|
|
893
901
|
yield (0, onEventChanged_1.onEventChanged)({
|
|
894
902
|
id: [savedEvent.id],
|
|
@@ -118,7 +118,7 @@ schedule, createDate) {
|
|
|
118
118
|
// return Array.isArray(m.member.hasRole) && m.member.hasRole.some((r) => AVAILABLE_ROLE_NAMES.includes(r.roleName));
|
|
119
119
|
// });
|
|
120
120
|
for (const performanceInfo of targetInfo) {
|
|
121
|
-
const
|
|
121
|
+
const oldEventId = [
|
|
122
122
|
// tslint:disable-next-line:no-magic-numbers
|
|
123
123
|
performanceInfo.day.slice(-6),
|
|
124
124
|
workPerformedIdentifier,
|
|
@@ -215,22 +215,22 @@ schedule, createDate) {
|
|
|
215
215
|
// 旧フォーマットIDを追加特性に追加(2022-09-08~)
|
|
216
216
|
additionalProperty: [
|
|
217
217
|
{ name: 'tourNumber', value: String(performanceInfo.tour_number) },
|
|
218
|
-
{ name: 'oldEventId', value:
|
|
218
|
+
{ name: 'oldEventId', value: oldEventId }
|
|
219
219
|
],
|
|
220
220
|
// organizer追加(2023-07-12~)
|
|
221
221
|
organizer: { id: seller.id }
|
|
222
222
|
};
|
|
223
223
|
// domain.serviceで実装(2022-09-10~)
|
|
224
|
-
debug('updating event...',
|
|
224
|
+
debug('updating event...', oldEventId, eventAttributes.startDate);
|
|
225
225
|
yield (0, event_1.updateEvent4ttts)({
|
|
226
|
-
oldEventId
|
|
226
|
+
oldEventId,
|
|
227
227
|
attributes: eventAttributes,
|
|
228
|
-
project: { id: eventAttributes.project.id }
|
|
229
|
-
agent: eventAttributes.project
|
|
228
|
+
project: { id: eventAttributes.project.id }
|
|
229
|
+
// agent: eventAttributes.project
|
|
230
230
|
})(repos
|
|
231
231
|
// settings
|
|
232
232
|
);
|
|
233
|
-
debug('event update(updateEvent4ttts)',
|
|
233
|
+
debug('event update(updateEvent4ttts)', oldEventId, eventAttributes.startDate);
|
|
234
234
|
}
|
|
235
235
|
debug(targetInfo.length, 'events updated');
|
|
236
236
|
});
|
package/package.json
CHANGED