UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

112 lines (111 loc) 6.27 kB
"use strict"; 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 factory = require("../../factory"); const accountingReport_1 = require("../../repo/accountingReport"); const action_1 = require("../../repo/action"); const assetTransaction_1 = require("../../repo/assetTransaction"); const authorization_1 = require("../../repo/authorization"); const confirmationNumber_1 = require("../../repo/confirmationNumber"); const credentials_1 = require("../../repo/credentials"); const event_1 = require("../../repo/event"); const orderNumber_1 = require("../../repo/orderNumber"); const paymentService_1 = require("../../repo/paymentService"); const paymentServiceProvider_1 = require("../../repo/paymentServiceProvider"); const potentialAction_1 = require("../../repo/potentialAction"); const product_1 = require("../../repo/product"); const project_1 = require("../../repo/project"); const sellerPaymentAccepted_1 = require("../../repo/sellerPaymentAccepted"); const task_1 = require("../../repo/task"); const ticket_1 = require("../../repo/ticket"); const transaction_1 = require("../../repo/transaction"); const transactionNumber_1 = require("../../repo/transactionNumber"); const transactionProcess_1 = require("../../repo/transactionProcess"); const any_1 = require("../payment/any"); /** * タスク実行関数 */ function call(params) { return (_a, options_1) => __awaiter(this, [_a, options_1], void 0, function* ({ connection, redisClient, settings }, options) { if (redisClient === undefined) { throw new factory.errors.Argument('settings', 'redisClient required'); } // 遅延実行(executeByName)には対応しない if (!options.executeById) { return; } let callResult; const actionRepo = new action_1.ActionRepo(connection); const transactionProcessRepo = new transactionProcess_1.TransactionProcessRepo(redisClient, { lockExpiresInSeconds: 120 }); const paymentServiceId = params.data.object.issuedThrough.id; const credentialsExpireInSeconds = settings.movieticketReserve.credentialsExpireInSeconds; const useCredentialsRepo = typeof paymentServiceId === 'string' && paymentServiceId !== '' && typeof credentialsExpireInSeconds === 'number' && credentialsExpireInSeconds > 0; try { yield (0, any_1.authorize)(Object.assign(Object.assign({}, params.data), { sameAs: { id: params.id } // タスクIDを関連付け(2024-04-20~) }))({ accountingReport: new accountingReport_1.AccountingReportRepo(connection), action: actionRepo, assetTransaction: new assetTransaction_1.AssetTransactionRepo(connection), authorization: new authorization_1.AuthorizationRepo(connection), confirmationNumber: new confirmationNumber_1.ConfirmationNumberRepo({ redisClient, connection }), credentials: new credentials_1.CredentialsRepo(redisClient, { scope: `${factory.service.paymentService.PaymentServiceType.MovieTicket}:${paymentServiceId}`, expireInSeconds: (useCredentialsRepo) ? credentialsExpireInSeconds : 0 }), event: new event_1.EventRepo(connection), orderNumber: new orderNumber_1.OrderNumberRepo({ redisClient, connection }), paymentAccepted: new sellerPaymentAccepted_1.SellerPaymentAcceptedRepo(connection), paymentService: new paymentService_1.PaymentServiceRepo(connection), paymentServiceProvider: new paymentServiceProvider_1.PaymentServiceProviderRepo(connection), potentialAction: new potentialAction_1.PotentialActionRepo(connection), product: new product_1.ProductRepo(connection), project: new project_1.ProjectRepo(connection), task: new task_1.TaskRepo(connection), ticket: new ticket_1.TicketRepo(connection), transaction: new transaction_1.TransactionRepo(connection), transactionNumber: new transactionNumber_1.TransactionNumberRepo({ redisClient, connection }) // transactionProcess: transactionProcessRepo }, settings); } catch (error) { let throwsError = true; // アクションが存在すればタスクを実行済扱いにする const action = (yield actionRepo.searchBySameAs({ sameAs: { id: { $eq: params.id } }, purpose: { id: { $eq: params.data.purpose.id } }, typeOf: { $eq: factory.actionType.AuthorizeAction } })).shift(); if (typeof (action === null || action === void 0 ? void 0 : action.id) === 'string') { throwsError = false; } if (throwsError) { if (error instanceof Error) { // throwせずにcallResultとして返す(2024-05-29~) callResult = { error }; } else { throw error; } } } finally { // 取引プロセスロック解除(2024-04-20~) if (params.data.options.useUnlockTransactionProcess) { yield transactionProcessRepo.unlock({ typeOf: params.data.purpose.typeOf, id: params.data.purpose.id }); } } if (callResult !== undefined) { return callResult; } }); }