UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

350 lines (287 loc) 13.7 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>Chevre Domain Library for Node.js Source: service/aggregation.js</title> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/sunlight.default.css"> <link type="text/css" rel="stylesheet" href="styles/site.cosmo.css"> </head> <body> <div class="navbar navbar-default navbar-fixed-top navbar-inverse"> <div class="container"> <div class="navbar-header"> <a class="navbar-brand" href="index.html">Chevre Domain Library for Node.js</a> <button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#topNavigation"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> </div> <div class="navbar-collapse collapse" id="topNavigation"> <ul class="nav navbar-nav"> <li class="dropdown"> <a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b class="caret"></b></a> <ul class="dropdown-menu "> <li><a href="MongoRepository.html">MongoRepository</a></li><li><a href="RedisRepository.html">RedisRepository</a></li><li><a href="Repository.html">Repository</a></li> </ul> </li> <li class="dropdown"> <a href="global.html" class="dropdown-toggle" data-toggle="dropdown">Global<b class="caret"></b></a> <ul class="dropdown-menu "> <li><a href="global.html#abort">abort</a></li><li><a href="global.html#accountTitle_1">accountTitle_1</a></li><li><a href="global.html#aggregateScreeningEvent">aggregateScreeningEvent</a></li><li><a href="global.html#AggregationService">AggregationService</a></li><li><a href="global.html#call">call</a></li><li><a href="global.html#cancel">cancel</a></li><li><a href="global.html#cancelPendingReservation">cancelPendingReservation</a></li><li><a href="global.html#cancelReservation">cancelReservation</a></li><li><a href="global.html#confirm">confirm</a></li><li><a href="global.html#confirmReservation">confirmReservation</a></li><li><a href="global.html#createDebug">createDebug</a></li><li><a href="global.html#default">default</a></li><li><a href="global.html#execute">execute</a></li><li><a href="global.html#executeByName">executeByName</a></li><li><a href="global.html#exportTasks">exportTasks</a></li><li><a href="global.html#exportTasksById">exportTasksById</a></li><li><a href="global.html#mongoose">mongoose</a></li><li><a href="global.html#redis">redis</a></li><li><a href="global.html#retry">retry</a></li><li><a href="global.html#schema">schema</a></li><li><a href="global.html#searchScreeningEventTicketOffers">searchScreeningEventTicketOffers</a></li><li><a href="global.html#sortOrder4executionOfTasks">sortOrder4executionOfTasks</a></li><li><a href="global.html#start">start</a></li> </ul> </li> </ul> <div class="col-sm-3 col-md-3"> <form class="navbar-form" role="search"> <div class="input-group"> <input type="text" class="form-control" placeholder="Search" name="q" id="search-input"> <div class="input-group-btn"> <button class="btn btn-default" id="search-submit"><i class="glyphicon glyphicon-search"></i></button> </div> </div> </form> </div> </div> </div> </div> <div class="container" id="toc-content"> <div class="row"> <div class="col-md-12"> <div id="main"> <h1 class="page-title">Source: service/aggregation.js</h1> <section> <article> <pre class="sunlight-highlight-javascript linenums">"use strict"; var __awaiter = (this &amp;&amp; this.__awaiter) || function (thisArg, _arguments, P, generator) { 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); /** * 集計サービス */ const createDebug = require("debug"); const factory = require("../factory"); const debug = createDebug('chevre-domain:service'); /** * 上映イベントデータを期間指定で集計する */ // export function aggregateScreeningEvents(params: { // startFrom: Date; // startThrough: Date; // ttl: number; // }): IAggregateScreeningEventOperation&lt;void> { // return async (repos: { // aggregation: ScreeningEventAggregationRepo; // screeningEventAvailability: ScreeningEventAvailabilityRepo; // event: EventRepo; // place: PlaceRepo; // }) => { // // 集計対象イベント検索 // const events = await repos.event.searchScreeningEvents({ // startFrom: params.startFrom, // startThrough: params.startThrough // }); // // イベントの座席情報検索 // const movieTheatersWithoutScreeningRoom = await repos.place.searchMovieTheaters({}); // const movieTheaters = await Promise.all(movieTheatersWithoutScreeningRoom.map(async (m) => { // return repos.place.findMovieTheaterByBranchCode(m.branchCode); // })); // // 収容人数を集計 // const aggregations: IScreeningEventAggregation[] = await Promise.all(events.map(async (e) => { // let maximumAttendeeCapacity: number = 0; // let remainingAttendeeCapacity: number = 0; // const movieTheater = movieTheaters.find((m) => m.branchCode === e.superEvent.location.branchCode); // if (movieTheater === undefined) { // // 基本的にありえないはずだが、万が一劇場が見つからなければcapacityは0のまま // console.error(new Error('Movie theater not found')); // } else { // const screeningRoom = &lt;factory.place.movieTheater.IScreeningRoom | undefined> // movieTheater.containsPlace.find((p) => p.branchCode === e.location.branchCode); // if (screeningRoom === undefined) { // // 基本的にありえないはずだが、万が一スクリーンが見つからなければcapacityは0のまま // console.error(new Error('Screening room not found')); // } else { // maximumAttendeeCapacity = screeningRoom.containsPlace.reduce((a, b) => a + b.containsPlace.length, 0); // const unavailableOffers = await repos.screeningEventAvailability.findUnavailableOffersByEventId({ eventId: e.id }); // remainingAttendeeCapacity = maximumAttendeeCapacity - unavailableOffers.length; // } // } // return { // id: e.id, // maximumAttendeeCapacity: maximumAttendeeCapacity, // remainingAttendeeCapacity: remainingAttendeeCapacity // }; // })); // // 保管 // await repos.aggregation.store(aggregations, params.ttl); // }; // } /** * 上映イベントデータをID指定で集計する */ function aggregateScreeningEvent(params) { return (repos) => __awaiter(this, void 0, void 0, function* () { // 集計対象イベント検索 const event = yield repos.event.findById(params); // 全予約検索 const limit = 100; let page = 0; let numData = limit; const confirmedReservations = []; while (numData === limit) { page += 1; const reservations = yield repos.reservation.searchScreeningEventReservations({ limit: limit, page: page, reservationFor: { typeOf: factory.eventType.ScreeningEvent, id: event.id }, reservationStatuses: [factory.reservationStatusType.ReservationConfirmed] }); numData = reservations.length; debug('numData:', numData); confirmedReservations.push(...reservations); } // イベントの座席情報検索 const movieTheatersWithoutScreeningRoom = yield repos.place.searchMovieTheaters({}); const movieTheaters = yield Promise.all(movieTheatersWithoutScreeningRoom.map((m) => __awaiter(this, void 0, void 0, function* () { return repos.place.findMovieTheaterByBranchCode({ branchCode: m.branchCode }); }))); // 収容人数を集計 let maximumAttendeeCapacity = 0; let remainingAttendeeCapacity = 0; let checkInCount = 0; let attendeeCount = 0; const movieTheater = movieTheaters.find((m) => m.branchCode === event.superEvent.location.branchCode); if (movieTheater === undefined) { // 基本的にありえないはずだが、万が一劇場が見つからなければcapacityは0のまま console.error(new Error('Movie theater not found')); } else { const screeningRoom = movieTheater.containsPlace.find((p) => p.branchCode === event.location.branchCode); if (screeningRoom === undefined) { // 基本的にありえないはずだが、万が一スクリーンが見つからなければcapacityは0のまま console.error(new Error('Screening room not found')); } else { maximumAttendeeCapacity = screeningRoom.containsPlace.reduce((a, b) => a + b.containsPlace.length, 0); remainingAttendeeCapacity = maximumAttendeeCapacity - confirmedReservations.length; checkInCount = confirmedReservations.filter((r) => r.checkedIn).length; attendeeCount = confirmedReservations.filter((r) => r.attended).length; } } const aggregation = { maximumAttendeeCapacity: maximumAttendeeCapacity, remainingAttendeeCapacity: remainingAttendeeCapacity, checkInCount: checkInCount, attendeeCount: attendeeCount }; debug('aggregation:', aggregation); // 保管 yield repos.event.eventModel.findOneAndUpdate({ typeOf: factory.eventType.ScreeningEvent, _id: event.id }, aggregation, { new: true }).exec(); }); } exports.aggregateScreeningEvent = aggregateScreeningEvent; </pre> </article> </section> </div> </div> <div class="clearfix"></div> </div> </div> <div class="modal fade" id="searchResults"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> <h4 class="modal-title">Search results</h4> </div> <div class="modal-body"></div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div><!-- /.modal-content --> </div><!-- /.modal-dialog --> </div> <footer> <span class="jsdoc-message"> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Dec 16th 2018 using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>. </span> </footer> <script src="scripts/docstrap.lib.js"></script> <script src="scripts/toc.js"></script> <script type="text/javascript" src="scripts/fulltext-search-ui.js"></script> <script> $( function () { $( "[id*='$']" ).each( function () { var $this = $( this ); $this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) ); } ); $( ".tutorial-section pre, .readme-section pre, pre.prettyprint.source" ).each( function () { var $this = $( this ); var example = $this.find( "code" ); exampleText = example.html(); var lang = /{@lang (.*?)}/.exec( exampleText ); if ( lang && lang[1] ) { exampleText = exampleText.replace( lang[0], "" ); example.html( exampleText ); lang = lang[1]; } else { var langClassMatch = example.parent()[0].className.match(/lang\-(\S+)/); lang = langClassMatch ? langClassMatch[1] : "javascript"; } if ( lang ) { $this .addClass( "sunlight-highlight-" + lang ) .addClass( "linenums" ) .html( example.html() ); } } ); Sunlight.highlightAll( { lineNumbers : true, showMenu : true, enableDoclinks : true } ); $.catchAnchorLinks( { navbarOffset: 10 } ); $( "#toc" ).toc( { anchorName : function ( i, heading, prefix ) { return $( heading ).attr( "id" ) || ( prefix + i ); }, selectors : "#toc-content h1,#toc-content h2,#toc-content h3,#toc-content h4", showAndHide : false, smoothScrolling: true } ); $( "#main span[id^='toc']" ).addClass( "toc-shim" ); $( '.dropdown-toggle' ).dropdown(); $( "table" ).each( function () { var $this = $( this ); $this.addClass('table'); } ); } ); </script> <!--Navigation and Symbol Display--> <!--Google Analytics--> <script type="text/javascript"> $(document).ready(function() { SearcherDisplay.init(); }); </script> </body> </html>