@chevre/domain
Version:
Chevre Domain Library for Node.js
60 lines (59 loc) • 2.81 kB
JavaScript
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.placeOrderWithoutTransaction = placeOrderWithoutTransaction;
const factory = require("../../factory");
/**
* 注文取引なしに注文を作成する
*/
function placeOrderWithoutTransaction(params) {
return (repos) => __awaiter(this, void 0, void 0, function* () {
var _a;
const order = params.object;
const simpleOrder = {
typeOf: order.typeOf,
// seller: {
// id: order.seller.id,
// typeOf: order.seller.typeOf,
// name: order.seller.name
// }, // 廃止(2024-03-06~)
// customer: { typeOf: maskedCustomer.typeOf, id: maskedCustomer.id }, // 廃止(2024-03-06~)
orderNumber: order.orderNumber,
// price: order.price,
// priceCurrency: order.priceCurrency,
orderDate: order.orderDate
};
const orderActionAttributes = {
agent: (typeof ((_a = params.agent) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') ? params.agent : order.project,
object: simpleOrder,
// potentialActions: {}, // discontinue(2024-06-28~)
project: order.project,
// purpose: { typeOf: placeOrderTransaction.typeOf, id: placeOrderTransaction.id },
typeOf: factory.actionType.OrderAction
};
const action = yield repos.action.start(orderActionAttributes);
try {
yield repos.order.createIfNotExist(Object.assign(Object.assign({}, order), {
// discounts: [], // 廃止(2024-04-16~)
acceptedOffers: [] }));
}
catch (error) {
try {
yield repos.action.giveUp({ typeOf: orderActionAttributes.typeOf, id: action.id, error });
}
catch (__) {
// 失敗したら仕方ない
}
throw error;
}
yield repos.action.completeWithVoid({ typeOf: orderActionAttributes.typeOf, id: action.id, result: {} });
});
}
;