UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

56 lines (55 loc) 2.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createReservationOwnershipInfo = createReservationOwnershipInfo; const moment = require("moment-timezone"); const factory = require("../../../factory"); function createReservationOwnershipInfo(params) { var _a, _b; const itemOffered = params.acceptedOffer.itemOffered; let ownershipInfo; // イベント予約に対する所有権の有効期限はイベント終了日時までで十分だろう // 現時点では所有権対象がイベント予約のみなので、これで問題ないが、 // 対象が他に広がれば、有効期間のコントロールは別でしっかり行う必要があるだろう let ownedThrough; if (itemOffered.typeOf === factory.reservationType.EventReservation) { ownedThrough = moment(itemOffered.reservationFor.endDate) .toDate(); } else if (itemOffered.typeOf === factory.reservationType.BusReservation) { ownedThrough = moment(itemOffered.reservationFor.arrivalTime) .toDate(); } else { throw new factory.errors.NotImplemented(`itemOffered.typeOf '${itemOffered.typeOf}' not implemented`); } let bookingService = params.acceptedOffer.offeredThrough; if (bookingService === undefined) { // デフォルトブッキングサービスはChevre bookingService = { typeOf: 'WebAPI', identifier: factory.service.webAPI.Identifier.Chevre }; } let typeOfGood; if (itemOffered.typeOf === factory.reservationType.EventReservation) { typeOfGood = Object.assign({ typeOf: itemOffered.typeOf, id: itemOffered.id, reservationNumber: itemOffered.reservationNumber, bookingService: bookingService }, (typeof ((_a = itemOffered.issuedThrough) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') ? { issuedThrough: itemOffered.issuedThrough } : undefined); } else if (itemOffered.typeOf === factory.reservationType.BusReservation) { typeOfGood = Object.assign({ typeOf: itemOffered.typeOf, id: itemOffered.id, reservationNumber: itemOffered.reservationNumber, bookingService: bookingService }, (typeof ((_b = itemOffered.issuedThrough) === null || _b === void 0 ? void 0 : _b.typeOf) === 'string') ? { issuedThrough: itemOffered.issuedThrough } : undefined); } else { throw new factory.errors.NotImplemented(`itemOffered.typeOf '${itemOffered.typeOf}' not implemented`); } ownershipInfo = { project: params.project, typeOf: 'OwnershipInfo', id: '', identifier: params.identifier, ownedBy: params.ownedBy, acquiredFrom: params.acquiredFrom, ownedFrom: params.ownedFrom, ownedThrough: ownedThrough, typeOfGood }; return ownershipInfo; }