@chevre/domain 21.30.0-alpha.14 → 21.30.0-alpha.15
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.
|
@@ -30,8 +30,8 @@ async function main() {
|
|
|
30
30
|
.add(1, 'day')
|
|
31
31
|
.toDate(),
|
|
32
32
|
saveMovieTheater: false,
|
|
33
|
-
saveScreeningEventSeries:
|
|
34
|
-
saveScreeningEventSeriesPeriodInMonth:
|
|
33
|
+
saveScreeningEventSeries: false,
|
|
34
|
+
saveScreeningEventSeriesPeriodInMonth: 3
|
|
35
35
|
})({
|
|
36
36
|
action: actionRepo,
|
|
37
37
|
categoryCode: categoryCodeRepo,
|
|
@@ -16,9 +16,8 @@ async function main() {
|
|
|
16
16
|
for (let index = 0; index < 24 * 1000; index++) {
|
|
17
17
|
const updateResult = await actionRepo.unsetUnnecessaryFields({
|
|
18
18
|
filter: {
|
|
19
|
-
|
|
19
|
+
typeOf: { $eq: chevre.factory.actionType.SendAction },
|
|
20
20
|
// 'agent.typeOf': { $exists: true, $eq: chevre.factory.creativeWorkType.WebApplication },
|
|
21
|
-
'agent.typeOf': { $exists: true, $eq: chevre.factory.personType.Person },
|
|
22
21
|
startDate: {
|
|
23
22
|
// $exists: true,
|
|
24
23
|
$gte: moment()
|
|
@@ -31,12 +30,12 @@ async function main() {
|
|
|
31
30
|
// _id: { $eq: '61da235d94a80f000af85f6b' }
|
|
32
31
|
},
|
|
33
32
|
$unset: {
|
|
34
|
-
'
|
|
35
|
-
'
|
|
36
|
-
'
|
|
37
|
-
'
|
|
38
|
-
'
|
|
39
|
-
'
|
|
33
|
+
'recipient.identifier': 1,
|
|
34
|
+
'recipient.memberOf': 1,
|
|
35
|
+
'recipient.email': 1,
|
|
36
|
+
'recipient.familyName': 1,
|
|
37
|
+
'recipient.givenName': 1,
|
|
38
|
+
'recipient.telephone': 1
|
|
40
39
|
// 'object.project': 1,
|
|
41
40
|
// 'object.seller': 1,
|
|
42
41
|
// 'object.customer': 1,
|
|
@@ -9,13 +9,7 @@ import type { MongoRepository as SellerRepo } from '../repo/seller';
|
|
|
9
9
|
import type { MongoRepository as TaskRepo } from '../repo/task';
|
|
10
10
|
import * as factory from '../factory';
|
|
11
11
|
import { createEvent } from './event/createEvent';
|
|
12
|
-
|
|
13
|
-
* Googleで作品画像を検索する
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* イベントをインポートする
|
|
17
|
-
*/
|
|
18
|
-
export declare function importFromCOA(params: {
|
|
12
|
+
interface IImportFromCOAParams {
|
|
19
13
|
project: {
|
|
20
14
|
id: string;
|
|
21
15
|
typeOf: factory.organizationType.Project;
|
|
@@ -35,7 +29,11 @@ export declare function importFromCOA(params: {
|
|
|
35
29
|
*/
|
|
36
30
|
saveScreeningEventSeries: boolean;
|
|
37
31
|
saveScreeningEventSeriesPeriodInMonth: number;
|
|
38
|
-
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* イベントをインポートする
|
|
35
|
+
*/
|
|
36
|
+
export declare function importFromCOA(params: IImportFromCOAParams): (repos: {
|
|
39
37
|
action: ActionRepo;
|
|
40
38
|
categoryCode: CategoryCodeRepo;
|
|
41
39
|
creativeWork: CreativeWorkRepo;
|
|
@@ -30,53 +30,18 @@ const coaAuthClient = new COA.auth.RefreshToken({
|
|
|
30
30
|
refreshToken: credentials_1.credentials.coa.refreshToken,
|
|
31
31
|
useFetch: credentials_1.credentials.coa.useFetch
|
|
32
32
|
});
|
|
33
|
-
/**
|
|
34
|
-
* Googleで作品画像を検索する
|
|
35
|
-
*/
|
|
36
|
-
// export async function findMovieImage(params: {
|
|
37
|
-
// query: string;
|
|
38
|
-
// }): Promise<string | undefined> {
|
|
39
|
-
// // カスタム検索エンジンIDの指定がなければ検索しない
|
|
40
|
-
// if (typeof credentials.customSearch.engineId !== 'string' || typeof credentials.customSearch.apiKey !== 'string') {
|
|
41
|
-
// return;
|
|
42
|
-
// }
|
|
43
|
-
// return new Promise<string | undefined>((resolve) => {
|
|
44
|
-
// customsearch.cse.list(
|
|
45
|
-
// {
|
|
46
|
-
// cx: credentials.customSearch.engineId,
|
|
47
|
-
// q: params.query,
|
|
48
|
-
// auth: credentials.customSearch.apiKey,
|
|
49
|
-
// num: 1,
|
|
50
|
-
// rights: 'cc_publicdomain cc_sharealike',
|
|
51
|
-
// // start: 0,
|
|
52
|
-
// // imgSize: 'medium',
|
|
53
|
-
// searchType: 'image'
|
|
54
|
-
// },
|
|
55
|
-
// (err: any, res: any) => {
|
|
56
|
-
// if (!(err instanceof Error)) {
|
|
57
|
-
// if (typeof res.data === 'object' && Array.isArray(res.data.items) && res.data.items.length > 0) {
|
|
58
|
-
// resolve(<string>res.data.items[0].image.thumbnailLink);
|
|
59
|
-
// // resolve(<string>res.data.items[0].link);
|
|
60
|
-
// return;
|
|
61
|
-
// // thumbnails.push({
|
|
62
|
-
// // eventId: event.id,
|
|
63
|
-
// // link: res.data.items[0].link,
|
|
64
|
-
// // thumbnailLink: res.data.items[0].image.thumbnailLink
|
|
65
|
-
// // });
|
|
66
|
-
// }
|
|
67
|
-
// }
|
|
68
|
-
// resolve();
|
|
69
|
-
// }
|
|
70
|
-
// );
|
|
71
|
-
// });
|
|
72
|
-
// }
|
|
73
33
|
/**
|
|
74
34
|
* イベントをインポートする
|
|
75
35
|
*/
|
|
76
36
|
function importFromCOA(params) {
|
|
77
37
|
// tslint:disable-next-line:max-func-body-length
|
|
78
38
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
79
|
-
const
|
|
39
|
+
const masterService = new COA.service.Master({
|
|
40
|
+
endpoint: credentials_1.credentials.coa.endpoint,
|
|
41
|
+
auth: coaAuthClient
|
|
42
|
+
}, { timeout: credentials_1.credentials.coa.timeout });
|
|
43
|
+
// 施設更新アクションを分離(2024-04-26~)
|
|
44
|
+
const { seller, movieTheater, screeningRooms } = yield processUpdateMovieTheater(params)(Object.assign(Object.assign({}, repos), { masterService }));
|
|
80
45
|
// const targetImportFrom = moment(`${moment(params.importFrom)
|
|
81
46
|
// .tz('Asia/Tokyo')
|
|
82
47
|
// .format('YYYY-MM-DD')}T00:00:00+09:00`);
|
|
@@ -99,65 +64,33 @@ function importFromCOA(params) {
|
|
|
99
64
|
.tz('Asia/Tokyo')
|
|
100
65
|
.format('YYYYMMDD'); // COAは日本時間で判断
|
|
101
66
|
debug('importing screening events...', targetImportFrom, targetImportThrough, begin, end);
|
|
67
|
+
const instrument = {
|
|
68
|
+
theaterCode: params.locationBranchCode,
|
|
69
|
+
begin,
|
|
70
|
+
end,
|
|
71
|
+
typeOf: 'WebAPI',
|
|
72
|
+
identifier: factory.service.webAPI.Identifier.COA
|
|
73
|
+
};
|
|
102
74
|
const actionAttributes = {
|
|
103
75
|
project: { typeOf: factory.organizationType.Project, id: params.project.id },
|
|
104
|
-
typeOf: factory.actionType.UpdateAction,
|
|
76
|
+
// typeOf: factory.actionType.UpdateAction,
|
|
77
|
+
typeOf: factory.actionType.ReplaceAction,
|
|
105
78
|
agent: { typeOf: factory.organizationType.Project, id: params.project.id },
|
|
106
|
-
object: Object.assign(Object.assign({}, params), {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
typeOf: 'WebAPI',
|
|
111
|
-
identifier: factory.service.webAPI.Identifier.COA
|
|
112
|
-
}
|
|
79
|
+
object: Object.assign(Object.assign({}, params), { startDate: `${moment(targetImportFrom) // debug(2024-04-26~)
|
|
80
|
+
.toISOString()}/${moment(targetImportThrough)
|
|
81
|
+
.toISOString()}`, superEvent: { location: { branchCode: params.locationBranchCode } }, typeOf: factory.eventType.ScreeningEvent }),
|
|
82
|
+
instrument
|
|
113
83
|
};
|
|
114
84
|
const action = yield repos.action.start(actionAttributes);
|
|
115
85
|
let savedScreeningEventsCount = 0;
|
|
116
86
|
let savedScreeningEventSeriesCount = 0;
|
|
87
|
+
let cancelledIds = [];
|
|
88
|
+
let processTime;
|
|
117
89
|
try {
|
|
118
|
-
const masterService = new COA.service.Master({
|
|
119
|
-
endpoint: credentials_1.credentials.coa.endpoint,
|
|
120
|
-
auth: coaAuthClient
|
|
121
|
-
}, { timeout: credentials_1.credentials.coa.timeout });
|
|
122
|
-
// 同ブランチコードの販売者を検索する
|
|
123
|
-
const sellersWithSameBranchCode = yield repos.seller.search({
|
|
124
|
-
limit: 1,
|
|
125
|
-
page: 1,
|
|
126
|
-
project: { id: { $eq: project.id } },
|
|
127
|
-
branchCode: { $eq: params.locationBranchCode }
|
|
128
|
-
}, ['_id'], []);
|
|
129
|
-
const seller = sellersWithSameBranchCode.shift();
|
|
130
|
-
if (typeof (seller === null || seller === void 0 ? void 0 : seller.id) !== 'string') {
|
|
131
|
-
throw new factory.errors.NotFound('Seller', `Seller with branchCod '${params.locationBranchCode}' not found`);
|
|
132
|
-
}
|
|
133
|
-
// saveMovieTheater:trueの場合のみ、施設保管(2022-10-10~)
|
|
134
|
-
if (params.saveMovieTheater === true) {
|
|
135
|
-
const savingMovieTheater = createMovieTheaterFromCOA(project, { id: seller.id }, yield masterService.theater({ theaterCode: params.locationBranchCode }), yield masterService.screen({ theaterCode: params.locationBranchCode }));
|
|
136
|
-
yield repos.movieTheater.saveMovieTheaterByBranchCode4coa(savingMovieTheater);
|
|
137
|
-
// } else {
|
|
138
|
-
// movieTheater = await repos.place.findMovieTheaterByBranchCode({
|
|
139
|
-
// project: { id: project.id },
|
|
140
|
-
// branchCode: creatingMovieTheater.branchCode
|
|
141
|
-
// });
|
|
142
|
-
}
|
|
143
|
-
const movieTheaters = yield repos.movieTheater.searchMovieTheaters({
|
|
144
|
-
limit: 1,
|
|
145
|
-
page: 1,
|
|
146
|
-
project: { id: { $eq: project.id } },
|
|
147
|
-
branchCode: { $eq: params.locationBranchCode }
|
|
148
|
-
}, ['_id', 'typeOf', 'branchCode', 'name', 'kanaName'], []);
|
|
149
|
-
const movieTheater = movieTheaters.shift();
|
|
150
|
-
if (movieTheater === undefined) {
|
|
151
|
-
throw new factory.errors.NotFound(factory.placeType.MovieTheater);
|
|
152
|
-
}
|
|
153
|
-
const screeningRooms = yield repos.screeningRoom.searchScreeningRooms({
|
|
154
|
-
project: { id: { $eq: project.id } },
|
|
155
|
-
containedInPlace: { branchCode: { $eq: movieTheater.branchCode } }
|
|
156
|
-
});
|
|
157
90
|
const { screeningEventSerieses, savedEventsCount } = yield saveScreeningEventSeries({
|
|
158
91
|
locationBranchCode: params.locationBranchCode,
|
|
159
92
|
movieTheater,
|
|
160
|
-
project: project,
|
|
93
|
+
project: params.project,
|
|
161
94
|
saveScreeningEventSeries: params.saveScreeningEventSeries,
|
|
162
95
|
saveScreeningEventSeriesPeriodInMonth: params.saveScreeningEventSeriesPeriodInMonth,
|
|
163
96
|
seller: { id: seller.id }
|
|
@@ -165,25 +98,27 @@ function importFromCOA(params) {
|
|
|
165
98
|
savedScreeningEventSeriesCount = savedEventsCount;
|
|
166
99
|
try {
|
|
167
100
|
// イベント永続化
|
|
101
|
+
const processStart = process.hrtime.bigint();
|
|
168
102
|
const screeningEvents = yield saveScreeningEvents({
|
|
169
|
-
locationBranchCode: params.locationBranchCode,
|
|
170
103
|
screeningRooms,
|
|
171
104
|
screeningEventSerieses: screeningEventSerieses,
|
|
172
|
-
project: project,
|
|
105
|
+
project: params.project,
|
|
173
106
|
targetImportFrom: targetImportFrom.toDate(),
|
|
174
107
|
targetImportThrough: targetImportThrough.toDate(),
|
|
175
108
|
seller: { id: seller.id },
|
|
176
|
-
instrument
|
|
109
|
+
instrument
|
|
177
110
|
})(repos);
|
|
178
111
|
savedScreeningEventsCount = screeningEvents.length;
|
|
179
112
|
// COAから削除されたイベントをキャンセル済ステータスへ変更
|
|
180
|
-
yield cancelDeletedEvents({
|
|
113
|
+
cancelledIds = yield cancelDeletedEvents({
|
|
181
114
|
project: params.project,
|
|
182
115
|
locationBranchCode: params.locationBranchCode,
|
|
183
116
|
targetImportFrom: targetImportFrom.toDate(),
|
|
184
117
|
targetImportThrough: targetImportThrough.toDate(),
|
|
185
118
|
idsShouldBe: screeningEvents.map((e) => e.id)
|
|
186
119
|
})(repos);
|
|
120
|
+
const processEnd = process.hrtime.bigint();
|
|
121
|
+
processTime = processEnd - processStart;
|
|
187
122
|
}
|
|
188
123
|
catch (error) {
|
|
189
124
|
let throwsError = true;
|
|
@@ -213,12 +148,82 @@ function importFromCOA(params) {
|
|
|
213
148
|
}
|
|
214
149
|
throw error;
|
|
215
150
|
}
|
|
216
|
-
|
|
217
|
-
|
|
151
|
+
const actionResult = Object.assign({ cancelledIds,
|
|
152
|
+
savedScreeningEventsCount,
|
|
153
|
+
savedScreeningEventSeriesCount }, (processTime !== undefined) ? { processTime } : undefined);
|
|
218
154
|
yield repos.action.completeWithVoid({ typeOf: action.typeOf, id: action.id, result: actionResult });
|
|
219
155
|
});
|
|
220
156
|
}
|
|
221
157
|
exports.importFromCOA = importFromCOA;
|
|
158
|
+
// tslint:disable-next-line:max-func-body-length
|
|
159
|
+
function processUpdateMovieTheater(params) {
|
|
160
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
161
|
+
const actionAttributes = {
|
|
162
|
+
project: { typeOf: factory.organizationType.Project, id: params.project.id },
|
|
163
|
+
typeOf: factory.actionType.ReplaceAction,
|
|
164
|
+
agent: { typeOf: factory.organizationType.Project, id: params.project.id },
|
|
165
|
+
object: Object.assign(Object.assign({}, params), { branchCode: params.locationBranchCode, typeOf: factory.placeType.MovieTheater }),
|
|
166
|
+
instrument: {
|
|
167
|
+
theaterCode: params.locationBranchCode,
|
|
168
|
+
typeOf: 'WebAPI',
|
|
169
|
+
identifier: factory.service.webAPI.Identifier.COA
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
const action = yield repos.action.start(actionAttributes);
|
|
173
|
+
let seller;
|
|
174
|
+
let movieTheater;
|
|
175
|
+
let screeningRooms;
|
|
176
|
+
let processTime;
|
|
177
|
+
try {
|
|
178
|
+
// 同ブランチコードの販売者を検索する
|
|
179
|
+
const sellersWithSameBranchCode = yield repos.seller.search({
|
|
180
|
+
limit: 1,
|
|
181
|
+
page: 1,
|
|
182
|
+
project: { id: { $eq: params.project.id } },
|
|
183
|
+
branchCode: { $eq: params.locationBranchCode }
|
|
184
|
+
}, ['_id'], []);
|
|
185
|
+
const sellerWithSameBranchCode = sellersWithSameBranchCode.shift();
|
|
186
|
+
if (typeof (sellerWithSameBranchCode === null || sellerWithSameBranchCode === void 0 ? void 0 : sellerWithSameBranchCode.id) !== 'string') {
|
|
187
|
+
throw new factory.errors.NotFound('Seller', `Seller with branchCode '${params.locationBranchCode}' not found`);
|
|
188
|
+
}
|
|
189
|
+
seller = { id: sellerWithSameBranchCode.id };
|
|
190
|
+
// saveMovieTheater:trueの場合のみ、施設保管(2022-10-10~)
|
|
191
|
+
if (params.saveMovieTheater === true) {
|
|
192
|
+
const processStart = process.hrtime.bigint();
|
|
193
|
+
const savingMovieTheater = createMovieTheaterFromCOA(params.project, { id: seller.id }, yield repos.masterService.theater({ theaterCode: params.locationBranchCode }), yield repos.masterService.screen({ theaterCode: params.locationBranchCode }));
|
|
194
|
+
yield repos.movieTheater.saveMovieTheaterByBranchCode4coa(savingMovieTheater);
|
|
195
|
+
const processEnd = process.hrtime.bigint();
|
|
196
|
+
processTime = processEnd - processStart;
|
|
197
|
+
}
|
|
198
|
+
const movieTheaters = yield repos.movieTheater.searchMovieTheaters({
|
|
199
|
+
limit: 1,
|
|
200
|
+
page: 1,
|
|
201
|
+
project: { id: { $eq: params.project.id } },
|
|
202
|
+
branchCode: { $eq: params.locationBranchCode }
|
|
203
|
+
}, ['_id', 'typeOf', 'branchCode', 'name', 'kanaName'], []);
|
|
204
|
+
movieTheater = movieTheaters.shift();
|
|
205
|
+
if (movieTheater === undefined) {
|
|
206
|
+
throw new factory.errors.NotFound(factory.placeType.MovieTheater);
|
|
207
|
+
}
|
|
208
|
+
screeningRooms = yield repos.screeningRoom.searchScreeningRooms({
|
|
209
|
+
project: { id: { $eq: params.project.id } },
|
|
210
|
+
containedInPlace: { branchCode: { $eq: movieTheater.branchCode } }
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
try {
|
|
215
|
+
yield repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error });
|
|
216
|
+
}
|
|
217
|
+
catch (__) {
|
|
218
|
+
// 失敗したら仕方ない
|
|
219
|
+
}
|
|
220
|
+
throw error;
|
|
221
|
+
}
|
|
222
|
+
const actionResult = Object.assign({ screeningRoomsCount: screeningRooms.length }, (processTime !== undefined) ? { processTime } : undefined);
|
|
223
|
+
yield repos.action.completeWithVoid({ typeOf: action.typeOf, id: action.id, result: actionResult });
|
|
224
|
+
return { seller, movieTheater, screeningRooms };
|
|
225
|
+
});
|
|
226
|
+
}
|
|
222
227
|
function saveScreeningEventSeries(params) {
|
|
223
228
|
// tslint:disable-next-line:max-func-body-length
|
|
224
229
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -349,24 +354,24 @@ function createScreeningEvents(params) {
|
|
|
349
354
|
}, { timeout: credentials_1.credentials.coa.timeout });
|
|
350
355
|
// COAからイベント取得;
|
|
351
356
|
const schedulesFromCOA = yield masterService.schedule({
|
|
352
|
-
theaterCode: params.
|
|
357
|
+
theaterCode: params.instrument.theaterCode,
|
|
353
358
|
begin: params.instrument.begin,
|
|
354
359
|
end: params.instrument.end // COAは日本時間で判断
|
|
355
360
|
});
|
|
356
361
|
// COAから区分マスター抽出
|
|
357
362
|
const serviceKubuns = yield masterService.kubunName({
|
|
358
|
-
theaterCode: params.
|
|
363
|
+
theaterCode: params.instrument.theaterCode,
|
|
359
364
|
kubunClass: '009'
|
|
360
365
|
});
|
|
361
366
|
const acousticKubuns = yield masterService.kubunName({
|
|
362
|
-
theaterCode: params.
|
|
367
|
+
theaterCode: params.instrument.theaterCode,
|
|
363
368
|
kubunClass: '046'
|
|
364
369
|
});
|
|
365
370
|
// イベントごとに永続化トライ
|
|
366
371
|
const screeningEvents = [];
|
|
367
372
|
schedulesFromCOA.forEach((scheduleFromCOA) => {
|
|
368
373
|
const screeningEventSeriesId = createScreeningEventSeriesId({
|
|
369
|
-
theaterCode: params.
|
|
374
|
+
theaterCode: params.instrument.theaterCode,
|
|
370
375
|
titleCode: scheduleFromCOA.titleCode,
|
|
371
376
|
titleBranchNum: scheduleFromCOA.titleBranchNum
|
|
372
377
|
});
|
|
@@ -435,6 +440,7 @@ function cancelDeletedEvents(params) {
|
|
|
435
440
|
}
|
|
436
441
|
}
|
|
437
442
|
debug(`${cancelledIds.length} events cancelled.`);
|
|
443
|
+
return cancelledIds;
|
|
438
444
|
});
|
|
439
445
|
}
|
|
440
446
|
/**
|
package/package.json
CHANGED