@chevre/domain 23.1.0 → 23.2.0-alpha.1
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/importEventSeriesFromCOAByTitle.ts +83 -0
- package/example/src/chevre/event/importEventsFromCOAByTitle.ts +148 -0
- package/lib/chevre/service/aggregation/event/importFromCOA.js +2 -2
- package/lib/chevre/service/event/factory.d.ts +22 -0
- package/lib/chevre/service/event/factory.js +2 -0
- package/lib/chevre/service/event/processUpdateMovieTheater.d.ts +24 -0
- package/lib/chevre/service/event/processUpdateMovieTheater.js +190 -0
- package/lib/chevre/service/event/saveScreeningEventSeries.d.ts +63 -0
- package/lib/chevre/service/event/saveScreeningEventSeries.js +277 -0
- package/lib/chevre/service/event/saveScreeningEvents.d.ts +46 -0
- package/lib/chevre/service/event/saveScreeningEvents.js +321 -0
- package/lib/chevre/service/event.d.ts +4 -34
- package/lib/chevre/service/event.js +12 -698
- package/lib/chevre/service/eventOld.d.ts +60 -0
- package/lib/chevre/service/eventOld.js +864 -0
- package/lib/chevre/service/task/syncResourcesFromCOA.d.ts +6 -0
- package/lib/chevre/service/task/syncResourcesFromCOA.js +166 -0
- package/lib/chevre/service/taskHandler.js +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,277 @@
|
|
|
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.createScreeningEventSeriesId = createScreeningEventSeriesId;
|
|
13
|
+
exports.saveScreeningEventSeries = saveScreeningEventSeries;
|
|
14
|
+
const createDebug = require("debug");
|
|
15
|
+
const moment = require("moment-timezone");
|
|
16
|
+
// import type { IMovieTheaterIncludingScreeningRooms, MovieTheaterRepo } from '../../repo/place/movieTheater';
|
|
17
|
+
// import type { ScreeningRoomRepo } from '../../repo/place/screeningRoom';
|
|
18
|
+
// import type { SellerRepo } from '../../repo/seller';
|
|
19
|
+
const factory = require("../../factory");
|
|
20
|
+
const debug = createDebug('chevre-domain:service:event');
|
|
21
|
+
/**
|
|
22
|
+
* - 施設コード
|
|
23
|
+
* - タイトルコード(optional)
|
|
24
|
+
* - タイトル枝番(optional)
|
|
25
|
+
*
|
|
26
|
+
* 指定で、施設コンテンツをインポートする
|
|
27
|
+
*
|
|
28
|
+
* - 作品マスタ抽出
|
|
29
|
+
* - 区分マスタ抽出
|
|
30
|
+
* を使用して、施設コンテンツを作成する
|
|
31
|
+
*/
|
|
32
|
+
function saveScreeningEventSeries(params, options) {
|
|
33
|
+
// tslint:disable-next-line:max-func-body-length
|
|
34
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
const { importingIds, locationBranchCode, project } = params;
|
|
36
|
+
const { filterFilmsFromCOA } = options;
|
|
37
|
+
let filteredByTitle = false;
|
|
38
|
+
// COAから作品取得
|
|
39
|
+
let filmsFromCOA = yield repos.masterService.title({ theaterCode: locationBranchCode });
|
|
40
|
+
if (typeof (filterFilmsFromCOA === null || filterFilmsFromCOA === void 0 ? void 0 : filterFilmsFromCOA.titleBranchNum) === 'string'
|
|
41
|
+
&& typeof (filterFilmsFromCOA === null || filterFilmsFromCOA === void 0 ? void 0 : filterFilmsFromCOA.titleBranchNum) === 'string') {
|
|
42
|
+
filmsFromCOA = filmsFromCOA.filter((film) => {
|
|
43
|
+
return film.titleBranchNum === filterFilmsFromCOA.titleBranchNum
|
|
44
|
+
&& film.titleCode === filterFilmsFromCOA.titleCode;
|
|
45
|
+
});
|
|
46
|
+
filteredByTitle = true;
|
|
47
|
+
debug('filmsFromCOA filtered by title.', JSON.stringify(filmsFromCOA));
|
|
48
|
+
}
|
|
49
|
+
debug(filmsFromCOA.length, 'filmsFromCOA processing...');
|
|
50
|
+
// COAから区分マスター抽出
|
|
51
|
+
const eirinKubuns = yield repos.masterService.kubunName({
|
|
52
|
+
theaterCode: locationBranchCode,
|
|
53
|
+
kubunClass: '044'
|
|
54
|
+
});
|
|
55
|
+
const eizouKubuns = yield repos.masterService.kubunName({
|
|
56
|
+
theaterCode: locationBranchCode,
|
|
57
|
+
kubunClass: '042'
|
|
58
|
+
});
|
|
59
|
+
const joueihousikiKubuns = yield repos.masterService.kubunName({
|
|
60
|
+
theaterCode: locationBranchCode,
|
|
61
|
+
kubunClass: '045'
|
|
62
|
+
});
|
|
63
|
+
const jimakufukikaeKubuns = yield repos.masterService.kubunName({
|
|
64
|
+
theaterCode: locationBranchCode,
|
|
65
|
+
kubunClass: '043'
|
|
66
|
+
});
|
|
67
|
+
debug('kubunNames found.');
|
|
68
|
+
const availablePaymentMethodTypes = yield repos.categoryCode.projectCategoryCodeFields({
|
|
69
|
+
project: { id: { $eq: params.project.id } },
|
|
70
|
+
inCodeSet: { identifier: { $eq: factory.categoryCode.CategorySetIdentifier.PaymentMethodType } }
|
|
71
|
+
}, ['additionalProperty', 'codeValue']);
|
|
72
|
+
const screeningEventSerieses = filmsFromCOA.map((filmFromCOA) => {
|
|
73
|
+
return createScreeningEventSeriesFromCOA({
|
|
74
|
+
project: project,
|
|
75
|
+
filmFromCOA: filmFromCOA,
|
|
76
|
+
movieTheater: params.movieTheater,
|
|
77
|
+
eirinKubuns: eirinKubuns,
|
|
78
|
+
eizouKubuns: eizouKubuns,
|
|
79
|
+
joueihousikiKubuns: joueihousikiKubuns,
|
|
80
|
+
jimakufukikaeKubuns: jimakufukikaeKubuns,
|
|
81
|
+
availablePaymentMethodTypes,
|
|
82
|
+
seller: params.seller
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
const COA_IMPORT_SCREENING_EVENT_SERIES_PERIOD_IN_MONTH = (typeof params.saveScreeningEventSeriesPeriodInMonth === 'number')
|
|
86
|
+
? params.saveScreeningEventSeriesPeriodInMonth
|
|
87
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
88
|
+
: 3;
|
|
89
|
+
let savedEventsCount = 0;
|
|
90
|
+
// saveScreeningEventSeries:trueの場合のみ保管(2022-10-10~)
|
|
91
|
+
if (params.saveScreeningEventSeries === true) {
|
|
92
|
+
let saveParams;
|
|
93
|
+
// タイトルでフィルターする場合に対応
|
|
94
|
+
if (filteredByTitle) {
|
|
95
|
+
saveParams = screeningEventSerieses.map((screeningEventSeries) => {
|
|
96
|
+
return {
|
|
97
|
+
id: screeningEventSeries.id,
|
|
98
|
+
attributes: screeningEventSeries,
|
|
99
|
+
upsert: true
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
else if (Array.isArray(importingIds) && importingIds.length > 0) {
|
|
104
|
+
saveParams = screeningEventSerieses
|
|
105
|
+
.filter((screeningEventSeries) => importingIds.includes(screeningEventSeries.id))
|
|
106
|
+
.map((screeningEventSeries) => {
|
|
107
|
+
return {
|
|
108
|
+
id: screeningEventSeries.id,
|
|
109
|
+
attributes: screeningEventSeries,
|
|
110
|
+
upsert: true
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
// 更新対象が無限に増えるのを防ぐためにstartDateでフィルター
|
|
116
|
+
const someMonthsAgo = moment()
|
|
117
|
+
.add(-COA_IMPORT_SCREENING_EVENT_SERIES_PERIOD_IN_MONTH, 'months');
|
|
118
|
+
saveParams = screeningEventSerieses
|
|
119
|
+
.filter((screeningEventSeries) => {
|
|
120
|
+
return moment(screeningEventSeries.startDate)
|
|
121
|
+
.isAfter(someMonthsAgo);
|
|
122
|
+
})
|
|
123
|
+
.map((screeningEventSeries) => {
|
|
124
|
+
return {
|
|
125
|
+
id: screeningEventSeries.id,
|
|
126
|
+
attributes: screeningEventSeries,
|
|
127
|
+
upsert: true
|
|
128
|
+
};
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
debug('saving', saveParams.length, 'ScreeningEventSeries...');
|
|
132
|
+
yield repos.eventSeries.upsertManyEventSeriesById4sskts(saveParams);
|
|
133
|
+
debug('saved', saveParams.length, 'ScreeningEventSeries');
|
|
134
|
+
savedEventsCount = saveParams.length;
|
|
135
|
+
// コンテンツ永続化(2023-10-23~)
|
|
136
|
+
try {
|
|
137
|
+
debug('saving', saveParams.length, 'movies...');
|
|
138
|
+
yield repos.creativeWork.upsertMoviesByIdentifier(saveParams.map((saveScreeningEventSeriesParams) => {
|
|
139
|
+
var _a;
|
|
140
|
+
return {
|
|
141
|
+
$set: Object.assign(Object.assign({ typeOf: factory.creativeWorkType.Movie, project: params.project, identifier: saveScreeningEventSeriesParams.attributes.workPerformed.identifier, name: { ja: (_a = saveScreeningEventSeriesParams.attributes.workPerformed.name) === null || _a === void 0 ? void 0 : _a.ja }, offers: { typeOf: factory.offerType.Offer } }, (typeof saveScreeningEventSeriesParams.attributes.workPerformed.contentRating === 'string')
|
|
142
|
+
? { contentRating: saveScreeningEventSeriesParams.attributes.workPerformed.contentRating }
|
|
143
|
+
: undefined), (typeof saveScreeningEventSeriesParams.attributes.workPerformed.duration === 'string')
|
|
144
|
+
? { duration: saveScreeningEventSeriesParams.attributes.workPerformed.duration }
|
|
145
|
+
: undefined)
|
|
146
|
+
};
|
|
147
|
+
}));
|
|
148
|
+
debug('saved', saveParams.length, 'movies');
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
// tslint:disable-next-line:no-console
|
|
152
|
+
console.error('failed in upsertMoviesByIdentifier', error);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return { screeningEventSerieses, savedEventsCount };
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* 作品抽出結果から施設コンテンツを作成する
|
|
160
|
+
*/
|
|
161
|
+
function createScreeningEventSeriesFromCOA(params) {
|
|
162
|
+
const endDate = (moment(`${params.filmFromCOA.dateEnd} +09:00`, 'YYYYMMDD Z')
|
|
163
|
+
.isValid())
|
|
164
|
+
? moment(`${params.filmFromCOA.dateEnd} +09:00`, 'YYYYMMDD Z')
|
|
165
|
+
.toDate()
|
|
166
|
+
: moment('2118-01-01T00:00:00+09:00') // 値がない場合、十分に長く
|
|
167
|
+
.toDate();
|
|
168
|
+
const startDate = (moment(`${params.filmFromCOA.dateBegin} +09:00`, 'YYYYMMDD Z')
|
|
169
|
+
.isValid())
|
|
170
|
+
? moment(`${params.filmFromCOA.dateBegin} +09:00`, 'YYYYMMDD Z')
|
|
171
|
+
.toDate()
|
|
172
|
+
: moment('2018-01-01T00:00:00+09:00') // 値がない場合、十分に長く
|
|
173
|
+
.toDate();
|
|
174
|
+
// title_codeは施設をまたいで共有、title_branch_numは施設毎に管理
|
|
175
|
+
const id = createScreeningEventSeriesId({
|
|
176
|
+
theaterCode: params.movieTheater.branchCode,
|
|
177
|
+
titleCode: params.filmFromCOA.titleCode,
|
|
178
|
+
titleBranchNum: params.filmFromCOA.titleBranchNum
|
|
179
|
+
});
|
|
180
|
+
const { additionalProperty, coaInfo } = createScreeningEventSeriesAdditionalPropertyFromCOA(params);
|
|
181
|
+
const { unacceptedPaymentMethod } = createScreeningEventSeriesUnacceptedPaymentMethodFromCOA(params);
|
|
182
|
+
const workPerformed = Object.assign({
|
|
183
|
+
// id: `${params.movieTheater.branchCode}-${params.filmFromCOA.titleCode}`, // discontinue(2025-01-03~)
|
|
184
|
+
identifier: params.filmFromCOA.titleCode, name: {
|
|
185
|
+
ja: params.filmFromCOA.titleNameOrig
|
|
186
|
+
}, duration: moment.duration(params.filmFromCOA.showTime, 'm')
|
|
187
|
+
.toISOString(), contentRating: params.eirinKubuns.filter((kubun) => kubun.kubunCode === params.filmFromCOA.kbnEirin)[0], typeOf: factory.creativeWorkType.Movie }, (typeof params.filmFromCOA.titleBranchNum === 'string' && params.filmFromCOA.titleBranchNum.length > 0)
|
|
188
|
+
? { version: params.filmFromCOA.titleBranchNum } // add version(2024-01-31~)
|
|
189
|
+
: undefined);
|
|
190
|
+
// redefine videoFormat(2024-09-18~)
|
|
191
|
+
// const videoFormat: factory.event.screeningEventSeries.ICOAKubun =
|
|
192
|
+
// params.eizouKubuns.filter((kubun) => kubun.kubunCode === params.filmFromCOA.kbnEizou)[0];
|
|
193
|
+
const videoFormat = params.joueihousikiKubuns.filter(({ kubunCode }) => kubunCode === params.filmFromCOA.kbnJoueihousiki)
|
|
194
|
+
.map(({ kubunCode }) => ({ typeOf: kubunCode, name: kubunCode }));
|
|
195
|
+
return {
|
|
196
|
+
project: { typeOf: params.project.typeOf, id: params.project.id },
|
|
197
|
+
typeOf: factory.eventType.ScreeningEventSeries,
|
|
198
|
+
eventStatus: factory.eventStatusType.EventScheduled,
|
|
199
|
+
id: id,
|
|
200
|
+
identifier: id,
|
|
201
|
+
name: {
|
|
202
|
+
ja: params.filmFromCOA.titleName,
|
|
203
|
+
en: params.filmFromCOA.titleNameEng
|
|
204
|
+
},
|
|
205
|
+
kanaName: params.filmFromCOA.titleNameKana,
|
|
206
|
+
alternativeHeadline: params.filmFromCOA.titleNameShort,
|
|
207
|
+
location: {
|
|
208
|
+
id: (params.movieTheater.id !== undefined) ? params.movieTheater.id : '',
|
|
209
|
+
branchCode: params.movieTheater.branchCode,
|
|
210
|
+
name: params.movieTheater.name,
|
|
211
|
+
// 廃止(2024-03-05~)
|
|
212
|
+
// kanaName: params.movieTheater.kanaName,
|
|
213
|
+
typeOf: params.movieTheater.typeOf
|
|
214
|
+
},
|
|
215
|
+
// 必須化(2023-07-12~)
|
|
216
|
+
organizer: { id: params.seller.id },
|
|
217
|
+
videoFormat,
|
|
218
|
+
soundFormat: [],
|
|
219
|
+
workPerformed,
|
|
220
|
+
duration: moment.duration(params.filmFromCOA.showTime, 'm')
|
|
221
|
+
.toISOString(),
|
|
222
|
+
endDate: endDate,
|
|
223
|
+
startDate: startDate,
|
|
224
|
+
coaInfo,
|
|
225
|
+
offers: Object.assign({ typeOf: factory.offerType.Offer }, (Array.isArray(unacceptedPaymentMethod)) ? { unacceptedPaymentMethod: unacceptedPaymentMethod } : undefined),
|
|
226
|
+
additionalProperty
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
function createScreeningEventSeriesAdditionalPropertyFromCOA(params) {
|
|
230
|
+
const coaInfo = Object.assign(Object.assign(Object.assign({ titleBranchNum: params.filmFromCOA.titleBranchNum, kbnEirin: params.eirinKubuns.filter((k) => k.kubunCode === params.filmFromCOA.kbnEirin)[0], kbnEizou: params.eizouKubuns.filter((k) => k.kubunCode === params.filmFromCOA.kbnEizou)[0], kbnJoueihousiki: params.joueihousikiKubuns.filter((k) => k.kubunCode === params.filmFromCOA.kbnJoueihousiki)[0], kbnJimakufukikae: params.jimakufukikaeKubuns.filter((k) => k.kubunCode === params.filmFromCOA.kbnJimakufukikae)[0], flgMvtkUse: params.filmFromCOA.flgMvtkUse, dateMvtkBegin: params.filmFromCOA.dateMvtkBegin }, (typeof params.filmFromCOA.flgMgtkUse === 'string') ? { flgMgtkUse: params.filmFromCOA.flgMgtkUse } : undefined), (typeof params.filmFromCOA.dateMgtkBegin === 'string') ? { dateMgtkBegin: params.filmFromCOA.dateMgtkBegin } : undefined), (typeof params.filmFromCOA.flgNotDiscount === 'string') ? { flgNotDiscount: params.filmFromCOA.flgNotDiscount } : undefined);
|
|
231
|
+
return {
|
|
232
|
+
coaInfo,
|
|
233
|
+
additionalProperty: [
|
|
234
|
+
// { name: 'coaInfo', value: JSON.stringify(coaInfo) } // discontinue(2024-09-13~)
|
|
235
|
+
]
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
function createScreeningEventSeriesUnacceptedPaymentMethodFromCOA(params) {
|
|
239
|
+
let unacceptedPaymentMethod;
|
|
240
|
+
// flgMvtkUseはムビチケ、MGチケットの両方に適用される(<-flgMgtkUseが追加されるまで)(~2024-03-05)
|
|
241
|
+
if (params.filmFromCOA.flgMvtkUse === '1') {
|
|
242
|
+
// no op
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
if (!Array.isArray(unacceptedPaymentMethod)) {
|
|
246
|
+
unacceptedPaymentMethod = [];
|
|
247
|
+
}
|
|
248
|
+
// flgMvtkUseで決済方法区分から動的に
|
|
249
|
+
unacceptedPaymentMethod.push(...params.availablePaymentMethodTypes.filter(({ additionalProperty }) => { var _a; return ((_a = additionalProperty === null || additionalProperty === void 0 ? void 0 : additionalProperty.find(({ name }) => name === 'flgMvtkUse')) === null || _a === void 0 ? void 0 : _a.value) === '1'; })
|
|
250
|
+
.map(({ codeValue }) => codeValue));
|
|
251
|
+
}
|
|
252
|
+
if (params.filmFromCOA.flgMgtkUse === '0') {
|
|
253
|
+
if (!Array.isArray(unacceptedPaymentMethod)) {
|
|
254
|
+
unacceptedPaymentMethod = [];
|
|
255
|
+
}
|
|
256
|
+
// flgMgtkUseで決済方法区分から動的に
|
|
257
|
+
unacceptedPaymentMethod.push(...params.availablePaymentMethodTypes.filter(({ additionalProperty }) => { var _a; return ((_a = additionalProperty === null || additionalProperty === void 0 ? void 0 : additionalProperty.find(({ name }) => name === 'flgMgtkUse')) === null || _a === void 0 ? void 0 : _a.value) === '1'; })
|
|
258
|
+
.map(({ codeValue }) => codeValue));
|
|
259
|
+
}
|
|
260
|
+
if (Array.isArray(unacceptedPaymentMethod)) {
|
|
261
|
+
// 重複排除
|
|
262
|
+
unacceptedPaymentMethod = [...new Set(unacceptedPaymentMethod)];
|
|
263
|
+
}
|
|
264
|
+
return { unacceptedPaymentMethod };
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* COA情報からイベント識別子を作成する
|
|
268
|
+
*/
|
|
269
|
+
// tslint:disable-next-line:no-single-line-block-comment
|
|
270
|
+
/* istanbul ignore next */
|
|
271
|
+
function createScreeningEventSeriesId(params) {
|
|
272
|
+
return [
|
|
273
|
+
params.theaterCode,
|
|
274
|
+
params.titleCode,
|
|
275
|
+
params.titleBranchNum
|
|
276
|
+
].join('');
|
|
277
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type * as COA from '@motionpicture/coa-service';
|
|
2
|
+
import type { CategoryCodeRepo } from '../../repo/categoryCode';
|
|
3
|
+
import type { CreativeWorkRepo } from '../../repo/creativeWork';
|
|
4
|
+
import type { EventRepo } from '../../repo/event';
|
|
5
|
+
import type { EventSeriesRepo } from '../../repo/eventSeries';
|
|
6
|
+
import * as factory from '../../factory';
|
|
7
|
+
type IMovieTheater = Pick<factory.place.movieTheater.IPlace, 'id' | 'typeOf' | 'branchCode' | 'name' | 'kanaName'>;
|
|
8
|
+
declare function saveScreeningEvents(params: {
|
|
9
|
+
movieTheater: IMovieTheater;
|
|
10
|
+
screeningRooms: Pick<factory.place.screeningRoom.IPlace, 'typeOf' | 'branchCode' | 'name' | 'maximumAttendeeCapacity'>[];
|
|
11
|
+
screeningEventSerieses?: factory.eventSeries.IEvent[];
|
|
12
|
+
project: {
|
|
13
|
+
id: string;
|
|
14
|
+
typeOf: factory.organizationType.Project;
|
|
15
|
+
};
|
|
16
|
+
targetImportFrom: Date;
|
|
17
|
+
targetImportThrough: Date;
|
|
18
|
+
seller: {
|
|
19
|
+
id: string;
|
|
20
|
+
};
|
|
21
|
+
instrument: factory.action.update.replace.IInstrumentAsCOAAPI;
|
|
22
|
+
}, options: {
|
|
23
|
+
filterSchedulesFromCOA?: {
|
|
24
|
+
titleCode: string;
|
|
25
|
+
titleBranchNum: string;
|
|
26
|
+
roomCode: string;
|
|
27
|
+
};
|
|
28
|
+
}): (repos: {
|
|
29
|
+
categoryCode: CategoryCodeRepo;
|
|
30
|
+
creativeWork: CreativeWorkRepo;
|
|
31
|
+
event: EventRepo;
|
|
32
|
+
eventSeries: EventSeriesRepo;
|
|
33
|
+
masterService: COA.service.Master;
|
|
34
|
+
}) => Promise<factory.event.screeningEvent.IEvent[]>;
|
|
35
|
+
/**
|
|
36
|
+
* COA情報からイベントIDを作成する
|
|
37
|
+
*/
|
|
38
|
+
declare function createScreeningEventIdFromCOA(params: {
|
|
39
|
+
theaterCode: string;
|
|
40
|
+
titleCode: string;
|
|
41
|
+
titleBranchNum: string;
|
|
42
|
+
dateJouei: string;
|
|
43
|
+
screenCode: string;
|
|
44
|
+
timeBegin: string;
|
|
45
|
+
}): string;
|
|
46
|
+
export { createScreeningEventIdFromCOA, saveScreeningEvents };
|
|
@@ -0,0 +1,321 @@
|
|
|
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.createScreeningEventIdFromCOA = createScreeningEventIdFromCOA;
|
|
13
|
+
exports.saveScreeningEvents = saveScreeningEvents;
|
|
14
|
+
const createDebug = require("debug");
|
|
15
|
+
// import { google } from 'googleapis';
|
|
16
|
+
const moment = require("moment-timezone");
|
|
17
|
+
const factory = require("../../factory");
|
|
18
|
+
const saveScreeningEventSeries_1 = require("./saveScreeningEventSeries");
|
|
19
|
+
const debug = createDebug('chevre-domain:service:event');
|
|
20
|
+
function saveScreeningEvents(params, options) {
|
|
21
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const screeningEvents = yield createScreeningEvents(params, options)(repos);
|
|
23
|
+
// 永続化
|
|
24
|
+
debug(`storing ${screeningEvents.length} screeningEvents...`);
|
|
25
|
+
const saveParams = [];
|
|
26
|
+
for (const screeningEvent of screeningEvents) {
|
|
27
|
+
try {
|
|
28
|
+
const attributes = screeningEvent;
|
|
29
|
+
saveParams.push({
|
|
30
|
+
id: screeningEvent.id,
|
|
31
|
+
attributes: attributes,
|
|
32
|
+
upsert: true
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
// no op
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
yield repos.event.saveManyEvents(saveParams);
|
|
40
|
+
debug(`${screeningEvents.length} screeningEvents stored.`);
|
|
41
|
+
return screeningEvents;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function createScreeningEvents(params, options) {
|
|
45
|
+
// tslint:disable-next-line:max-func-body-length
|
|
46
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
const { filterSchedulesFromCOA } = options;
|
|
48
|
+
// let filteredByTitle: boolean = false;
|
|
49
|
+
const project = params.project;
|
|
50
|
+
if (typeof params.instrument.begin !== 'string') {
|
|
51
|
+
throw new factory.errors.ArgumentNull('instrument.begin');
|
|
52
|
+
}
|
|
53
|
+
if (typeof params.instrument.end !== 'string') {
|
|
54
|
+
throw new factory.errors.ArgumentNull('instrument.end');
|
|
55
|
+
}
|
|
56
|
+
// COAからイベント取得;
|
|
57
|
+
let schedulesFromCOA = yield repos.masterService.schedule({
|
|
58
|
+
theaterCode: params.instrument.theaterCode,
|
|
59
|
+
begin: params.instrument.begin, // COAは日本時間で判断
|
|
60
|
+
end: params.instrument.end // COAは日本時間で判断
|
|
61
|
+
});
|
|
62
|
+
if (typeof (filterSchedulesFromCOA === null || filterSchedulesFromCOA === void 0 ? void 0 : filterSchedulesFromCOA.titleBranchNum) === 'string'
|
|
63
|
+
&& typeof (filterSchedulesFromCOA === null || filterSchedulesFromCOA === void 0 ? void 0 : filterSchedulesFromCOA.titleBranchNum) === 'string'
|
|
64
|
+
&& typeof (filterSchedulesFromCOA === null || filterSchedulesFromCOA === void 0 ? void 0 : filterSchedulesFromCOA.roomCode) === 'string') {
|
|
65
|
+
schedulesFromCOA = schedulesFromCOA.filter((scheduleFromCOA) => {
|
|
66
|
+
return scheduleFromCOA.titleBranchNum === filterSchedulesFromCOA.titleBranchNum
|
|
67
|
+
&& scheduleFromCOA.titleCode === filterSchedulesFromCOA.titleCode
|
|
68
|
+
&& scheduleFromCOA.screenCode === filterSchedulesFromCOA.roomCode;
|
|
69
|
+
});
|
|
70
|
+
// filteredByTitle = true;
|
|
71
|
+
debug('schedulesFromCOAd filtered by title.', JSON.stringify(schedulesFromCOA));
|
|
72
|
+
}
|
|
73
|
+
debug(schedulesFromCOA.length, 'schedulesFromCOA processing...');
|
|
74
|
+
// COAから区分マスター抽出
|
|
75
|
+
const serviceKubuns = yield repos.masterService.kubunName({
|
|
76
|
+
theaterCode: params.instrument.theaterCode,
|
|
77
|
+
kubunClass: '009'
|
|
78
|
+
});
|
|
79
|
+
const acousticKubuns = yield repos.masterService.kubunName({
|
|
80
|
+
theaterCode: params.instrument.theaterCode,
|
|
81
|
+
kubunClass: '046'
|
|
82
|
+
});
|
|
83
|
+
let screeningEventSerieses;
|
|
84
|
+
if (Array.isArray(params.screeningEventSerieses)) {
|
|
85
|
+
screeningEventSerieses = params.screeningEventSerieses;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
// 指定がなければDBから検索する(2024-09-09~)
|
|
89
|
+
const importingEventSeriesIds = [...new Set(schedulesFromCOA.map((scheduleFromCOA) => {
|
|
90
|
+
return (0, saveScreeningEventSeries_1.createScreeningEventSeriesId)({
|
|
91
|
+
theaterCode: params.instrument.theaterCode,
|
|
92
|
+
titleCode: scheduleFromCOA.titleCode,
|
|
93
|
+
titleBranchNum: scheduleFromCOA.titleBranchNum
|
|
94
|
+
});
|
|
95
|
+
}))];
|
|
96
|
+
debug('searching eventSeries... importingEventSeriesIds:', importingEventSeriesIds);
|
|
97
|
+
if (importingEventSeriesIds.length > 0) {
|
|
98
|
+
screeningEventSerieses = yield repos.eventSeries.projectEventSeriesFields({
|
|
99
|
+
id: { $in: importingEventSeriesIds },
|
|
100
|
+
project: { id: { $eq: params.project.id } }
|
|
101
|
+
}, [
|
|
102
|
+
'project', 'typeOf', 'eventStatus', 'identifier',
|
|
103
|
+
'name', 'kanaName', 'alternativeHeadline', 'location',
|
|
104
|
+
'organizer', 'videoFormat', 'soundFormat', 'workPerformed',
|
|
105
|
+
'duration', 'endDate', 'startDate', 'coaInfo',
|
|
106
|
+
'offers', 'additionalProperty'
|
|
107
|
+
]);
|
|
108
|
+
debug(screeningEventSerieses.length, 'screeningEventSerieses for importing events found.');
|
|
109
|
+
// 万が一未インポートの施設コンテンツがあれば強制的にインポート(2024-09-09~)
|
|
110
|
+
if (screeningEventSerieses.length < importingEventSeriesIds.length) {
|
|
111
|
+
const saveScreeningEventSeriesResult = yield (0, saveScreeningEventSeries_1.saveScreeningEventSeries)({
|
|
112
|
+
locationBranchCode: params.instrument.theaterCode,
|
|
113
|
+
movieTheater: params.movieTheater,
|
|
114
|
+
project: params.project,
|
|
115
|
+
saveScreeningEventSeries: true,
|
|
116
|
+
saveScreeningEventSeriesPeriodInMonth: 0, // importingIds指定するので0でok
|
|
117
|
+
seller: { id: params.seller.id },
|
|
118
|
+
importingIds: importingEventSeriesIds
|
|
119
|
+
}, {})(repos);
|
|
120
|
+
screeningEventSerieses = saveScreeningEventSeriesResult.screeningEventSerieses;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
screeningEventSerieses = [];
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// イベントごとに永続化トライ
|
|
128
|
+
const screeningEvents = [];
|
|
129
|
+
schedulesFromCOA.forEach((scheduleFromCOA) => {
|
|
130
|
+
const screeningEventSeriesId = (0, saveScreeningEventSeries_1.createScreeningEventSeriesId)({
|
|
131
|
+
theaterCode: params.instrument.theaterCode,
|
|
132
|
+
titleCode: scheduleFromCOA.titleCode,
|
|
133
|
+
titleBranchNum: scheduleFromCOA.titleBranchNum
|
|
134
|
+
});
|
|
135
|
+
// ルーム存在チェック
|
|
136
|
+
const screenRoom = params.screeningRooms.find((place) => place.branchCode === scheduleFromCOA.screenCode);
|
|
137
|
+
// const screenRoom = <factory.place.screeningRoom.IPlace | undefined>movieTheater.containsPlace.find(
|
|
138
|
+
// (place) => place.branchCode === scheduleFromCOA.screenCode
|
|
139
|
+
// );
|
|
140
|
+
if (screenRoom === undefined) {
|
|
141
|
+
// tslint:disable-next-line:no-console
|
|
142
|
+
console.error('screenRoom not found.', scheduleFromCOA.screenCode);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
// イベントシリーズ取得
|
|
146
|
+
const screeningEventSeries = screeningEventSerieses.find((e) => e.id === screeningEventSeriesId);
|
|
147
|
+
if (screeningEventSeries === undefined) {
|
|
148
|
+
// tslint:disable-next-line:no-console
|
|
149
|
+
console.error('screeningEventSeries not found.', screeningEventSeriesId);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const screeningEvent = createScreeningEventFromCOA({
|
|
153
|
+
project: project,
|
|
154
|
+
performanceFromCOA: scheduleFromCOA,
|
|
155
|
+
screenRoom: screenRoom,
|
|
156
|
+
superEvent: screeningEventSeries,
|
|
157
|
+
serviceKubuns: serviceKubuns,
|
|
158
|
+
acousticKubuns: acousticKubuns,
|
|
159
|
+
seller: params.seller
|
|
160
|
+
});
|
|
161
|
+
// インポート期間で確実に絞る(2024-04-25~)
|
|
162
|
+
const isStartDateInTarget = moment(screeningEvent.startDate)
|
|
163
|
+
.isBetween(params.targetImportFrom, params.targetImportThrough, 'second', '[]');
|
|
164
|
+
if (isStartDateInTarget) {
|
|
165
|
+
screeningEvents.push(screeningEvent);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
debug('createScreeningEvents processed', params.targetImportFrom, params.targetImportThrough, params.instrument.begin, params.instrument.end, 'schedulesFromCOA.length:', schedulesFromCOA.length, 'screeningEvents.length:', screeningEvents.length);
|
|
169
|
+
return screeningEvents;
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
function minimizeSuperEvent(params) {
|
|
173
|
+
const { workPerformed, videoFormat, startDate, soundFormat, name, location, kanaName, identifier, endDate, duration, coaInfo, alternativeHeadline,
|
|
174
|
+
// additionalProperty,
|
|
175
|
+
typeOf, id
|
|
176
|
+
// project,
|
|
177
|
+
// organizer,
|
|
178
|
+
// offers,
|
|
179
|
+
// eventStatus
|
|
180
|
+
} = params.superEvent;
|
|
181
|
+
return {
|
|
182
|
+
workPerformed, videoFormat, startDate, soundFormat,
|
|
183
|
+
name, location, kanaName, identifier,
|
|
184
|
+
endDate, duration, coaInfo, alternativeHeadline,
|
|
185
|
+
// additionalProperty,
|
|
186
|
+
typeOf, id
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* コアデータからイベントを作成する
|
|
191
|
+
*/
|
|
192
|
+
function createScreeningEventFromCOA(params) {
|
|
193
|
+
const id = createScreeningEventIdFromCOA({
|
|
194
|
+
theaterCode: params.superEvent.location.branchCode,
|
|
195
|
+
titleCode: params.superEvent.workPerformed.identifier,
|
|
196
|
+
titleBranchNum: params.performanceFromCOA.titleBranchNum,
|
|
197
|
+
dateJouei: params.performanceFromCOA.dateJouei,
|
|
198
|
+
screenCode: params.performanceFromCOA.screenCode,
|
|
199
|
+
timeBegin: params.performanceFromCOA.timeBegin
|
|
200
|
+
});
|
|
201
|
+
// COA情報を整形して開始日時と終了日時を作成('2500'のような日またぎの時刻入力に対応)
|
|
202
|
+
const DAY = 2400;
|
|
203
|
+
let timeBegin = params.performanceFromCOA.timeBegin;
|
|
204
|
+
let timeEnd = params.performanceFromCOA.timeEnd;
|
|
205
|
+
let addDay4startDate = 0;
|
|
206
|
+
let addDay4endDate = 0;
|
|
207
|
+
try {
|
|
208
|
+
addDay4startDate += Math.floor(Number(timeBegin) / DAY);
|
|
209
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
210
|
+
timeBegin = `0000${Number(timeBegin) % DAY}`.slice(-4);
|
|
211
|
+
addDay4endDate += Math.floor(Number(timeEnd) / DAY);
|
|
212
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
213
|
+
timeEnd = `0000${Number(timeEnd) % DAY}`.slice(-4);
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
// no op
|
|
217
|
+
}
|
|
218
|
+
let endDate = moment(`${params.performanceFromCOA.dateJouei} ${timeEnd} +09:00`, 'YYYYMMDD HHmm Z')
|
|
219
|
+
.add(addDay4endDate, 'days')
|
|
220
|
+
.toDate();
|
|
221
|
+
const startDate = moment(`${params.performanceFromCOA.dateJouei} ${timeBegin} +09:00`, 'YYYYMMDD HHmm Z')
|
|
222
|
+
.add(addDay4startDate, 'days')
|
|
223
|
+
.toDate();
|
|
224
|
+
// startDateの方が大きければ日またぎイベントなので調整
|
|
225
|
+
// tslint:disable-next-line:no-single-line-block-comment
|
|
226
|
+
/* istanbul ignore if */
|
|
227
|
+
if (moment(startDate)
|
|
228
|
+
.isAfter(moment(endDate))) {
|
|
229
|
+
endDate = moment(endDate)
|
|
230
|
+
.add(1, 'day')
|
|
231
|
+
.toDate();
|
|
232
|
+
}
|
|
233
|
+
const offers = {
|
|
234
|
+
typeOf: factory.offerType.Offer,
|
|
235
|
+
offeredThrough: {
|
|
236
|
+
typeOf: 'WebAPI',
|
|
237
|
+
identifier: factory.service.webAPI.Identifier.COA
|
|
238
|
+
},
|
|
239
|
+
eligibleQuantity: {
|
|
240
|
+
typeOf: 'QuantitativeValue',
|
|
241
|
+
unitCode: factory.unitCode.C62,
|
|
242
|
+
maxValue: Number(params.performanceFromCOA.availableNum)
|
|
243
|
+
},
|
|
244
|
+
itemOffered: {
|
|
245
|
+
serviceOutput: {
|
|
246
|
+
reservedTicket: {
|
|
247
|
+
typeOf: 'Ticket',
|
|
248
|
+
ticketedSeat: { typeOf: factory.placeType.Seat } // 必ず指定席
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
seller: {
|
|
253
|
+
typeOf: factory.organizationType.Corporation,
|
|
254
|
+
id: params.seller.id,
|
|
255
|
+
// name: params.sellerFromDB.name,
|
|
256
|
+
makesOffer: []
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
const { additionalProperty, coaInfo } = createScreeningEventAdditionalPropertyFromCOA(params);
|
|
260
|
+
const superEvent = minimizeSuperEvent({ superEvent: params.superEvent }); // optimize superEvent(2024-09-10~)
|
|
261
|
+
return {
|
|
262
|
+
project: { typeOf: params.project.typeOf, id: params.project.id },
|
|
263
|
+
typeOf: factory.eventType.ScreeningEvent,
|
|
264
|
+
id: id,
|
|
265
|
+
identifier: id,
|
|
266
|
+
name: params.superEvent.name,
|
|
267
|
+
eventStatus: factory.eventStatusType.EventScheduled,
|
|
268
|
+
location: {
|
|
269
|
+
typeOf: params.screenRoom.typeOf,
|
|
270
|
+
branchCode: params.screenRoom.branchCode,
|
|
271
|
+
name: params.screenRoom.name
|
|
272
|
+
},
|
|
273
|
+
endDate: endDate,
|
|
274
|
+
startDate: startDate,
|
|
275
|
+
superEvent,
|
|
276
|
+
coaInfo,
|
|
277
|
+
offers: offers,
|
|
278
|
+
checkInCount: 0,
|
|
279
|
+
attendeeCount: 0,
|
|
280
|
+
maximumAttendeeCapacity: params.screenRoom.maximumAttendeeCapacity,
|
|
281
|
+
remainingAttendeeCapacity: params.screenRoom.maximumAttendeeCapacity,
|
|
282
|
+
additionalProperty,
|
|
283
|
+
organizer: { id: params.seller.id }
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
function createScreeningEventAdditionalPropertyFromCOA(params) {
|
|
287
|
+
const coaInfo = {
|
|
288
|
+
theaterCode: params.superEvent.location.branchCode,
|
|
289
|
+
dateJouei: params.performanceFromCOA.dateJouei,
|
|
290
|
+
titleCode: params.performanceFromCOA.titleCode,
|
|
291
|
+
titleBranchNum: params.performanceFromCOA.titleBranchNum,
|
|
292
|
+
timeBegin: params.performanceFromCOA.timeBegin,
|
|
293
|
+
timeEnd: params.performanceFromCOA.timeEnd,
|
|
294
|
+
screenCode: params.performanceFromCOA.screenCode,
|
|
295
|
+
trailerTime: params.performanceFromCOA.trailerTime,
|
|
296
|
+
kbnService: params.serviceKubuns.filter((kubun) => kubun.kubunCode === params.performanceFromCOA.kbnService)[0],
|
|
297
|
+
kbnAcoustic: params.acousticKubuns.filter((kubun) => kubun.kubunCode === params.performanceFromCOA.kbnAcoustic)[0],
|
|
298
|
+
nameServiceDay: params.performanceFromCOA.nameServiceDay,
|
|
299
|
+
availableNum: params.performanceFromCOA.availableNum,
|
|
300
|
+
rsvStartDate: params.performanceFromCOA.rsvStartDate,
|
|
301
|
+
rsvEndDate: params.performanceFromCOA.rsvEndDate,
|
|
302
|
+
flgEarlyBooking: params.performanceFromCOA.flgEarlyBooking
|
|
303
|
+
};
|
|
304
|
+
return {
|
|
305
|
+
coaInfo,
|
|
306
|
+
additionalProperty: [
|
|
307
|
+
{ name: 'coaInfo', value: JSON.stringify(coaInfo) }
|
|
308
|
+
]
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* COA情報からイベントIDを作成する
|
|
313
|
+
*/
|
|
314
|
+
function createScreeningEventIdFromCOA(params) {
|
|
315
|
+
return [
|
|
316
|
+
(0, saveScreeningEventSeries_1.createScreeningEventSeriesId)(params),
|
|
317
|
+
params.dateJouei,
|
|
318
|
+
params.screenCode,
|
|
319
|
+
params.timeBegin
|
|
320
|
+
].join('');
|
|
321
|
+
}
|