UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

79 lines (78 loc) 4.28 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 action_1 = require("../../repo/action"); const assetTransaction_1 = require("../../repo/assetTransaction"); const authorization_1 = require("../../repo/authorization"); const orderNumber_1 = require("../../repo/orderNumber"); const paymentService_1 = require("../../repo/paymentService"); const paymentServiceProvider_1 = require("../../repo/paymentServiceProvider"); const project_1 = require("../../repo/project"); const sellerPaymentAccepted_1 = require("../../repo/sellerPaymentAccepted"); 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; } const actionRepo = new action_1.ActionRepo(connection); const transactionProcessRepo = new transactionProcess_1.TransactionProcessRepo(redisClient, { lockExpiresInSeconds: 120 }); try { yield (0, any_1.publishPaymentUrl)(Object.assign(Object.assign({}, params.data), { sameAs: { id: params.id } }))({ action: actionRepo, assetTransaction: new assetTransaction_1.AssetTransactionRepo(connection), authorization: new authorization_1.AuthorizationRepo(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), project: new project_1.ProjectRepo(connection), ticket: new ticket_1.TicketRepo(connection), transaction: new transaction_1.TransactionRepo(connection), transactionNumber: new transactionNumber_1.TransactionNumberRepo({ redisClient, connection }) }, 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.AcceptAction } })).shift(); if (typeof (action === null || action === void 0 ? void 0 : action.id) === 'string') { throwsError = false; } if (throwsError) { throw error; } } finally { // 取引プロセスロック解除 // if (params.data.options.useUnlockTransactionProcess) { yield transactionProcessRepo.unlock({ typeOf: params.data.purpose.typeOf, id: params.data.purpose.id }); // } } }); }