UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

135 lines (134 loc) 7.62 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 reserve_api_abstract_client_1 = require("@movieticket/reserve-api-abstract-client"); 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 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.ticketTypeGroup }); // 価格仕様を検索する 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 movieTicketTypeCodes = [...new Set(movieTicketTypeChargeSpecs.map((s) => s.appliesToMovieTicketType))]; const movieTicketOffers = movieTicketTypeCodes.map((movieTicketTypeCode) => { const movieTicketType = reserve_api_abstract_client_1.mvtk.util.constants.TICKET_TYPE.find((ticketType) => ticketType.code === movieTicketTypeCode); const unitPriceSpecification = { typeOf: factory.priceSpecificationType.UnitPriceSpecification, price: 0, priceCurrency: factory.priceCurrency.JPY, name: { ja: `ムビチケ${(movieTicketType !== undefined) ? movieTicketType.name : ''}`, en: 'Movie Ticket' }, description: { ja: `ムビチケ${(movieTicketType !== undefined) ? movieTicketType.name : ''}`, en: 'Movie Ticket' }, valueAddedTaxIncluded: true, referenceQuantity: { typeOf: 'QuantitativeValue', unitCode: factory.unitCode.C62, value: 1 } }; const mvtkSpecs = movieTicketTypeChargeSpecs.filter((s) => s.appliesToMovieTicketType === movieTicketTypeCode); const priceComponent = [ unitPriceSpecification, ...mvtkSpecs ]; const compoundPriceSpecification = { typeOf: factory.priceSpecificationType.CompoundPriceSpecification, priceCurrency: factory.priceCurrency.JPY, valueAddedTaxIncluded: true, priceComponent: priceComponent }; return { typeOf: 'Offer', id: `Offer-by-movieticket-${movieTicketTypeCode}`, name: { ja: `ムビチケ${(movieTicketType !== undefined) ? movieTicketType.name : ''}`, en: 'Movie Ticket' }, description: { ja: `ムビチケ${(movieTicketType !== undefined) ? movieTicketType.name : ''}`, en: 'Movie Ticket' }, valueAddedTaxIncluded: true, priceCurrency: factory.priceCurrency.JPY, priceSpecification: compoundPriceSpecification, availability: factory.itemAvailability.InStock }; }); const offers = ticketTypes.map((ticketType) => { // イベントに関係のある価格仕様に絞り、ひとつの複合価格仕様としてまとめる const unitPriceSpecification = { typeOf: factory.priceSpecificationType.UnitPriceSpecification, price: ticketType.price, priceCurrency: factory.priceCurrency.JPY, name: ticketType.name, description: ticketType.description, valueAddedTaxIncluded: true, referenceQuantity: { typeOf: 'QuantitativeValue', unitCode: factory.unitCode.C62, value: 1 } }; const priceComponent = [ unitPriceSpecification, ...videoFormatChargeSpecifications, ...soundFormatChargeSpecifications ]; const compoundPriceSpecification = { typeOf: factory.priceSpecificationType.CompoundPriceSpecification, priceCurrency: factory.priceCurrency.JPY, valueAddedTaxIncluded: true, priceComponent: priceComponent }; return { typeOf: 'Offer', id: ticketType.id, name: ticketType.name, description: ticketType.description, priceCurrency: factory.priceCurrency.JPY, priceSpecification: compoundPriceSpecification, availability: ticketType.availability }; }); return [...offers, ...movieTicketOffers]; }); } exports.searchScreeningEventTicketOffers = searchScreeningEventTicketOffers;