@chevre/domain
Version:
Chevre Domain Library for Node.js
95 lines (94 loc) • 5.48 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createStartParams = createStartParams;
const factory = require("../../../../../factory");
function createStartParams(params) {
var _a;
const { reservationNumber, acceptedOffers4transactionObject, objectSubReservations, agent, expires, project, instrument } = params;
const provider = {
id: params.provider.id,
typeOf: factory.organizationType.Corporation
};
// reservationFor,issuedThrough保管をaddReservationsから移行(2024-07-01~)
const reservationFor = createReservationFor(params.event, true);
const { issuedThrough } = createIssuedThrough({ reservationFor: params.event });
const reservationPackage = Object.assign({ issuedThrough, // addReservationsから移行(2024-07-01~)
provider,
reservationFor, reservationNumber: reservationNumber, reservationStatus: factory.reservationStatusType.ReservationPending, disablePendingReservations: true, useHoldStockByTransactionNumber: true, typeOf: factory.reservationType.ReservationPackage, acceptedOffer: acceptedOffers4transactionObject, subReservation: objectSubReservations }, (typeof ((_a = params.object.broker) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') ? { broker: params.object.broker } : undefined);
return {
project: { id: project.id, typeOf: factory.organizationType.Project },
typeOf: factory.assetTransactionType.Reserve,
transactionNumber: reservationNumber,
agent, expires,
object: reservationPackage,
instrument
};
}
function createReservationFor(params, useOptimizeReservation) {
var _a, _b;
if (params.typeOf === factory.eventType.ScreeningEvent) {
return Object.assign({ endDate: params.endDate, id: params.id, location: params.location, name: params.name, startDate: params.startDate, superEvent: optimizeReservationSuperEvent(params, useOptimizeReservation), typeOf: params.typeOf }, (params.doorTime instanceof Date)
? { doorTime: params.doorTime }
: undefined);
}
else {
const tripByEvent = (_b = (_a = params.offers) === null || _a === void 0 ? void 0 : _a.itemOffered.serviceOutput) === null || _b === void 0 ? void 0 : _b.reservationFor;
if (typeof (tripByEvent === null || tripByEvent === void 0 ? void 0 : tripByEvent.typeOf) !== 'string') {
throw new factory.errors.NotFound('event.offers.itemOffered.serviceOutput?.reservationFor');
}
return Object.assign(Object.assign({}, tripByEvent), { arrivalTime: params.endDate, id: params.id, name: params.name, departureTime: params.startDate });
}
}
function optimizeReservationSuperEvent(params, useOptimizeReservation) {
const superEvent = params.superEvent;
return Object.assign(Object.assign({ id: superEvent.id,
// kanaName: superEvent.kanaName, // 廃止(2024-01-26~)
location: superEvent.location, name: superEvent.name, soundFormat: superEvent.soundFormat, typeOf: superEvent.typeOf, videoFormat: superEvent.videoFormat, workPerformed: superEvent.workPerformed }, (superEvent.headline !== undefined)
? { headline: superEvent.headline }
: undefined), (useOptimizeReservation)
? {}
: {
additionalProperty: (Array.isArray(superEvent.additionalProperty))
? superEvent.additionalProperty
: []
});
}
function createIssuedThrough(params) {
var _a;
const eventOffers = params.reservationFor.offers;
// offersは必ず存在するはず
if (eventOffers === undefined) {
throw new factory.errors.NotFound('reservationFor.offers');
}
const serviceTypeOfIssuedThrough = (typeof ((_a = eventOffers.itemOffered.serviceType) === null || _a === void 0 ? void 0 : _a.codeValue) === 'string')
? {
codeValue: eventOffers.itemOffered.serviceType.codeValue,
inCodeSet: {
typeOf: 'CategoryCodeSet',
identifier: factory.categoryCode.CategorySetIdentifier.ServiceType
},
typeOf: 'CategoryCode'
}
: undefined;
const availableChannel = eventOffers.itemOffered.availableChannel;
if (availableChannel === undefined) {
// availableChannelは必ず存在するはず
throw new factory.errors.NotFound('reservationFor.offers.availableChannel');
}
if (params.reservationFor.typeOf === factory.eventType.ScreeningEvent) {
const issuedThrough = Object.assign({ typeOf: factory.product.ProductType.EventService,
// 興行IDを追加(2022-09-08~)
id: eventOffers.itemOffered.id, availableChannel }, (typeof (serviceTypeOfIssuedThrough === null || serviceTypeOfIssuedThrough === void 0 ? void 0 : serviceTypeOfIssuedThrough.typeOf) === 'string') ? { serviceType: serviceTypeOfIssuedThrough } : undefined);
return {
issuedThrough
};
}
else {
const issuedThrough = Object.assign({ typeOf: factory.product.ProductType.Transportation,
// 興行IDを追加(2022-09-08~)
id: eventOffers.itemOffered.id, availableChannel }, (typeof (serviceTypeOfIssuedThrough === null || serviceTypeOfIssuedThrough === void 0 ? void 0 : serviceTypeOfIssuedThrough.typeOf) === 'string') ? { serviceType: serviceTypeOfIssuedThrough } : undefined);
return {
issuedThrough
};
}
}