@chevre/domain 22.13.0-alpha.1 → 22.13.0-alpha.10

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.
@@ -9,10 +9,7 @@ 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,28 +57,4 @@ export declare function createScreeningEventIdFromCOA(params: {
63
57
  screenCode: string;
64
58
  timeBegin: string;
65
59
  }): string;
66
- export declare function updateEvent4ttts(params: {
67
- /**
68
- * 旧イベントID
69
- */
70
- oldEventId: string;
71
- /**
72
- * イベント属性
73
- */
74
- attributes: factory.event.IAttributes<factory.eventType.ScreeningEvent>;
75
- project: {
76
- id: string;
77
- };
78
- /**
79
- * 更新者
80
- */
81
- agent: factory.action.IParticipant;
82
- }): (repos: {
83
- action: ActionRepo;
84
- event: EventRepo;
85
- eventSeries: EventSeriesRepo;
86
- project: ProjectRepo;
87
- setting: SettingRepo;
88
- task: TaskRepo;
89
- }) => Promise<void>;
90
- export {};
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,46 +854,3 @@ function createScreeningRoomFromCOA(project, seller, screenFromCOA) {
858
854
  parentOrganization: { id: seller.id, typeOf: factory.organizationType.Corporation }
859
855
  };
860
856
  }
861
- function updateEvent4ttts(params) {
862
- 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
- } }, {
867
- // replacee: reservation,
868
- // replacer: params.attributes, // $unsetもありうるのでいったん保留
869
- targetCollection: {
870
- id: params.oldEventId,
871
- typeOf: factory.eventType.ScreeningEvent
872
- }
873
- });
874
- const action = yield repos.action.start(actionAttributes);
875
- let savedEvent;
876
- try {
877
- savedEvent = yield repos.event.save4ttts({
878
- oldEventId: params.oldEventId,
879
- attributes: params.attributes
880
- });
881
- }
882
- catch (error) {
883
- try {
884
- yield repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error });
885
- }
886
- catch (__) {
887
- // 失敗したら仕方ない
888
- }
889
- throw error;
890
- }
891
- // アクション完了
892
- yield repos.action.completeWithVoid({ typeOf: action.typeOf, id: action.id, result: { id: savedEvent.id } });
893
- yield (0, onEventChanged_1.onEventChanged)({
894
- id: [savedEvent.id],
895
- project: { id: params.project.id },
896
- typeOf: factory.eventType.ScreeningEvent,
897
- isNew: false,
898
- useInform: true
899
- })(repos
900
- // スケジュールによるイベント作成ではendDateに変更がないのでpendingReservationsへの同期はひとまず必要なし
901
- );
902
- });
903
- }
@@ -0,0 +1,22 @@
1
+ import type { ICreatingEvent4ttts } from '../../../../repo/event';
2
+ import type { ICustomerMember } from '../../../../repo/member';
3
+ import * as factory from '../../../../factory';
4
+ declare function tour2creatingEvent(tour: ITourBySchedule, movieTheater: Pick<factory.place.movieTheater.IPlace, 'id' | 'branchCode' | 'parentOrganization'>, screeningRoom: Omit<factory.place.screeningRoom.IPlace, 'containsPlace' | 'parentOrganization'>, existingApplicationMembers: {
5
+ member: ICustomerMember;
6
+ }[], maxValue: number, eventService: Pick<factory.product.IProduct, 'id' | 'name'> & {
7
+ id: string;
8
+ }, screeningEventSeries: Pick<factory.event.screeningEventSeries.IEvent, 'location' | 'additionalProperty' | 'description' | 'endDate' | 'headline' | 'id' | 'kanaName' | 'name' | 'soundFormat' | 'startDate' | 'typeOf' | 'videoFormat' | 'workPerformed'>, project: {
9
+ id: string;
10
+ }): ICreatingEvent4ttts;
11
+ interface ITourBySchedule {
12
+ day: string;
13
+ start_time: string;
14
+ end_time?: never;
15
+ door_time: Date;
16
+ start_date: Date;
17
+ end_date: Date;
18
+ duration?: never;
19
+ tour_number: string;
20
+ }
21
+ declare function schedule2tours(settings: factory.schedule.IEventWithSchedule, createDate: Date): ITourBySchedule[];
22
+ export { tour2creatingEvent, schedule2tours };
@@ -0,0 +1,274 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tour2creatingEvent = tour2creatingEvent;
4
+ exports.schedule2tours = schedule2tours;
5
+ const moment = require("moment-timezone");
6
+ const factory = require("../../../../factory");
7
+ // tslint:disable-next-line:max-func-body-length
8
+ // function schedule2createEventParams(
9
+ // schedule: factory.schedule.IEventWithSchedule,
10
+ // createDate: Date
11
+ // ): factory.event.screeningEvent.ICreateParams[] {
12
+ // const eventServiceId = schedule.offers?.itemOffered?.id;
13
+ // const makesOffer = schedule.offers?.seller?.makesOffer;
14
+ // const applicationIds: string[] = (Array.isArray(makesOffer))
15
+ // ? makesOffer.map(({ availableAtOrFrom }) => availableAtOrFrom.id)
16
+ // : [];
17
+ // const eventSeriesId = schedule.superEvent?.id;
18
+ // if (typeof eventServiceId !== 'string' || eventServiceId === '') {
19
+ // throw new factory.errors.NotFound('schedule.offers.itemOffered.id');
20
+ // }
21
+ // if (typeof eventSeriesId !== 'string' || eventSeriesId === '') {
22
+ // throw new factory.errors.NotFound('schedule.superEvent.id');
23
+ // }
24
+ // // 引数情報取得
25
+ // if (schedule.eventSchedule === undefined) {
26
+ // throw new factory.errors.NotFound('eventSchedule');
27
+ // }
28
+ // const targetInfo = getTargetInfoByEventWithSchedule(schedule, createDate);
29
+ // debug(targetInfo.length, 'targetInfos ->', targetInfo);
30
+ // const createParams: factory.event.screeningEvent.ICreateParams[] = [];
31
+ // for (const performanceInfo of targetInfo) {
32
+ // const oldEventId = [
33
+ // // tslint:disable-next-line:no-magic-numbers
34
+ // performanceInfo.day.slice(-6),
35
+ // workPerformedIdentifier,
36
+ // movieTheater.branchCode,
37
+ // screeningRoom.branchCode,
38
+ // performanceInfo.start_time
39
+ // ].join('');
40
+ // const maxValue = movieTheater.offers?.eligibleQuantity?.maxValue;
41
+ // const availabilityEnds: Date = moment(performanceInfo.end_date)
42
+ // .tz('Asia/Tokyo')
43
+ // .endOf('date')
44
+ // .toDate();
45
+ // const availabilityStarts: Date = moment(performanceInfo.start_date)
46
+ // .tz('Asia/Tokyo')
47
+ // .startOf('date')
48
+ // // tslint:disable-next-line:no-magic-numbers
49
+ // .add(-3, 'months')
50
+ // .toDate();
51
+ // const validThrough: Date = moment(performanceInfo.end_date)
52
+ // .tz('Asia/Tokyo')
53
+ // .endOf('date')
54
+ // .toDate();
55
+ // const validFrom: Date = moment(performanceInfo.start_date)
56
+ // .tz('Asia/Tokyo')
57
+ // .startOf('date')
58
+ // // tslint:disable-next-line:no-magic-numbers
59
+ // .add(-3, 'months')
60
+ // .toDate();
61
+ // // イベント作成
62
+ // createParams.push({
63
+ // eventStatus: factory.eventStatusType.EventScheduled,
64
+ // doorTime: performanceInfo.door_time,
65
+ // startDate: performanceInfo.start_date,
66
+ // endDate: performanceInfo.end_date,
67
+ // offers: {
68
+ // eligibleQuantity: {
69
+ // ...(typeof maxValue === 'number') ? { maxValue } : undefined // ひとまず全座席予約可能なように
70
+ // },
71
+ // itemOffered: {
72
+ // // 興行ID追加(2022-09-01~)
73
+ // id: eventServiceId,
74
+ // serviceOutput: {
75
+ // typeOf: factory.reservationType.EventReservation,
76
+ // reservedTicket: {
77
+ // typeOf: 'Ticket',
78
+ // ticketedSeat: { typeOf: factory.placeType.Seat }
79
+ // }
80
+ // },
81
+ // },
82
+ // seller: {
83
+ // // event.offersにseller.makesOfferを追加(2022-11-18~)
84
+ // makesOffer: applicationIds.map((applicationId) => {
85
+ // return {
86
+ // typeOf: factory.offerType.Offer,
87
+ // availableAtOrFrom: { id: applicationId }, // support no-array(2024-10-13~),
88
+ // availabilityEnds,
89
+ // availabilityStarts,
90
+ // validFrom,
91
+ // validThrough
92
+ // };
93
+ // })
94
+ // }
95
+ // },
96
+ // // 旧フォーマットIDを追加特性に追加(2022-09-08~)
97
+ // additionalProperty: [
98
+ // { name: 'tourNumber', value: String(performanceInfo.tour_number) },
99
+ // { name: 'oldEventId', value: oldEventId }
100
+ // ],
101
+ // identifier: oldEventId
102
+ // });
103
+ // }
104
+ // return createParams;
105
+ // }
106
+ // tslint:disable-next-line:max-func-body-length
107
+ function tour2creatingEvent(tour, movieTheater, screeningRoom, existingApplicationMembers, maxValue, eventService, screeningEventSeries, project) {
108
+ var _a;
109
+ const workPerformedIdentifier = screeningEventSeries.workPerformed.identifier;
110
+ const oldEventId = [
111
+ // tslint:disable-next-line:no-magic-numbers
112
+ tour.day.slice(-6),
113
+ workPerformedIdentifier,
114
+ movieTheater.branchCode,
115
+ screeningRoom.branchCode,
116
+ tour.start_time
117
+ ].join('');
118
+ const availabilityEnds = moment(tour.end_date)
119
+ .tz('Asia/Tokyo')
120
+ .endOf('date')
121
+ .toDate();
122
+ const availabilityStarts = moment(tour.start_date)
123
+ .tz('Asia/Tokyo')
124
+ .startOf('date')
125
+ // tslint:disable-next-line:no-magic-numbers
126
+ .add(-3, 'months')
127
+ .toDate();
128
+ const validThrough = moment(tour.end_date)
129
+ .tz('Asia/Tokyo')
130
+ .endOf('date')
131
+ .toDate();
132
+ const validFrom = moment(tour.start_date)
133
+ .tz('Asia/Tokyo')
134
+ .startOf('date')
135
+ // tslint:disable-next-line:no-magic-numbers
136
+ .add(-3, 'months')
137
+ .toDate();
138
+ const seller = movieTheater.parentOrganization;
139
+ const offersSeller = {
140
+ typeOf: factory.organizationType.Corporation,
141
+ id: seller.id,
142
+ // event.offersにseller.makesOfferを追加(2022-11-18~)
143
+ makesOffer: existingApplicationMembers.map((a) => {
144
+ return {
145
+ typeOf: factory.offerType.Offer,
146
+ availableAtOrFrom: { id: a.member.id }, // support no-array(2024-10-13~),
147
+ availabilityEnds,
148
+ availabilityStarts,
149
+ validFrom,
150
+ validThrough
151
+ };
152
+ })
153
+ };
154
+ const offers = {
155
+ typeOf: factory.offerType.Offer,
156
+ eligibleQuantity: {
157
+ typeOf: 'QuantitativeValue',
158
+ unitCode: factory.unitCode.C62,
159
+ maxValue
160
+ },
161
+ itemOffered: Object.assign({
162
+ // 興行ID追加(2022-09-01~)
163
+ id: eventService.id, serviceOutput: {
164
+ typeOf: factory.reservationType.EventReservation,
165
+ reservedTicket: {
166
+ typeOf: 'Ticket',
167
+ ticketedSeat: { typeOf: factory.placeType.Seat }
168
+ }
169
+ }, typeOf: factory.product.ProductType.EventService, availableChannel: {
170
+ typeOf: 'ServiceChannel',
171
+ serviceLocation: {
172
+ typeOf: screeningRoom.typeOf,
173
+ branchCode: screeningRoom.branchCode,
174
+ name: screeningRoom.name,
175
+ containedInPlace: Object.assign({ typeOf: screeningEventSeries.location.typeOf, id: screeningEventSeries.location.id, branchCode: screeningEventSeries.location.branchCode }, (screeningEventSeries.location.name !== undefined)
176
+ ? { name: screeningEventSeries.location.name }
177
+ : undefined)
178
+ }
179
+ } }, { name: { ja: (typeof eventService.name === 'string') ? eventService.name : String((_a = eventService.name) === null || _a === void 0 ? void 0 : _a.ja) } }),
180
+ seller: offersSeller
181
+ };
182
+ const screeningEventSuperEvent = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ typeOf: screeningEventSeries.typeOf, id: screeningEventSeries.id, videoFormat: screeningEventSeries.videoFormat, soundFormat: screeningEventSeries.soundFormat, workPerformed: screeningEventSeries.workPerformed, location: screeningEventSeries.location, kanaName: screeningEventSeries.kanaName, name: screeningEventSeries.name }, (Array.isArray(screeningEventSeries.additionalProperty))
183
+ ? { additionalProperty: screeningEventSeries.additionalProperty }
184
+ : undefined), (screeningEventSeries.startDate !== undefined)
185
+ ? { startDate: screeningEventSeries.startDate }
186
+ : undefined), (screeningEventSeries.endDate !== undefined)
187
+ ? { endDate: screeningEventSeries.endDate }
188
+ : undefined), (screeningEventSeries.description !== undefined)
189
+ ? { description: screeningEventSeries.description }
190
+ : undefined), (screeningEventSeries.headline !== undefined)
191
+ ? { headline: screeningEventSeries.headline }
192
+ : undefined);
193
+ const location = Object.assign({ typeOf: screeningRoom.typeOf, branchCode: screeningRoom.branchCode, name: screeningRoom.name }, (screeningRoom.address !== undefined) ? { address: screeningRoom.address } : undefined);
194
+ return {
195
+ project: { id: project.id, typeOf: factory.organizationType.Project },
196
+ typeOf: factory.eventType.ScreeningEvent,
197
+ eventStatus: factory.eventStatusType.EventScheduled,
198
+ name: screeningEventSeries.name,
199
+ doorTime: tour.door_time,
200
+ startDate: tour.start_date,
201
+ endDate: tour.end_date,
202
+ superEvent: screeningEventSuperEvent,
203
+ location,
204
+ offers,
205
+ // 旧フォーマットIDを追加特性に追加(2022-09-08~)
206
+ additionalProperty: [
207
+ { name: 'tourNumber', value: String(tour.tour_number) },
208
+ { name: 'oldEventId', value: oldEventId }
209
+ ],
210
+ // organizer追加(2023-07-12~)
211
+ organizer: { id: seller.id },
212
+ identifier: oldEventId
213
+ };
214
+ }
215
+ function schedule2tours(settings, createDate) {
216
+ const tours = [];
217
+ const { eventSchedule } = settings;
218
+ // 作成対象時間: 9,10,11など
219
+ // const hours: string[] = ['9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22'];
220
+ // const minutes = ['00', '15', '30', '45'];
221
+ // const tours = ['1', '2', '3', '4'];
222
+ // 1日分作成する
223
+ const now = (createDate instanceof Date)
224
+ ? moment(createDate)
225
+ : moment();
226
+ let startDate = moment.tz(`${now.tz(eventSchedule.scheduleTimezone)
227
+ .format('YYYYMMDD')} ${eventSchedule.startTime}`, 'YYYYMMDD HH:mm:ss', eventSchedule.scheduleTimezone);
228
+ const startDateShouldBeLte = moment.tz(`${now.tz(eventSchedule.scheduleTimezone)
229
+ .format('YYYYMMDD')} ${eventSchedule.endTime}`, 'YYYYMMDD HH:mm:ss', eventSchedule.scheduleTimezone);
230
+ const frequencyInMinutes = moment.duration(eventSchedule.repeatFrequency)
231
+ .asMinutes();
232
+ // tslint:disable-next-line:no-magic-numbers
233
+ const repeatCountInHour = Math.floor(60 / frequencyInMinutes);
234
+ let i = 0;
235
+ while (startDate < startDateShouldBeLte) {
236
+ i += 1;
237
+ if (i > 1) {
238
+ startDate = moment(startDate)
239
+ .add(moment.duration(eventSchedule.repeatFrequency));
240
+ }
241
+ const hour = `0${moment(startDate)
242
+ .format('HH')}`
243
+ // 2桁でない時は'0'詰め
244
+ // tslint:disable-next-line:no-magic-numbers
245
+ .slice(-2);
246
+ let tourIndex = i % repeatCountInHour;
247
+ if (tourIndex === 0) {
248
+ tourIndex = repeatCountInHour;
249
+ }
250
+ const tourNumber = `${hour}${tourIndex}`;
251
+ const endDate = moment(startDate)
252
+ .add(moment.duration(eventSchedule.duration));
253
+ const day = moment(startDate)
254
+ .tz(eventSchedule.scheduleTimezone)
255
+ .format('YYYYMMDD');
256
+ const startTime = moment(startDate)
257
+ .tz(eventSchedule.scheduleTimezone)
258
+ .format('HHmm');
259
+ // const endTime = moment(endDate)
260
+ // .tz(eventSchedule.scheduleTimezone)
261
+ // .format('HHmm');
262
+ tours.push({
263
+ day: day,
264
+ start_time: startTime,
265
+ // end_time: endTime,
266
+ door_time: startDate.toDate(),
267
+ start_date: startDate.toDate(),
268
+ end_date: endDate.toDate(),
269
+ tour_number: tourNumber
270
+ // duration: eventSchedule.duration
271
+ });
272
+ }
273
+ return tours;
274
+ }
@@ -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 };
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.schedule2events = schedule2events;
13
+ const createDebug = require("debug");
14
+ const factory = require("../../../../factory");
15
+ const factory_1 = require("./factory");
16
+ const debug = createDebug('chevre-domain:service:task:createEvent');
17
+ function schedule2relatedResources(schedule) {
18
+ // tslint:disable-next-line:max-func-body-length
19
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
20
+ var _a, _b, _c, _d, _e, _f, _g, _h;
21
+ debug('schedule2relatedResources processing...', JSON.stringify(schedule));
22
+ const eventServiceId = (_b = (_a = schedule.offers) === null || _a === void 0 ? void 0 : _a.itemOffered) === null || _b === void 0 ? void 0 : _b.id;
23
+ const makesOffer = (_d = (_c = schedule.offers) === null || _c === void 0 ? void 0 : _c.seller) === null || _d === void 0 ? void 0 : _d.makesOffer;
24
+ const applicationIds = (Array.isArray(makesOffer))
25
+ ? makesOffer.map(({ availableAtOrFrom }) => availableAtOrFrom.id)
26
+ : [];
27
+ const eventSeriesId = (_e = schedule.superEvent) === null || _e === void 0 ? void 0 : _e.id;
28
+ const maxValue = (_g = (_f = schedule.offers) === null || _f === void 0 ? void 0 : _f.eligibleQuantity) === null || _g === void 0 ? void 0 : _g.maxValue;
29
+ const locationBranchCode = (_h = schedule.location) === null || _h === void 0 ? void 0 : _h.branchCode;
30
+ if (typeof eventServiceId !== 'string' || eventServiceId === '') {
31
+ throw new factory.errors.NotFound('schedule.offers.itemOffered.id required');
32
+ }
33
+ if (typeof eventSeriesId !== 'string' || eventSeriesId === '') {
34
+ throw new factory.errors.NotFound('schedule.superEvent.id required');
35
+ }
36
+ if (typeof maxValue !== 'number') {
37
+ throw new factory.errors.NotFound('schedule.offers.eligibleQuantity.maxValue required');
38
+ }
39
+ if (typeof locationBranchCode !== 'string' || locationBranchCode === '') {
40
+ throw new factory.errors.NotFound('location.branchCode required');
41
+ }
42
+ const project = schedule.project;
43
+ // 施設コンテンツ検索
44
+ const screeningEventSeries = (yield repos.eventSeries.projectEventSeriesFields({
45
+ project: { id: { $eq: project.id } },
46
+ id: { $eq: eventSeriesId }
47
+ }, [
48
+ 'location', 'additionalProperty', 'description', 'endDate', 'headline', 'kanaName', 'name',
49
+ 'soundFormat', 'startDate', 'typeOf', 'videoFormat', 'workPerformed'
50
+ ])).shift();
51
+ if (screeningEventSeries === undefined) {
52
+ throw new factory.errors.NotFound(factory.eventType.ScreeningEventSeries);
53
+ }
54
+ // 劇場検索
55
+ const movieTheater = (yield repos.movieTheater.projectFields({
56
+ limit: 1,
57
+ page: 1,
58
+ project: { id: { $eq: project.id } },
59
+ branchCode: { $eq: screeningEventSeries.location.branchCode }
60
+ }, ['id', 'branchCode', 'parentOrganization'])).shift();
61
+ if (movieTheater === undefined) {
62
+ throw new factory.errors.NotFound(factory.placeType.MovieTheater);
63
+ }
64
+ const screeningRoom = (yield repos.screeningRoom.searchScreeningRooms({
65
+ limit: 1,
66
+ page: 1,
67
+ project: { id: { $eq: project.id } },
68
+ containedInPlace: { id: { $eq: movieTheater.id } },
69
+ branchCode: { $eq: locationBranchCode }
70
+ })).shift();
71
+ if (screeningRoom === undefined) {
72
+ throw new factory.errors.NotFound(factory.placeType.ScreeningRoom, `${factory.placeType.ScreeningRoom} ${locationBranchCode} not found`);
73
+ }
74
+ // 興行検索
75
+ const eventService = (yield repos.product.projectFields({
76
+ limit: 1,
77
+ page: 1,
78
+ project: { id: { $eq: project.id } },
79
+ id: { $eq: eventServiceId }
80
+ // productID: { $eq: eventServiceProductID }
81
+ }, ['name'])).shift();
82
+ if (typeof (eventService === null || eventService === void 0 ? void 0 : eventService.id) !== 'string') {
83
+ throw new Error(`EventService ${eventServiceId} not found`);
84
+ }
85
+ let existingApplicationMembers = [];
86
+ if (applicationIds.length > 0) {
87
+ existingApplicationMembers = yield repos.member.searchCustomerMembers({
88
+ limit: 100,
89
+ page: 1,
90
+ project: { id: project.id },
91
+ member: {
92
+ // typeOf: {
93
+ // $eq: factory.creativeWorkType.WebApplication
94
+ // },
95
+ id: { $in: applicationIds }
96
+ }
97
+ });
98
+ }
99
+ return {
100
+ movieTheater, screeningRoom,
101
+ existingApplicationMembers, maxValue, eventService, screeningEventSeries
102
+ };
103
+ });
104
+ }
105
+ function schedule2events(schedule, createDate) {
106
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
107
+ if (schedule.eventSchedule === undefined) {
108
+ throw new factory.errors.NotFound('schedule.eventSchedule required');
109
+ }
110
+ const { movieTheater, screeningRoom, existingApplicationMembers, maxValue, eventService, screeningEventSeries } = yield schedule2relatedResources(schedule)(repos);
111
+ const project = schedule.project;
112
+ const tours = (0, factory_1.schedule2tours)(schedule, createDate);
113
+ debug(tours.length, 'tours ->', JSON.stringify(tours));
114
+ return tours.map((tour) => (0, factory_1.tour2creatingEvent)(tour, movieTheater, screeningRoom, existingApplicationMembers, maxValue, eventService, screeningEventSeries, project));
115
+ });
116
+ }