UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

53 lines (52 loc) 2.66 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.startAndConfirm = startAndConfirm; const mongoose_1 = require("mongoose"); const factory = require("../../../factory"); const factory_1 = require("./factory"); const start_1 = require("./start"); /** * 取引開始&確定 */ function startAndConfirm(params) { return (repos) => __awaiter(this, void 0, void 0, function* () { const project = yield repos.project.findById({ id: params.project.id, inclusion: ['typeOf'] }); const { reserveTransaction, reservations } = yield (0, start_1.validateStartParams)(params)(repos); const transactionNumber = params.transactionNumber; if (typeof transactionNumber !== 'string' || transactionNumber.length === 0) { throw new factory.errors.ArgumentNull('transactionNumber'); } const startParams = (0, factory_1.createStartParams)({ project: { id: project.id, typeOf: project.typeOf }, paramsWithoutDetail: params, transactionNumber, transaction: reserveTransaction, reservations: reservations }); const transactionId = new mongoose_1.Types.ObjectId().toHexString(); const transaction = Object.assign(Object.assign({}, startParams), { id: transactionId, startDate: new Date(), status: factory.transactionStatusType.InProgress }); // 事前に取引IDだけ発行 const potentialActions = (0, factory_1.createPotentialActions)({ transaction: transaction // confirmParams: { // id: transactionId, // potentialActions: params.potentialActions // } }); const result = {}; // 取引作成 return repos.assetTransaction.startAndConfirm(Object.assign(Object.assign({}, startParams), { id: transactionId, result: result, potentialActions: potentialActions })); }); }