@chevre/domain
Version:
Chevre Domain Library for Node.js
44 lines (43 loc) • 2.32 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.call = call;
const COA = require("@motionpicture/coa-service");
const event_1 = require("../../repo/event");
const reserveInterface_1 = require("../../repo/reserveInterface");
const factory = require("../../factory");
const EventAggregationService = require("../aggregation/event");
let coaAuthClient;
/**
* タスク実行関数
*/
function call(params) {
return (_a) => __awaiter(this, [_a], void 0, function* ({ connection, settings }) {
var _b;
if (coaAuthClient === undefined) {
const reserveInterfaceRepo = new reserveInterface_1.ReserveInterfaceRepo(connection);
const coaAPI = yield reserveInterfaceRepo.findOne({ project: { id: { $eq: params.project.id } } });
const credentials = (_b = coaAPI === null || coaAPI === void 0 ? void 0 : coaAPI.availableChannel) === null || _b === void 0 ? void 0 : _b.credentials;
if (typeof (credentials === null || credentials === void 0 ? void 0 : credentials.refreshToken) !== 'string') {
throw new factory.errors.NotFound('WebAPI');
}
coaAuthClient = new COA.auth.RefreshToken(credentials);
}
const reserveService = new COA.service.Reserve({
endpoint: coaAuthClient.options.endpoint, // same as authClient(2024-07-17~)
auth: coaAuthClient
}, { timeout: settings.coa.timeout });
yield EventAggregationService.importFromCOA(params.data)({
event: new event_1.EventRepo(connection),
reserveService
});
});
}
;