@chevre/domain 23.2.0-alpha.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.
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as factory from '../../factory';
|
|
2
|
+
import type { ICallResult, IExecutableTaskKeys, IOperationExecute } from '../taskHandler';
|
|
3
|
+
/**
|
|
4
|
+
* タスク実行関数
|
|
5
|
+
*/
|
|
6
|
+
export declare function call(params: Pick<factory.task.syncResourcesFromCOA.ITask, IExecutableTaskKeys>): IOperationExecute<ICallResult>;
|
|
@@ -0,0 +1,166 @@
|
|
|
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.call = call;
|
|
13
|
+
const COA = require("@motionpicture/coa-service");
|
|
14
|
+
const factory = require("../../factory");
|
|
15
|
+
const action_1 = require("../../repo/action");
|
|
16
|
+
const categoryCode_1 = require("../../repo/categoryCode");
|
|
17
|
+
const creativeWork_1 = require("../../repo/creativeWork");
|
|
18
|
+
const credentials_1 = require("../../repo/credentials");
|
|
19
|
+
// import { EventRepo } from '../../repo/event';
|
|
20
|
+
const eventSeries_1 = require("../../repo/eventSeries");
|
|
21
|
+
const movieTheater_1 = require("../../repo/place/movieTheater");
|
|
22
|
+
const reserveInterface_1 = require("../../repo/reserveInterface");
|
|
23
|
+
const saveScreeningEventSeries_1 = require("../event/saveScreeningEventSeries");
|
|
24
|
+
let coaAuthClient;
|
|
25
|
+
/**
|
|
26
|
+
* タスク実行関数
|
|
27
|
+
*/
|
|
28
|
+
function call(params) {
|
|
29
|
+
// tslint:disable-next-line:max-func-body-length
|
|
30
|
+
return (_a, options_1) => __awaiter(this, [_a, options_1], void 0, function* ({ connection, redisClient, settings }, options) {
|
|
31
|
+
var _b, _c, _d;
|
|
32
|
+
if (redisClient === undefined) {
|
|
33
|
+
throw new factory.errors.Argument('settings', 'redisClient required');
|
|
34
|
+
}
|
|
35
|
+
// 遅延実行(executeByName)には対応しない
|
|
36
|
+
if (!options.executeById) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const reserveInterfaceRepo = new reserveInterface_1.ReserveInterfaceRepo(connection);
|
|
40
|
+
const coaAPI = yield reserveInterfaceRepo.findOne({ project: { id: { $eq: params.project.id } } });
|
|
41
|
+
if (typeof (coaAPI === null || coaAPI === void 0 ? void 0 : coaAPI.id) !== 'string') {
|
|
42
|
+
throw new factory.errors.NotFound('WebAPI');
|
|
43
|
+
}
|
|
44
|
+
const credentials = (_b = coaAPI.availableChannel) === null || _b === void 0 ? void 0 : _b.credentials;
|
|
45
|
+
if (typeof (credentials === null || credentials === void 0 ? void 0 : credentials.refreshToken) !== 'string') {
|
|
46
|
+
throw new factory.errors.NotFound('WebAPI');
|
|
47
|
+
}
|
|
48
|
+
if (coaAuthClient === undefined) {
|
|
49
|
+
let credentialsRepo;
|
|
50
|
+
const credentialsExpireInSeconds = (_d = (_c = coaAPI.availableChannel) === null || _c === void 0 ? void 0 : _c.credentials) === null || _d === void 0 ? void 0 : _d.expireInSeconds;
|
|
51
|
+
if (typeof credentialsExpireInSeconds === 'number') {
|
|
52
|
+
// set credentialsRepo(2024-11-20~)
|
|
53
|
+
credentialsRepo = new credentials_1.CredentialsRepo(redisClient, {
|
|
54
|
+
scope: `COA:${coaAPI.id}`,
|
|
55
|
+
expireInSeconds: credentialsExpireInSeconds
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
coaAuthClient = new COA.auth.RefreshToken(Object.assign(Object.assign({}, credentials), (credentialsRepo !== undefined) ? { credentialsRepo } : undefined));
|
|
59
|
+
}
|
|
60
|
+
const actionRepo = new action_1.ActionRepo(connection);
|
|
61
|
+
try {
|
|
62
|
+
const masterService = new COA.service.Master({
|
|
63
|
+
endpoint: coaAuthClient.options.endpoint, // same as authClient(2024-07-17~)
|
|
64
|
+
auth: coaAuthClient
|
|
65
|
+
}, { timeout: settings.coa.timeout });
|
|
66
|
+
const { object } = params.data;
|
|
67
|
+
if (object.typeOf === factory.eventType.ScreeningEventSeries) {
|
|
68
|
+
yield syncEventSeries({
|
|
69
|
+
project: { id: params.project.id },
|
|
70
|
+
object,
|
|
71
|
+
sameAs: { id: params.id }
|
|
72
|
+
})({
|
|
73
|
+
action: actionRepo,
|
|
74
|
+
categoryCode: new categoryCode_1.CategoryCodeRepo(connection),
|
|
75
|
+
creativeWork: new creativeWork_1.CreativeWorkRepo(connection),
|
|
76
|
+
eventSeries: new eventSeries_1.EventSeriesRepo(connection),
|
|
77
|
+
movieTheater: new movieTheater_1.MovieTheaterRepo(connection),
|
|
78
|
+
masterService
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
let throwsError = true;
|
|
84
|
+
// アクションが存在すればタスクを実行済扱いにする
|
|
85
|
+
const action = (yield actionRepo.searchBySameAs({
|
|
86
|
+
sameAs: { id: { $eq: params.id } },
|
|
87
|
+
typeOf: { $eq: factory.actionType.ReplaceAction }
|
|
88
|
+
})).shift();
|
|
89
|
+
if (typeof (action === null || action === void 0 ? void 0 : action.id) === 'string') {
|
|
90
|
+
throwsError = false;
|
|
91
|
+
}
|
|
92
|
+
if (throwsError) {
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
// no op
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function syncEventSeries(params) {
|
|
102
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
const { locationBranchCode, titleBranchNum, titleCode } = params.object;
|
|
104
|
+
const movieTheater = (yield repos.movieTheater.projectFields({
|
|
105
|
+
limit: 1,
|
|
106
|
+
page: 1,
|
|
107
|
+
project: { id: { $eq: params.project.id } },
|
|
108
|
+
branchCode: { $eq: locationBranchCode }
|
|
109
|
+
}, ['id', 'typeOf', 'branchCode', 'name', 'kanaName', 'parentOrganization']
|
|
110
|
+
// []
|
|
111
|
+
)).shift();
|
|
112
|
+
if (movieTheater === undefined) {
|
|
113
|
+
throw new factory.errors.NotFound(factory.placeType.MovieTheater);
|
|
114
|
+
}
|
|
115
|
+
// console.log('movieTheater:', movieTheater);
|
|
116
|
+
const actionAttributes = {
|
|
117
|
+
project: { typeOf: factory.organizationType.Project, id: params.project.id },
|
|
118
|
+
typeOf: factory.actionType.ReplaceAction,
|
|
119
|
+
agent: { typeOf: factory.organizationType.Project, id: params.project.id },
|
|
120
|
+
// tslint:disable-next-line:no-suspicious-comment
|
|
121
|
+
// TODO define object
|
|
122
|
+
object: Object.assign(Object.assign({}, params.object), { typeOf: factory.eventType.ScreeningEventSeries }),
|
|
123
|
+
// instrument,
|
|
124
|
+
targetCollection: { typeOf: factory.eventType.ScreeningEventSeries },
|
|
125
|
+
sameAs: { id: params.sameAs.id, typeOf: 'Task' }
|
|
126
|
+
};
|
|
127
|
+
const action = yield repos.action.start(actionAttributes);
|
|
128
|
+
let saveResult;
|
|
129
|
+
try {
|
|
130
|
+
saveResult = yield (0, saveScreeningEventSeries_1.saveScreeningEventSeries)({
|
|
131
|
+
project: { id: params.project.id, typeOf: factory.organizationType.Project },
|
|
132
|
+
seller: { id: movieTheater.parentOrganization.id },
|
|
133
|
+
movieTheater,
|
|
134
|
+
locationBranchCode,
|
|
135
|
+
saveScreeningEventSeries: true,
|
|
136
|
+
saveScreeningEventSeriesPeriodInMonth: 3
|
|
137
|
+
}, {
|
|
138
|
+
filterFilmsFromCOA: {
|
|
139
|
+
titleBranchNum,
|
|
140
|
+
titleCode
|
|
141
|
+
}
|
|
142
|
+
})(repos);
|
|
143
|
+
// console.log(
|
|
144
|
+
// 'result:',
|
|
145
|
+
// saveResult.savedEventsCount,
|
|
146
|
+
// saveResult.screeningEventSerieses.length
|
|
147
|
+
// );
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
try {
|
|
151
|
+
yield repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error });
|
|
152
|
+
}
|
|
153
|
+
catch (__) {
|
|
154
|
+
// no op
|
|
155
|
+
}
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
158
|
+
const result = saveResult.screeningEventSerieses.map((eventSeries) => {
|
|
159
|
+
return {
|
|
160
|
+
id: eventSeries.id,
|
|
161
|
+
typeOf: eventSeries.typeOf
|
|
162
|
+
};
|
|
163
|
+
});
|
|
164
|
+
yield repos.action.completeWithVoid({ typeOf: action.typeOf, id: action.id, result });
|
|
165
|
+
});
|
|
166
|
+
}
|
|
@@ -69,6 +69,7 @@ function executeTask(task, next) {
|
|
|
69
69
|
case factory.taskName.ReturnPayTransaction:
|
|
70
70
|
case factory.taskName.ReturnReserveTransaction:
|
|
71
71
|
case factory.taskName.SendEmailMessage:
|
|
72
|
+
case factory.taskName.SyncResourcesFromCOA:
|
|
72
73
|
case factory.taskName.TriggerWebhook:
|
|
73
74
|
callResult = yield call(task)(settings, options);
|
|
74
75
|
break;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@aws-sdk/client-cognito-identity-provider": "3.600.0",
|
|
13
13
|
"@aws-sdk/credential-providers": "3.600.0",
|
|
14
|
-
"@chevre/factory": "5.4.0-alpha.
|
|
14
|
+
"@chevre/factory": "5.4.0-alpha.4",
|
|
15
15
|
"@cinerino/sdk": "12.12.1",
|
|
16
16
|
"@motionpicture/coa-service": "9.6.0",
|
|
17
17
|
"@motionpicture/gmo-service": "5.4.0-alpha.1",
|
|
@@ -115,5 +115,5 @@
|
|
|
115
115
|
"postversion": "git push origin --tags",
|
|
116
116
|
"prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
|
|
117
117
|
},
|
|
118
|
-
"version": "23.2.0-alpha.
|
|
118
|
+
"version": "23.2.0-alpha.1"
|
|
119
119
|
}
|