@chevre/domain 22.13.0-alpha.4 → 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.
@@ -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);
@@ -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
@@ -75,10 +78,6 @@ export declare function updateEvent4ttts(params: {
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;
@@ -858,19 +858,28 @@ 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 actionAttributes = Object.assign({ project: { typeOf: factory.organizationType.Project, id: params.project.id }, typeOf: factory.actionType.UpdateAction, agent: params.agent, object: {
864
- id: params.oldEventId,
865
- typeOf: factory.eventType.ScreeningEvent
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 {
@@ -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],
@@ -225,8 +225,8 @@ schedule, createDate) {
225
225
  yield (0, event_1.updateEvent4ttts)({
226
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
  );
package/package.json CHANGED
@@ -115,5 +115,5 @@
115
115
  "postversion": "git push origin --tags",
116
116
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
117
117
  },
118
- "version": "22.13.0-alpha.4"
118
+ "version": "22.13.0-alpha.5"
119
119
  }