@chevre/domain
Version:
Chevre Domain Library for Node.js
140 lines (139 loc) • 8.55 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
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) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.product = exports.moneyTransfer = exports.eventServiceByCOA = exports.event = void 0;
exports.addOffers2Seat = addOffers2Seat;
exports.searchEventSeatOffersWithPaging = searchEventSeatOffersWithPaging;
const moment = require("moment");
const factory = require("../factory");
const EventOfferService = require("./offer/event");
exports.event = EventOfferService;
const EventServiceByCOAOfferService = require("./offer/eventServiceByCOA");
exports.eventServiceByCOA = EventServiceByCOAOfferService;
const MoneyTransferOfferService = require("./offer/moneyTransfer");
exports.moneyTransfer = MoneyTransferOfferService;
const ProductOfferService = require("./offer/product");
exports.product = ProductOfferService;
/**
* 座席にオファー情報を付加する
*/
function addOffers2Seat(params) {
// 座席タイプが指定されていれば、適用される価格仕様を構成要素に追加
const seatingTypes = (Array.isArray(params.seat.seatingType))
? params.seat.seatingType
: (typeof params.seat.seatingType === 'string' && params.seat.seatingType.length > 0) ? [params.seat.seatingType] : [];
const priceComponent = params.priceSpecs.filter(({ appliesToCategoryCode }) => {
// 適用カテゴリーコードに座席タイプが含まれる価格仕様を検索
return (Array.isArray(appliesToCategoryCode))
&& appliesToCategoryCode.some(({ codeValue }) => seatingTypes.includes(codeValue));
})
.map(({ appliesToCategoryCode, name, price, priceCurrency, typeOf, valueAddedTaxIncluded }) => {
return {
// optimize appliesToCategoryCode(2024-08-02~)
appliesToCategoryCode: appliesToCategoryCode.map(({ codeValue, inCodeSet }) => ({ codeValue, inCodeSet, typeOf: 'CategoryCode' })),
name, price, priceCurrency, typeOf, valueAddedTaxIncluded
};
});
const priceSpecification = {
typeOf: factory.priceSpecificationType.CompoundPriceSpecification,
priceComponent
};
let availability = factory.itemAvailability.InStock;
if (typeof params.availability === 'string') {
availability = params.availability;
}
return Object.assign(Object.assign({}, params.seat), { offers: [Object.assign({ availability }, (priceSpecification.priceComponent.length > 0) ? { priceSpecification } : undefined // priceComponentの存在する場合のみ追加(2023-11-08~)
)] });
}
/**
* イベントに対する座席オファーを検索する
*/
// tslint:disable-next-line:max-func-body-length
function searchEventSeatOffersWithPaging(params) {
// tslint:disable-next-line:max-func-body-length
return (repos) => __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
// const { excludePriceSpecification } = params.options;
let offers = [];
// optimize(2024-07-18~)
const event = yield repos.event.projectEventFieldsById({ id: params.event.id }, ['project', 'startDate', 'offers.itemOffered']);
// 座席指定利用可能かどうか
const eventOffers = event.offers;
const reservedSeatsAvailable = ((_b = (_a = eventOffers === null || eventOffers === void 0 ? void 0 : eventOffers.itemOffered.serviceOutput) === null || _a === void 0 ? void 0 : _a.reservedTicket) === null || _b === void 0 ? void 0 : _b.ticketedSeat) !== undefined;
if (reservedSeatsAvailable) {
const roomBranchCode = String((_d = (_c = eventOffers.itemOffered) === null || _c === void 0 ? void 0 : _c.availableChannel) === null || _d === void 0 ? void 0 : _d.serviceLocation.branchCode);
const movieTheaterBranchCode = String((_f = (_e = eventOffers.itemOffered) === null || _e === void 0 ? void 0 : _e.availableChannel) === null || _f === void 0 ? void 0 : _f.serviceLocation.containedInPlace.branchCode);
const seats = yield repos.seat.projectSeatsByScreeningRoom(Object.assign(Object.assign({}, params), { project: { id: { $eq: event.project.id } }, screeningRoom: {
branchCode: { $eq: roomBranchCode },
containedInPlace: {
branchCode: { $eq: movieTheaterBranchCode }
}
}, containedInPlace: {
branchCode: {
$eq: (typeof ((_h = (_g = params.containedInPlace) === null || _g === void 0 ? void 0 : _g.branchCode) === null || _h === void 0 ? void 0 : _h.$eq) === 'string')
? (_k = (_j = params.containedInPlace) === null || _j === void 0 ? void 0 : _j.branchCode) === null || _k === void 0 ? void 0 : _k.$eq
: undefined
}
}, $projection: Object.assign({}, params.$projection) }));
if (seats.length > 0) {
const availabilities = yield repos.stockHolder.searchHolders({
project: { id: event.project.id },
eventId: params.event.id,
startDate: moment(event.startDate)
.toDate(),
hasTicketedSeat: true,
offers: seats.map((s) => {
var _a;
return {
seatNumber: s.branchCode,
seatSection: (_a = s.containedInPlace) === null || _a === void 0 ? void 0 : _a.branchCode
};
})
});
// ルームに含まれる座席区分のみ加算料金を検索(2024-08-05~)
// const uniqueSeatingTypes = await repos.seat.aggregateSeatingTypes({
// project: { id: { $eq: event.project.id } },
// containedInPlace: {
// containedInPlace: {
// branchCode: { $eq: roomBranchCode },
// containedInPlace: { branchCode: { $eq: movieTheaterBranchCode } }
// }
// }
// });
// 座席タイプ価格仕様を検索
// let priceSpecs: ICategoryCodeChargeSpecification[] = [];
// if (!excludePriceSpecification) {
// if (Array.isArray(uniqueSeatingTypes) && uniqueSeatingTypes.length > 0) {
// priceSpecs =
// await repos.priceSpecification.search<factory.priceSpecificationType.CategoryCodeChargeSpecification>({
// project: { id: { $eq: event.project.id } },
// typeOf: factory.priceSpecificationType.CategoryCodeChargeSpecification,
// appliesToCategoryCode: {
// inCodeSet: { identifier: { $eq: factory.categoryCode.CategorySetIdentifier.SeatingType } },
// codeValue: { $in: uniqueSeatingTypes } // ルームに含まれる座席区分のみ加算料金を検索(2024-08-05~)
// }
// });
// }
// }
offers = seats.map((seat, index) => {
return addOffers2Seat({
seat,
availability: (typeof availabilities[index] === 'string')
? factory.itemAvailability.OutOfStock // ホルダーが存在すればOutOfStock
: factory.itemAvailability.InStock,
priceSpecs: [] // priceSpecsをレスポンスから廃止(2024-12-22~)
});
});
}
}
return offers;
});
}
;