UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

40 lines (39 loc) 3.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createPointAward = createPointAward; const factory = require("../../../../../factory"); const accountTransactionIdentifier_1 = require("../../../../../factory/accountTransactionIdentifier"); /** * ポイント特典を作成する */ function createPointAward(params) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; let pointAward; const pointAwardAmount = (_b = (_a = params.offer.itemOffered) === null || _a === void 0 ? void 0 : _a.pointAward) === null || _b === void 0 ? void 0 : _b.amount; const pointAwardDescription = (_d = (_c = params.offer.itemOffered) === null || _c === void 0 ? void 0 : _c.pointAward) === null || _d === void 0 ? void 0 : _d.description; const pointAwardToLocationIdentifier = (_g = (_f = (_e = params.acceptedOffer.itemOffered) === null || _e === void 0 ? void 0 : _e.pointAward) === null || _f === void 0 ? void 0 : _f.toLocation) === null || _g === void 0 ? void 0 : _g.identifier; const pointAwardToLocationIssuedThroughId = (_k = (_j = (_h = params.acceptedOffer.itemOffered) === null || _h === void 0 ? void 0 : _h.pointAward) === null || _j === void 0 ? void 0 : _j.toLocation) === null || _k === void 0 ? void 0 : _k.issuedThrough.id; const pointAwardRecipient = (_m = (_l = params.acceptedOffer.itemOffered) === null || _l === void 0 ? void 0 : _l.pointAward) === null || _m === void 0 ? void 0 : _m.recipient; // const pointAwardPurposeIdentifier = params.acceptedOffer.itemOffered?.pointAward?.purpose?.identifier; // オファーのpointAward設定が適切にされていれば、指定されたtoLocationを反映する if (typeof (pointAwardAmount === null || pointAwardAmount === void 0 ? void 0 : pointAwardAmount.value) === 'number' && typeof (pointAwardAmount === null || pointAwardAmount === void 0 ? void 0 : pointAwardAmount.currency) === 'string' && typeof pointAwardToLocationIdentifier === 'string' && typeof pointAwardToLocationIssuedThroughId === 'string') { // ここで識別子を作成する(入金のユニークネスが保証される) const purposeIdentifier = (0, accountTransactionIdentifier_1.createPointAwardPurposeIdentifier4reservation)({ assetTransaction: { typeOf: factory.assetTransactionType.Reserve }, project: { id: params.project.id }, reservation: { id: params.reservation.id }, toLocation: { identifier: pointAwardToLocationIdentifier } }); pointAward = Object.assign(Object.assign({ amount: pointAwardAmount, purpose: { identifier: purposeIdentifier }, toLocation: { typeOf: factory.permit.PermitType.Permit, identifier: pointAwardToLocationIdentifier, issuedThrough: { id: pointAwardToLocationIssuedThroughId } }, typeOf: factory.actionType.MoneyTransfer }, (typeof pointAwardDescription === 'string') ? { description: pointAwardDescription } : undefined), (pointAwardRecipient !== undefined) ? { recipient: pointAwardRecipient } : undefined // ...(typeof pointAwardPurposeIdentifier === 'string') ? { purpose: { identifier: pointAwardPurposeIdentifier } } : undefined ); } return pointAward; }