UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

47 lines (46 loc) 2.35 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.publishConfirmationNumberIfNotExist = publishConfirmationNumberIfNotExist; const factory = require("../../../factory"); /** * 未発行であれば、注文の確認番号を発行して取引に保管する */ function publishConfirmationNumberIfNotExist(params) { return (repos) => __awaiter(this, void 0, void 0, function* () { let confirmationNumber = yield repos.transaction.findInProgressConfirmationNumberById({ id: params.id, status: { $in: params.status.$in } }); // すでに発行済であれば何もしない if (typeof confirmationNumber === 'string') { return confirmationNumber; } // 確認番号を発行 confirmationNumber = yield repos.confirmationNumber.publish({ orderDate: params.object.orderDate }); // 取引に存在しなければ保管 yield repos.transaction.saveConfirmationNumberIfNotExist({ id: params.id, status: { $in: params.status.$in }, confirmationNumber }); // 確認番号を取引から再取得 confirmationNumber = yield repos.transaction.findInProgressConfirmationNumberById({ id: params.id, status: { $in: params.status.$in } }); // 万が一処理が想定通りでない場合confirmationNumberが存在しない if (typeof confirmationNumber !== 'string') { throw new factory.errors.Internal('transaction.object.confirmationNumber not found'); } return confirmationNumber; }); }