UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

108 lines (107 loc) 5.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.acceptedOffers2orderedItem = acceptedOffers2orderedItem; const factory = require("../../../../factory"); /** * 受入オファーを注文アイテムに変換する */ function acceptedOffers2orderedItem(params) { // 予約がある場合 const { reservationOrderItems } = createReservationAcceptedOffers(params); // 通貨転送がある場合 const { moneyTransferOrderItems } = createMoneyTransferAcceptedOffers(params); // プロダクトがある場合 const { productOrderItems } = createProductItems(params); return [...reservationOrderItems, ...moneyTransferOrderItems, ...productOrderItems]; } function createReservationAcceptedOffers(params) { const orderedItems = []; const eventIds = []; params.eventReservationAcceptedOffers.forEach(({ itemOffered }) => { // reservationFor.id単位でユニーク化 const reservationFor = itemOffered.reservationFor; const issuedThrough = itemOffered.issuedThrough; if (typeof reservationFor.id !== 'string' || reservationFor.id.length === 0) { throw new factory.errors.NotFound('acceptedOffers.itemOffered.reservationFor.id'); } if (typeof issuedThrough.typeOf === 'string') { if (!eventIds.includes(reservationFor.id)) { eventIds.push(reservationFor.id); const orderedItem = reservationOffers2orderedItem({ reservationFor, issuedThrough }); orderedItems.push({ typeOf: 'OrderItem', orderedItem }); } } }); return { reservationOrderItems: orderedItems }; } function reservationOffers2orderedItem(params) { var _a, _b; const reservationFor = params.reservationFor; const issuedThrough = params.issuedThrough; if (reservationFor.typeOf === factory.eventType.ScreeningEvent && issuedThrough.typeOf === factory.product.ProductType.EventService) { const reservationFor4orderedItem = { location: Object.assign({ branchCode: reservationFor.location.branchCode, typeOf: reservationFor.location.typeOf }, (reservationFor.location.name !== undefined) ? { name: reservationFor.location.name } : undefined), typeOf: reservationFor.typeOf, id: reservationFor.id, name: reservationFor.name, startDate: reservationFor.startDate, endDate: reservationFor.endDate }; return Object.assign(Object.assign({ typeOf: issuedThrough.typeOf, serviceOutput: { typeOf: factory.reservationType.EventReservation, reservationFor: reservationFor4orderedItem } }, (typeof issuedThrough.id === 'string') ? { id: issuedThrough.id } : undefined), (typeof ((_a = issuedThrough.serviceType) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') ? { serviceType: issuedThrough.serviceType } : undefined); } else if (reservationFor.typeOf === factory.tripType.BusTrip && issuedThrough.typeOf === factory.product.ProductType.Transportation) { const reservationFor4orderedItem = { typeOf: reservationFor.typeOf, id: reservationFor.id, departureTime: reservationFor.departureTime, arrivalTime: reservationFor.arrivalTime }; return Object.assign(Object.assign({ typeOf: issuedThrough.typeOf, id: issuedThrough.id }, (typeof ((_b = issuedThrough.serviceType) === null || _b === void 0 ? void 0 : _b.typeOf) === 'string') ? { serviceType: issuedThrough.serviceType } : undefined), { serviceOutput: { typeOf: factory.reservationType.ReservationPackage, reservationFor: reservationFor4orderedItem } }); } else { throw new factory.errors.Internal('unexpected params on reservationOffers2orderedItem'); } } function createProductItems(params) { var _a; const orderedItems = []; const productIds = []; if (Array.isArray(params.productAcceptedOffers) && params.productAcceptedOffers.length > 0) { // プロダクトIDで最適化する const issuedThrough = params.productAcceptedOffers[0].itemOffered.issuedThrough; if (typeof (issuedThrough === null || issuedThrough === void 0 ? void 0 : issuedThrough.id) === 'string') { if (!productIds.includes(issuedThrough.id)) { productIds.push(issuedThrough.id); orderedItems.push({ typeOf: 'OrderItem', orderedItem: Object.assign({ id: String(issuedThrough.id), typeOf: issuedThrough.typeOf }, (typeof ((_a = issuedThrough.serviceType) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') ? { serviceType: issuedThrough.serviceType } : undefined) }); } } } return { productOrderItems: orderedItems }; } function createMoneyTransferAcceptedOffers(__) { const orderedItems = []; return { moneyTransferOrderItems: orderedItems }; }