UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

133 lines (132 loc) 7.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createCompoundPriceSpec4event = createCompoundPriceSpec4event; const factory = require("../../factory"); function categoryCodeChargePriceSpec2component(params) { return { id: params.id, typeOf: params.typeOf, name: params.name, price: params.price, priceCurrency: params.priceCurrency, valueAddedTaxIncluded: params.valueAddedTaxIncluded, appliesToCategoryCode: params.appliesToCategoryCode.map((categoryCode) => { if (categoryCode.inCodeSet.identifier !== factory.categoryCode.CategorySetIdentifier.SoundFormatType && categoryCode.inCodeSet.identifier !== factory.categoryCode.CategorySetIdentifier.VideoFormatType) { throw new factory.errors.Internal(`unexpected appliesToCategoryCode: ${categoryCode.inCodeSet.identifier}`); } return { typeOf: categoryCode.typeOf, codeValue: categoryCode.codeValue, inCodeSet: { identifier: categoryCode.inCodeSet.identifier, typeOf: 'CategoryCodeSet' } }; }) // ...(typeof params.accounting?.typeOf === 'string') ? { accounting: params.accounting } : undefined // 不要(2024-12-15~) }; } function mvtkChargePriceSpec2component(params) { return { id: params.id, typeOf: params.typeOf, name: params.name, price: params.price, priceCurrency: params.priceCurrency, valueAddedTaxIncluded: params.valueAddedTaxIncluded, appliesToVideoFormat: params.appliesToVideoFormat, appliesToMovieTicket: params.appliesToMovieTicket // ...(typeof params.accounting?.typeOf === 'string') ? { accounting: params.accounting } : undefined // 不要(2024-12-15~) }; } // tslint:disable-next-line:max-func-body-length function createCompoundPriceSpec4event(params) { var _a; // priceSpecificationはマスタ管理の仕様上必ず存在するはず if (params.offer.priceSpecification === undefined) { throw new factory.errors.NotFound(`priceSpecification of the offer: ${params.offer.id}`); } let videoFormatChargeSpecComponents = []; let soundFormatChargeSpecComponents = []; let potentialSeatingTypeChargeSpecComponents = []; // 区分加算料金を適用しないオプションを追加(2023-01-26~) const ignoreCategoryCodeChargeSpec = ((_a = params.offer.settings) === null || _a === void 0 ? void 0 : _a.ignoreCategoryCodeChargeSpec) === true; if (!ignoreCategoryCodeChargeSpec) { videoFormatChargeSpecComponents = params.videoFormatChargeSpecs.map(categoryCodeChargePriceSpec2component); soundFormatChargeSpecComponents = params.soundFormatChargeSpecs.map(categoryCodeChargePriceSpec2component); // 潜在的な区分加算料金を追加(2025-01-07~) if (params.includePotentialPriceComponent) { potentialSeatingTypeChargeSpecComponents = [{ appliesToCategoryCode: [{ typeOf: 'CategoryCode', inCodeSet: { identifier: factory.categoryCode.CategorySetIdentifier.SeatingType, typeOf: 'CategoryCodeSet' } }], priceCurrency: factory.priceCurrency.JPY, typeOf: factory.priceSpecificationType.CategoryCodeChargeSpecification, valueAddedTaxIncluded: true }]; } } const unitPriceSpec = Object.assign(Object.assign({}, params.offer.priceSpecification), { name: params.offer.name }); const mvtkPriceComponents = []; // 複数決済カード対応(2022-07-11~) if (Array.isArray(unitPriceSpec.appliesToMovieTicket)) { // 決済カード加算料金自動補完(2023-02-21~) unitPriceSpec.appliesToMovieTicket.forEach((appliesToMovieTicket) => { // すべての上映方式に該当する加算料金を追加 params.videoFormatTypes.forEach((videoFormatType) => { let existingMvtkSpec4appliesToMovieTicket = params.movieTicketTypeChargeSpecs.find((s) => { var _a; return ((_a = s.appliesToMovieTicket.serviceOutput) === null || _a === void 0 ? void 0 : _a.typeOf) === appliesToMovieTicket.serviceOutput.typeOf && s.appliesToMovieTicket.serviceType === appliesToMovieTicket.serviceType && s.appliesToVideoFormat === videoFormatType; }); // 加算料金が存在しなければprice: 0で自動補完 if (existingMvtkSpec4appliesToMovieTicket === undefined) { existingMvtkSpec4appliesToMovieTicket = { typeOf: factory.priceSpecificationType.MovieTicketTypeChargeSpecification, price: 0, priceCurrency: factory.priceCurrency.JPY, appliesToVideoFormat: videoFormatType, valueAddedTaxIncluded: true, project: params.offer.project, id: '', // ''でよいか name: params.offer.name, appliesToMovieTicket: { typeOf: factory.service.paymentService.PaymentServiceType.MovieTicket, serviceType: appliesToMovieTicket.serviceType, serviceOutput: { typeOf: appliesToMovieTicket.serviceOutput.typeOf } } }; } mvtkPriceComponents.push(mvtkChargePriceSpec2component(existingMvtkSpec4appliesToMovieTicket)); }); }); } // 区分加算料金は決済カード適用でも価格要素に含まれるはず(2022-11-02~) const priceComponent = [ unitPriceSpec, ...videoFormatChargeSpecComponents, ...soundFormatChargeSpecComponents, ...mvtkPriceComponents, ...potentialSeatingTypeChargeSpecComponents // 潜在的な区分加算料金を追加(2025-01-07~) ]; const compoundPriceSpecification = { typeOf: factory.priceSpecificationType.CompoundPriceSpecification, priceCurrency: factory.priceCurrency.JPY, valueAddedTaxIncluded: true, priceComponent }; // 必要な属性のみに限定(2023-02-24~) const { acceptedPaymentMethod, name, description, alternateName, color, typeOf, id, availability, category, eligibleMembershipType, eligibleSeatingType, eligibleMonetaryAmount, eligibleSubReservation, priceCurrency, validFrom, validThrough, validRateLimit, additionalProperty, identifier, itemOffered, offerIndex, parentOffer } = params.offer; return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ name, description, alternateName, color, typeOf, id, category, eligibleMembershipType, eligibleSeatingType, eligibleMonetaryAmount, eligibleSubReservation, priceCurrency, validFrom, validThrough, validRateLimit, additionalProperty, identifier, itemOffered, addOn: params.addOn, eligibleQuantity: params.eligibleQuantity, priceSpecification: compoundPriceSpecification }, (typeof params.availability === 'string') ? { availability: params.availability } : { availability }), (typeof params.sortIndex === 'number') ? { sortIndex: params.sortIndex } : undefined), (typeof offerIndex === 'number') ? { offerIndex } : undefined), (typeof (parentOffer === null || parentOffer === void 0 ? void 0 : parentOffer.id) === 'string') ? { parentOffer: { id: parentOffer.id } } : undefined), (Array.isArray(acceptedPaymentMethod)) ? { acceptedPaymentMethod } : undefined); }