@chevre/domain 22.13.0-alpha.5 → 22.13.0-alpha.7

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.
@@ -13,7 +13,7 @@ async function main() {
13
13
 
14
14
  const cursor = eventRepo.getCursor(
15
15
  {
16
- _id: { $eq: 'blwz44aee' },
16
+ // _id: { $eq: 'blwz44d0k' },
17
17
  'project.id': { $eq: project.id }
18
18
  },
19
19
  {
@@ -61,16 +61,16 @@ async function main() {
61
61
  console.log(
62
62
  'updating... oldEventId:',
63
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
- // });
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
74
  updateCount += 1;
75
75
  console.log(
76
76
  'updated.',
@@ -0,0 +1,192 @@
1
+ // tslint:disable:no-console no-magic-numbers
2
+ import * as moment from 'moment-timezone';
3
+ import * as mongoose from 'mongoose';
4
+
5
+ import { chevre } from '../../../../lib/index';
6
+
7
+ const project = { id: String(process.env.PROJECT_ID) };
8
+ const ADDITIONAL_PROPERTY_NAME = 'sampleCreateId';
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 eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
15
+
16
+ const today = moment()
17
+ .tz('Asia/Tokyo')
18
+ .format('YYYY-MM-DD');
19
+ const identifier = `fromSamples:${moment()
20
+ .format('YYYY-MM-DD HH:mm')}`;
21
+ const settingEvent: chevre.factory.event.screeningEvent.IEvent = {
22
+ identifier,
23
+ additionalProperty: [
24
+ { name: ADDITIONAL_PROPERTY_NAME, value: identifier }
25
+ ],
26
+ id: 'bmcvkft5g',
27
+ project: {
28
+ id: project.id,
29
+ typeOf: chevre.factory.organizationType.Project
30
+ },
31
+ organizer: {
32
+ id: '59d20831e53ebc2b4e774466'
33
+ },
34
+ typeOf: chevre.factory.eventType.ScreeningEvent,
35
+ name: {
36
+ en: 'pet IMAX2D',
37
+ ja: 'ペット IMAX2D'
38
+ },
39
+ doorTime: moment(`${today}T13:00:00Z`)
40
+ .toDate(),
41
+ startDate: moment(`${today}T13:00:00Z`)
42
+ .toDate(),
43
+ endDate: moment(`${today}T14:00:00Z`)
44
+ .toDate(),
45
+ eventStatus: chevre.factory.eventStatusType.EventScheduled,
46
+ location: {
47
+ typeOf: chevre.factory.placeType.ScreeningRoom,
48
+ branchCode: '70',
49
+ name: {
50
+ ja: 'シネマ7',
51
+ en: 'CINEMA7'
52
+ },
53
+ address: {
54
+ ja: '',
55
+ en: ''
56
+ }
57
+ },
58
+ superEvent: {
59
+ typeOf: chevre.factory.eventType.ScreeningEventSeries,
60
+ id: 'al9s38bj6',
61
+ videoFormat: [
62
+ {
63
+ typeOf: '2D',
64
+ name: '2D'
65
+ },
66
+ {
67
+ typeOf: 'IMAX',
68
+ name: 'IMAX'
69
+ }
70
+ ],
71
+ soundFormat: [],
72
+ workPerformed: {
73
+ typeOf: chevre.factory.creativeWorkType.Movie,
74
+ identifier: '1622100',
75
+ id: '5bfb841d5a78d7948369980a',
76
+ name: {
77
+ en: 'Pet',
78
+ ja: 'ペット'
79
+ },
80
+ duration: 'PT2H3M'
81
+ },
82
+ location: {
83
+ typeOf: chevre.factory.placeType.MovieTheater,
84
+ id: '5bfb841d5a78d7948369979a',
85
+ branchCode: '118',
86
+ name: {
87
+ ja: 'シネモーション赤坂 ',
88
+ en: 'CineMotion Akasaka'
89
+ }
90
+ },
91
+ kanaName: 'ペット IMAX2D',
92
+ name: {
93
+ en: 'pet IMAX2D',
94
+ ja: 'ペット IMAX2D'
95
+ },
96
+ additionalProperty: [],
97
+ startDate: moment('2022-09-30T15:00:00.000Z')
98
+ .toDate(),
99
+ endDate: moment('2029-07-31T15:00:00.000Z')
100
+ .toDate(),
101
+ headline: {
102
+ ja: 'IMAX2D上映'
103
+ }
104
+ },
105
+ offers: {
106
+ typeOf: chevre.factory.offerType.Offer,
107
+ eligibleQuantity: {
108
+ typeOf: 'QuantitativeValue',
109
+ unitCode: chevre.factory.unitCode.C62,
110
+ maxValue: 6
111
+ },
112
+ itemOffered: {
113
+ id: '655dc6b02cbb99d946cb6081',
114
+ name: {
115
+ ja: '通常興行カタログ(サブカタログ版)'
116
+ },
117
+ serviceOutput: {
118
+ typeOf: chevre.factory.reservationType.EventReservation,
119
+ reservedTicket: {
120
+ typeOf: 'Ticket',
121
+ ticketedSeat: {
122
+ typeOf: chevre.factory.placeType.Seat
123
+ }
124
+ }
125
+ },
126
+ typeOf: chevre.factory.product.ProductType.EventService,
127
+ availableChannel: {
128
+ typeOf: 'ServiceChannel',
129
+ serviceLocation: {
130
+ typeOf: chevre.factory.placeType.ScreeningRoom,
131
+ branchCode: '70',
132
+ name: {
133
+ ja: 'シネマ7',
134
+ en: 'CINEMA7'
135
+ },
136
+ containedInPlace: {
137
+ typeOf: chevre.factory.placeType.MovieTheater,
138
+ id: '5bfb841d5a78d7948369979a',
139
+ branchCode: '118',
140
+ name: {
141
+ ja: 'シネモーション赤坂 ',
142
+ en: 'CineMotion Akasaka'
143
+ }
144
+ }
145
+ }
146
+ }
147
+ },
148
+ seller: {
149
+ typeOf: chevre.factory.organizationType.Corporation,
150
+ id: '59d20831e53ebc2b4e774466',
151
+ name: {
152
+ ja: 'シネモーション赤坂',
153
+ en: 'CineMotion Akasaka'
154
+ },
155
+ makesOffer: [
156
+ ]
157
+ }
158
+ }
159
+ };
160
+
161
+ const createResult = await eventRepo.upsertManyScreeningEventByIdentifier(
162
+ [
163
+ {
164
+ $set: settingEvent,
165
+ $unset: {}
166
+ }
167
+ ],
168
+ { update: false }
169
+ );
170
+ // tslint:disable-next-line:no-null-keyword
171
+ console.dir(createResult, { depth: null });
172
+
173
+ const updateResult = await eventRepo.upsertManyScreeningEventByIdentifier(
174
+ [
175
+ {
176
+ $set: {
177
+ ...settingEvent,
178
+ eventStatus: chevre.factory.eventStatusType.EventCancelled
179
+ },
180
+ $unset: {}
181
+ }
182
+ ],
183
+ { update: true }
184
+ );
185
+ // tslint:disable-next-line:no-null-keyword
186
+ console.dir(updateResult, { depth: null });
187
+
188
+ }
189
+
190
+ main()
191
+ .then()
192
+ .catch(console.error);
@@ -56,7 +56,9 @@ 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
+ export type ICreatingEvent4ttts = Pick<factory.event.IAttributes<factory.eventType.ScreeningEvent>, 'additionalProperty' | 'doorTime' | 'endDate' | 'eventStatus' | 'location' | 'name' | 'offers' | 'organizer' | 'project' | 'startDate' | 'superEvent' | 'typeOf' | 'identifier'> & {
60
+ identifier: string;
61
+ };
60
62
  /**
61
63
  * イベントリポジトリ
62
64
  */
@@ -105,6 +107,24 @@ export declare class EventRepo {
105
107
  id: string;
106
108
  }[];
107
109
  } | void>;
110
+ /**
111
+ * イベントコードをキーにして冪等置換
112
+ */
113
+ upsertManyScreeningEventByIdentifier(params: {
114
+ $set: factory.event.screeningEvent.IEvent;
115
+ $unset: IUnset<factory.eventType.ScreeningEvent>;
116
+ }[], options: {
117
+ /**
118
+ * falseの場合setOnInsertのみ
119
+ * trueの場合setのみ
120
+ */
121
+ update: boolean;
122
+ }): Promise<{
123
+ bulkWriteResult: BulkWriteResult;
124
+ modifiedEvents: {
125
+ id: string;
126
+ }[];
127
+ } | void>;
108
128
  /**
109
129
  * イベント部分更新
110
130
  */
@@ -142,7 +162,6 @@ export declare class EventRepo {
142
162
  * tttsイベントを識別子によって冪等作成する
143
163
  */
144
164
  saveEventByIdentifier4ttts(params: {
145
- oldEventId: string;
146
165
  attributes: ICreatingEvent4ttts;
147
166
  }): Promise<{
148
167
  id: string;
@@ -482,6 +482,71 @@ class EventRepo {
482
482
  }
483
483
  });
484
484
  }
485
+ /**
486
+ * イベントコードをキーにして冪等置換
487
+ */
488
+ upsertManyScreeningEventByIdentifier(params, options) {
489
+ return __awaiter(this, void 0, void 0, function* () {
490
+ const { update } = options;
491
+ const uniqid = yield Promise.resolve().then(() => require('uniqid'));
492
+ const bulkWriteOps = [];
493
+ const queryFilters = [];
494
+ if (Array.isArray(params)) {
495
+ params.forEach(({ $set, $unset }) => {
496
+ const { project, identifier } = $set;
497
+ if (typeof identifier !== 'string' || identifier.length === 0) {
498
+ throw new factory.errors.ArgumentNull('identifier');
499
+ }
500
+ // リソースのユニークネスを保証するfilter
501
+ const filter = {
502
+ 'project.id': { $eq: project.id },
503
+ identifier: { $exists: true, $eq: identifier }
504
+ };
505
+ queryFilters.push({
506
+ 'project.id': { $eq: project.id },
507
+ identifier: { $exists: true, $eq: identifier }
508
+ });
509
+ if (update === true) {
510
+ const { maximumPhysicalAttendeeCapacity, additionalProperty, eventStatus, location, name, superEvent, offers, doorTime, endDate, startDate } = $set;
511
+ const setFields = {
512
+ maximumPhysicalAttendeeCapacity, additionalProperty,
513
+ eventStatus, location, name, superEvent, offers,
514
+ doorTime, endDate, startDate
515
+ };
516
+ const updateOne = {
517
+ filter,
518
+ update: Object.assign({ $set: setFields }, ($unset !== undefined) ? { $unset } : undefined),
519
+ upsert: false
520
+ };
521
+ bulkWriteOps.push({ updateOne });
522
+ }
523
+ else {
524
+ const { id, coaInfo, description, maximumAttendeeCapacity, remainingAttendeeCapacity, checkInCount, attendeeCount, aggregateReservation } = $set, setOnInsertFields = __rest($set, ["id", "coaInfo", "description", "maximumAttendeeCapacity", "remainingAttendeeCapacity", "checkInCount", "attendeeCount", "aggregateReservation"]);
525
+ const setOnInsert = Object.assign(Object.assign({}, setOnInsertFields), { identifier, _id: uniqid() });
526
+ const updateOne = {
527
+ filter,
528
+ update: {
529
+ $setOnInsert: setOnInsert
530
+ },
531
+ upsert: true
532
+ };
533
+ bulkWriteOps.push({ updateOne });
534
+ }
535
+ });
536
+ }
537
+ if (bulkWriteOps.length > 0) {
538
+ const bulkWriteResult = yield this.eventModel.bulkWrite(bulkWriteOps, { ordered: false });
539
+ // modifiedの場合upsertedIdsに含まれないので、idを検索する
540
+ const modifiedEvents = yield this.eventModel.find({ $or: queryFilters }, {
541
+ _id: 0,
542
+ id: { $toString: '$_id' }
543
+ })
544
+ .lean()
545
+ .exec();
546
+ return { bulkWriteResult, modifiedEvents };
547
+ }
548
+ });
549
+ }
485
550
  /**
486
551
  * イベント部分更新
487
552
  */
@@ -594,9 +659,12 @@ class EventRepo {
594
659
  */
595
660
  saveEventByIdentifier4ttts(params) {
596
661
  return __awaiter(this, void 0, void 0, function* () {
597
- const { oldEventId } = params;
598
- const _a = params.attributes, { project, typeOf } = _a, updateFields = __rest(_a, ["project", "typeOf"]);
599
- const identifier = oldEventId;
662
+ // const { oldEventId } = params;
663
+ const _a = params.attributes, { project, typeOf, eventStatus, identifier, organizer } = _a, updateFields = __rest(_a, ["project", "typeOf", "eventStatus", "identifier", "organizer"]);
664
+ // const identifier = oldEventId;
665
+ if (typeof identifier !== 'string' || identifier.length === 0) {
666
+ throw new factory.errors.ArgumentNull('identifier');
667
+ }
600
668
  const uniqid = yield Promise.resolve().then(() => require('uniqid'));
601
669
  const id = uniqid();
602
670
  const doc = yield this.eventModel.findOneAndUpdate({
@@ -605,7 +673,7 @@ class EventRepo {
605
673
  // 追加特性をキーに更新
606
674
  additionalProperty: {
607
675
  $exists: true,
608
- $all: [{ name: 'oldEventId', value: oldEventId }]
676
+ $all: [{ name: 'oldEventId', value: identifier }]
609
677
  }
610
678
  },
611
679
  // upsertの場合、createがありうるので属性を除外しない
@@ -614,6 +682,8 @@ class EventRepo {
614
682
  _id: id,
615
683
  typeOf,
616
684
  project,
685
+ eventStatus,
686
+ organizer,
617
687
  identifier // イベントコードを必ず追加(2025-09-03~)
618
688
  // ...(typeof identifier === 'string' && identifier !== '') ? { identifier } : undefined
619
689
  },
@@ -5,14 +5,11 @@ 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, ICreatingEvent4ttts } from '../repo/event';
8
+ import type { EventRepo } 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';
12
- import type { ProjectRepo } from '../repo/project';
13
12
  import type { SellerRepo } from '../repo/seller';
14
- import type { SettingRepo } from '../repo/setting';
15
- import type { TaskRepo } from '../repo/task';
16
13
  import * as factory from '../factory';
17
14
  interface IImportFromCOAParams {
18
15
  project: {
@@ -38,7 +35,7 @@ interface IImportFromCOAParams {
38
35
  /**
39
36
  * イベントをインポートする
40
37
  */
41
- export declare function importFromCOA(params: IImportFromCOAParams): (repos: {
38
+ declare function importFromCOA(params: IImportFromCOAParams): (repos: {
42
39
  action: ActionRepo;
43
40
  categoryCode: CategoryCodeRepo;
44
41
  creativeWork: CreativeWorkRepo;
@@ -49,13 +46,10 @@ export declare function importFromCOA(params: IImportFromCOAParams): (repos: {
49
46
  seller: SellerRepo;
50
47
  masterService: COA.service.Master;
51
48
  }) => Promise<void>;
52
- export declare function minimizeSuperEvent(params: {
53
- superEvent: factory.event.screeningEventSeries.IEvent;
54
- }): factory.event.screeningEvent.ISuperEvent;
55
49
  /**
56
50
  * COA情報からイベントIDを作成する
57
51
  */
58
- export declare function createScreeningEventIdFromCOA(params: {
52
+ declare function createScreeningEventIdFromCOA(params: {
59
53
  theaterCode: string;
60
54
  titleCode: string;
61
55
  titleBranchNum: string;
@@ -63,27 +57,4 @@ export declare function createScreeningEventIdFromCOA(params: {
63
57
  screenCode: string;
64
58
  timeBegin: string;
65
59
  }): string;
66
- /**
67
- * イベントコード指定でtttsイベントを冪等更新する
68
- */
69
- export declare function updateEvent4ttts(params: {
70
- /**
71
- * 旧イベントID
72
- */
73
- oldEventId: string;
74
- /**
75
- * イベント属性
76
- */
77
- attributes: ICreatingEvent4ttts;
78
- project: {
79
- id: string;
80
- };
81
- }): (repos: {
82
- action: ActionRepo;
83
- event: EventRepo;
84
- eventSeries: EventSeriesRepo;
85
- project: ProjectRepo;
86
- setting: SettingRepo;
87
- task: TaskRepo;
88
- }) => Promise<void>;
89
- export { ICreatingEvent4ttts };
60
+ export { importFromCOA, createScreeningEventIdFromCOA };
@@ -10,17 +10,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.importFromCOA = importFromCOA;
13
- exports.minimizeSuperEvent = minimizeSuperEvent;
14
13
  exports.createScreeningEventIdFromCOA = createScreeningEventIdFromCOA;
15
- exports.updateEvent4ttts = updateEvent4ttts;
16
14
  const createDebug = require("debug");
17
15
  // @ts-ignore
18
16
  const difference = require("lodash.difference");
19
17
  // import { google } from 'googleapis';
20
18
  const moment = require("moment-timezone");
21
19
  const factory = require("../factory");
22
- // import { Settings } from '../settings';
23
- const onEventChanged_1 = require("./offer/onEventChanged");
24
20
  const debug = createDebug('chevre-domain:service:event');
25
21
  /**
26
22
  * イベントをインポートする
@@ -858,54 +854,3 @@ function createScreeningRoomFromCOA(project, seller, screenFromCOA) {
858
854
  parentOrganization: { id: seller.id, typeOf: factory.organizationType.Corporation }
859
855
  };
860
856
  }
861
- /**
862
- * イベントコード指定でtttsイベントを冪等更新する
863
- */
864
- function updateEvent4ttts(params) {
865
- return (repos) => __awaiter(this, void 0, void 0, function* () {
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,
876
- // replacee: reservation,
877
- // replacer: params.attributes, // $unsetもありうるのでいったん保留
878
- targetCollection: {
879
- id: params.oldEventId,
880
- typeOf: factory.eventType.ScreeningEvent
881
- }
882
- };
883
- const action = yield repos.action.start(actionAttributes);
884
- let savedEvent;
885
- try {
886
- savedEvent = yield repos.event.saveEventByIdentifier4ttts({
887
- oldEventId: params.oldEventId,
888
- attributes: params.attributes
889
- });
890
- }
891
- catch (error) {
892
- try {
893
- yield repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error });
894
- }
895
- catch (__) {
896
- // 失敗したら仕方ない
897
- }
898
- throw error;
899
- }
900
- yield repos.action.completeWithVoid({ typeOf: action.typeOf, id: action.id, result: { id: savedEvent.id } });
901
- yield (0, onEventChanged_1.onEventChanged)({
902
- id: [savedEvent.id],
903
- project: { id: params.project.id },
904
- typeOf: factory.eventType.ScreeningEvent,
905
- isNew: false,
906
- useInform: true
907
- })(repos
908
- // スケジュールによるイベント作成ではendDateに変更がないのでpendingReservationsへの同期はひとまず必要なし
909
- );
910
- });
911
- }
@@ -0,0 +1,15 @@
1
+ import type { ICreatingEvent4ttts } from '../../../../repo/event';
2
+ import type { EventSeriesRepo } from '../../../../repo/eventSeries';
3
+ import type { MemberRepo } from '../../../../repo/member';
4
+ import type { MovieTheaterRepo } from '../../../../repo/place/movieTheater';
5
+ import type { ScreeningRoomRepo } from '../../../../repo/place/screeningRoom';
6
+ import type { ProductRepo } from '../../../../repo/product';
7
+ import * as factory from '../../../../factory';
8
+ declare function schedule2events(schedule: factory.schedule.IEventWithSchedule, createDate: Date): (repos: {
9
+ eventSeries: EventSeriesRepo;
10
+ member: MemberRepo;
11
+ movieTheater: MovieTheaterRepo;
12
+ screeningRoom: ScreeningRoomRepo;
13
+ product: ProductRepo;
14
+ }) => Promise<ICreatingEvent4ttts[]>;
15
+ export { schedule2events };