UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

49 lines (48 loc) 2.34 kB
"use strict"; 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.checkAvailability = checkAvailability; const moment = require("moment-timezone"); const factory = require("../../../factory"); function checkAvailability(params) { return (repos) => __awaiter(this, void 0, void 0, function* () { var _a, _b; const unitPriceOffer = params.unitPriceOffer; let availability; // レート制限を確認 const scope = (_a = unitPriceOffer.validRateLimit) === null || _a === void 0 ? void 0 : _a.scope; const unitInSeconds = (_b = unitPriceOffer.validRateLimit) === null || _b === void 0 ? void 0 : _b.unitInSeconds; if (typeof scope === 'string' && typeof unitInSeconds === 'number') { const rateLimitKey = { project: { id: params.event.project.id }, reservedTicket: { ticketType: { validRateLimit: { scope: scope, unitInSeconds: unitInSeconds } } }, reservationFor: { startDate: moment(params.event.startDate) .toDate() }, reservationNumber: '' }; const holder = yield repos.offerRateLimit.getHolder(rateLimitKey); // ロックされていればOutOfStock if (typeof holder === 'string' && holder.length > 0) { availability = factory.itemAvailability.OutOfStock; } } return availability; }); }