UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

117 lines (116 loc) 5.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.createPotentialActions = createPotentialActions; const factory = require("../../../factory"); function createLocations(params) { var _a, _b, _c; const transaction = params.transaction; let fromLocation = { typeOf: transaction.agent.typeOf, name: transaction.agent.name }; let toLocation = { typeOf: transaction.recipient.typeOf, name: transaction.recipient.name }; const pendingTransactionType = (_a = transaction.object.pendingTransaction) === null || _a === void 0 ? void 0 : _a.typeOf; switch (pendingTransactionType) { case factory.account.transactionType.Deposit: if (typeof ((_b = transaction.object.fromLocation) === null || _b === void 0 ? void 0 : _b.typeOf) === 'string') { fromLocation = { typeOf: transaction.object.fromLocation.typeOf, name: transaction.agent.name }; } toLocation = { identifier: transaction.object.toLocation.identifier, issuedThrough: transaction.object.toLocation.issuedThrough, typeOf: transaction.object.toLocation.typeOf, name: transaction.recipient.name }; break; case factory.account.transactionType.Transfer: fromLocation = { identifier: transaction.object.fromLocation.identifier, issuedThrough: transaction.object.fromLocation.issuedThrough, typeOf: transaction.object.fromLocation.typeOf, name: transaction.agent.name }; toLocation = { identifier: transaction.object.toLocation.identifier, issuedThrough: transaction.object.toLocation.issuedThrough, typeOf: transaction.object.toLocation.typeOf, name: transaction.recipient.name }; break; case factory.account.transactionType.Withdraw: fromLocation = { identifier: transaction.object.fromLocation.identifier, issuedThrough: transaction.object.fromLocation.issuedThrough, typeOf: transaction.object.fromLocation.typeOf, name: transaction.agent.name }; if (typeof ((_c = transaction.object.toLocation) === null || _c === void 0 ? void 0 : _c.typeOf) === 'string') { toLocation = { typeOf: transaction.object.toLocation.typeOf, name: transaction.recipient.name }; } break; default: } return { fromLocation, toLocation }; } function createMoneyTransferActions(params) { const transaction = params.transaction; const { fromLocation, toLocation } = createLocations(params); return (transaction.object.pendingTransaction !== undefined) ? [{ project: transaction.project, typeOf: factory.actionType.MoneyTransfer, description: transaction.object.description, result: { amount: transaction.object.amount }, object: { typeOf: transaction.object.pendingTransaction.typeOf, transactionNumber: transaction.object.pendingTransaction.transactionNumber, pendingTransaction: transaction.object.pendingTransaction }, agent: transaction.agent, recipient: transaction.recipient, amount: transaction.object.amount, fromLocation: fromLocation, toLocation: toLocation, purpose: { typeOf: transaction.typeOf, id: transaction.id } }] : []; } /** * 取引のポストアクションを作成する */ function createPotentialActions(params) { return __awaiter(this, void 0, void 0, function* () { // 通貨転送アクション属性作成 const moneyTransferActionAttributesList = createMoneyTransferActions(params); // まずは1転送アクションのみ対応 if (moneyTransferActionAttributesList.length !== 1) { throw new factory.errors.Argument('Transaction', 'Number of moneyTransfer actions must be 1'); } return { moneyTransfer: moneyTransferActionAttributesList }; }); }