UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

97 lines (96 loc) 6.28 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const factory = require("../factory"); /** * 上映イベントに対するオファーを検索する */ function searchScreeningEventTicketOffers(params) { // tslint:disable-next-line:max-func-body-length return (repos) => __awaiter(this, void 0, void 0, function* () { const event = yield repos.event.findById({ typeOf: factory.eventType.ScreeningEvent, id: params.eventId }); const superEvent = yield repos.event.findById(event.superEvent); const eventSoundFormatTypes = (Array.isArray(event.superEvent.soundFormat)) ? event.superEvent.soundFormat.map((f) => f.typeOf) : []; const eventVideoFormatTypes = (Array.isArray(event.superEvent.videoFormat)) ? event.superEvent.videoFormat.map((f) => f.typeOf) : [factory.videoFormatType['2D']]; const ticketTypes = yield repos.ticketType.findByTicketGroupId({ ticketGroupId: event.offers.id }); // 価格仕様を検索する const soundFormatCompoundPriceSpecifications = yield repos.priceSpecification.searchCompoundPriceSpecifications({ typeOf: factory.priceSpecificationType.CompoundPriceSpecification, priceComponent: { typeOf: factory.priceSpecificationType.SoundFormatChargeSpecification } }); const videoFormatCompoundPriceSpecifications = yield repos.priceSpecification.searchCompoundPriceSpecifications({ typeOf: factory.priceSpecificationType.CompoundPriceSpecification, priceComponent: { typeOf: factory.priceSpecificationType.VideoFormatChargeSpecification } }); const movieTicketTypeCompoundPriceSpecifications = yield repos.priceSpecification.searchCompoundPriceSpecifications({ typeOf: factory.priceSpecificationType.CompoundPriceSpecification, priceComponent: { typeOf: factory.priceSpecificationType.MovieTicketTypeChargeSpecification } }); // イベントに関係のある価格仕様に絞り、ひとつの複合価格仕様としてまとめる const soundFormatChargeSpecifications = soundFormatCompoundPriceSpecifications.reduce((a, b) => [...a, ...b.priceComponent], []).filter((spec) => eventSoundFormatTypes.indexOf(spec.appliesToSoundFormat) >= 0); const videoFormatChargeSpecifications = videoFormatCompoundPriceSpecifications.reduce((a, b) => [...a, ...b.priceComponent], []).filter((spec) => eventVideoFormatTypes.indexOf(spec.appliesToVideoFormat) >= 0); const movieTicketTypeChargeSpecs = movieTicketTypeCompoundPriceSpecifications.reduce((a, b) => [...a, ...b.priceComponent], []).filter((spec) => eventVideoFormatTypes.indexOf(spec.appliesToVideoFormat) >= 0); const eventOffers = Object.assign({}, superEvent.offers, event.offers); // ムビチケが決済方法として許可されていれば、ムビチケオファーを作成 let movieTicketOffers = []; const movieTicketPaymentAccepted = eventOffers.acceptedPaymentMethod === undefined || eventOffers.acceptedPaymentMethod.indexOf(factory.paymentMethodType.MovieTicket) >= 0; if (movieTicketPaymentAccepted) { movieTicketOffers = ticketTypes .filter((t) => { const movieTicketType = t.priceSpecification.appliesToMovieTicketType; return movieTicketType !== undefined && movieTicketType !== '' // 万が一ムビチケチャージ仕様が存在しないオファーは除外する && movieTicketTypeChargeSpecs.filter((s) => s.appliesToMovieTicketType === movieTicketType).length > 0; }) .map((t) => { const movieTicketType = t.priceSpecification.appliesToMovieTicketType; const mvtkSpecs = movieTicketTypeChargeSpecs.filter((s) => s.appliesToMovieTicketType === movieTicketType); const compoundPriceSpecification = { typeOf: factory.priceSpecificationType.CompoundPriceSpecification, priceCurrency: factory.priceCurrency.JPY, valueAddedTaxIncluded: true, priceComponent: [ t.priceSpecification, ...mvtkSpecs ] }; return Object.assign({}, eventOffers, t, { eligibleQuantity: eventOffers.eligibleQuantity, priceSpecification: compoundPriceSpecification }); }); } // ムビチケ以外のオファーを作成 const ticketTypeOffers = ticketTypes .filter((t) => { return t.priceSpecification.appliesToMovieTicketType === undefined || t.priceSpecification.appliesToMovieTicketType === ''; }) .map((t) => { const compoundPriceSpecification = { typeOf: factory.priceSpecificationType.CompoundPriceSpecification, priceCurrency: factory.priceCurrency.JPY, valueAddedTaxIncluded: true, priceComponent: [ t.priceSpecification, ...videoFormatChargeSpecifications, ...soundFormatChargeSpecifications ] }; return Object.assign({}, eventOffers, t, { eligibleQuantity: eventOffers.eligibleQuantity, priceSpecification: compoundPriceSpecification }); }); return [...ticketTypeOffers, ...movieTicketOffers]; }); } exports.searchScreeningEventTicketOffers = searchScreeningEventTicketOffers;