UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

94 lines (93 loc) 5.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createPotentialActions = createPotentialActions; // tslint:disable-next-line:max-func-body-length function createPotentialActions(params) { // const transaction = params.transaction; // const reservationFor = transaction.object.reservationFor; // if (reservationFor === undefined) { // throw new factory.errors.NotFound('transaction.object.reservationFor'); // } var _a; // discontinue(2024-07-01~) // const useOptimizeReservation: boolean = !USE_OPTIMIZE_RESERVATION_EXCEPTIONS.includes(transaction.project.id); // 予約アクション属性作成 // const pendingReservations = (Array.isArray(transaction.object.subReservation)) ? transaction.object.subReservation : []; // let reserveActionAttributes: factory.action.reserve.IAttributes[] = []; // let reservationPackage: factory.action.reserve.IObject | undefined; let underName; // purpose:Orderの指定があれば、underName,issuedByを調整(2022-05-23~) if (typeof ((_a = params.order) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') { const ordre2reservationUnderNameResult = ordre2reservationUnderName({ order: params.order }); underName = ordre2reservationUnderNameResult.underName; } // if (pendingReservations.length > 0) { // const moneyTransferActions: factory.action.transfer.moneyTransfer.IAttributes[] = []; // pendingReservations.forEach((reservation) => { // const acceptedOffer4reservation = transaction.object.acceptedOffer?.find( // (o) => o.itemOffered?.serviceOutput?.id === reservation.id // ); // moneyTransferActions.push(...createMoneyTransferActions({ // acceptedOffer: acceptedOffer4reservation, // reservation, // transaction: params.transaction, // underName // })); // }); // reservationPackage = { // reservationFor: { // id: String(reservationFor.id), // typeOf: reservationFor.typeOf, // optimized: true // }, // optimize(2024-01-24~) // reservationNumber: transaction.object.reservationNumber, // reservationStatus: (typeof params.transaction.object.reservationStatus === 'string') // ? params.transaction.object.reservationStatus // : factory.reservationStatusType.ReservationPending, // typeOf: factory.reservationType.ReservationPackage // }; // reserveActionAttributes = [{ // project: transaction.project, // typeOf: <factory.actionType.ReserveAction>factory.actionType.ReserveAction, // object: reservationPackage, // agent: transaction.project, // potentialActions: { // moneyTransfer: moneyTransferActions // }, // purpose: { typeOf: transaction.typeOf, id: transaction.id } // }]; // } return { potentialActions: { // reserve: reserveActionAttributes // discontinue(2024-07-01~) }, // reservationPackage, underName }; } /** * 予約のunderName.identifierを決定する */ function createReservationUnderNameIdentifier(params) { // 必要最低限の識別子のみ継承する(2024-03-16~) let identifiersFromCustomer = (Array.isArray(params.order.customer.identifier)) ? params.order.customer.identifier : []; // if (params.useOptimizeReservation) { // identifiersFromCustomer = identifiersFromCustomer.filter(({ name }) => name === 'clientId'); // } identifiersFromCustomer = identifiersFromCustomer.filter(({ name }) => name === 'clientId'); return [ { name: 'orderNumber', value: params.order.orderNumber }, ...identifiersFromCustomer ]; } function createReservationUnderName(params) { return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ identifier: createReservationUnderNameIdentifier({ order: params.order }), name: String(params.order.customer.name), typeOf: params.order.customer.typeOf }, (typeof params.order.customer.address === 'string') ? { address: params.order.customer.address } : undefined), (typeof params.order.customer.age === 'string') ? { age: params.order.customer.age } : undefined), (typeof params.order.customer.email === 'string') ? { email: params.order.customer.email } : undefined), (typeof params.order.customer.familyName === 'string') ? { familyName: params.order.customer.familyName } : undefined), (typeof params.order.customer.gender === 'string') ? { gender: params.order.customer.gender } : undefined), (typeof params.order.customer.givenName === 'string') ? { givenName: params.order.customer.givenName } : undefined), (typeof params.order.customer.id === 'string') ? { id: params.order.customer.id } : undefined), (typeof params.order.customer.telephone === 'string') ? { telephone: params.order.customer.telephone } : undefined), (typeof params.order.customer.url === 'string') ? { url: params.order.customer.url } : undefined); } /** * 注文者情報を予約者情報へ変換する */ function ordre2reservationUnderName(params) { return { underName: createReservationUnderName({ order: params.order }) }; }