UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

1,002 lines (1,001 loc) 55.9 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.ReservationRepo = void 0; const reservation_1 = require("./mongoose/schemas/reservation"); const factory = require("../factory"); const settings_1 = require("../settings"); /** * 予約リポジトリ */ class ReservationRepo { constructor(connection) { this.reservationModel = connection.model(reservation_1.modelName, (0, reservation_1.createSchema)()); } // tslint:disable-next-line:cyclomatic-complexity max-func-body-length static CREATE_MONGO_CONDITIONS(params) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21; // MongoDB検索条件 const andConditions = [ { typeOf: { $eq: params.typeOf } } ]; const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq; if (typeof projectIdEq === 'string') { andConditions.push({ 'project.id': { $eq: projectIdEq } }); } const providerIdEq = (_d = (_c = params.provider) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.$eq; if (typeof providerIdEq === 'string') { andConditions.push({ 'provider.id': { $eq: providerIdEq } }); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (Array.isArray(params.ids)) { andConditions.push({ _id: { $in: params.ids } }); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (params.id !== undefined && params.id !== null) { if (typeof params.id.$eq === 'string') { andConditions.push({ _id: { $eq: params.id.$eq } }); } if (typeof params.id.$ne === 'string') { andConditions.push({ _id: { $ne: params.id.$ne } }); } if (Array.isArray(params.id.$in)) { andConditions.push({ _id: { $in: params.id.$in } }); } if (Array.isArray(params.id.$nin)) { andConditions.push({ _id: { $nin: params.id.$nin } }); } } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (Array.isArray(params.reservationNumbers)) { andConditions.push({ reservationNumber: { $in: params.reservationNumbers } }); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (params.reservationNumber !== undefined && params.reservationNumber !== null) { if (typeof params.reservationNumber === 'string') { if (params.reservationNumber.length > 0) { andConditions.push({ reservationNumber: { $regex: new RegExp(params.reservationNumber) } }); } } else { if (typeof params.reservationNumber.$eq === 'string') { andConditions.push({ reservationNumber: { $eq: params.reservationNumber.$eq } }); } if (typeof params.reservationNumber.$ne === 'string') { andConditions.push({ reservationNumber: { $ne: params.reservationNumber.$ne } }); } if (Array.isArray(params.reservationNumber.$in)) { andConditions.push({ reservationNumber: { $in: params.reservationNumber.$in } }); } if (Array.isArray(params.reservationNumber.$nin)) { andConditions.push({ reservationNumber: { $nin: params.reservationNumber.$nin } }); } } } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (params.additionalTicketText !== undefined && params.additionalTicketText !== null) { if (typeof params.additionalTicketText === 'string') { if (params.additionalTicketText.length > 0) { andConditions.push({ additionalTicketText: { $exists: true, $regex: new RegExp(params.additionalTicketText) } }); } } else { if (typeof params.additionalTicketText.$eq === 'string') { andConditions.push({ additionalTicketText: { $exists: true, $eq: params.additionalTicketText.$eq } }); } if (typeof params.additionalTicketText.$ne === 'string') { andConditions.push({ additionalTicketText: { $ne: params.additionalTicketText.$ne } }); } if (Array.isArray(params.additionalTicketText.$in)) { andConditions.push({ additionalTicketText: { $exists: true, $in: params.additionalTicketText.$in } }); } if (Array.isArray(params.additionalTicketText.$nin)) { andConditions.push({ additionalTicketText: { $nin: params.additionalTicketText.$nin } }); } const additionalTicketTextRegex = (_e = params.additionalTicketText) === null || _e === void 0 ? void 0 : _e.$regex; if (typeof additionalTicketTextRegex === 'string' && additionalTicketTextRegex.length > 0) { const additionalTicketTextOptions = (_f = params.additionalTicketText) === null || _f === void 0 ? void 0 : _f.$options; andConditions.push({ additionalTicketText: Object.assign({ $exists: true, $regex: new RegExp(additionalTicketTextRegex) }, (typeof additionalTicketTextOptions === 'string') ? { $options: additionalTicketTextOptions } : undefined) }); } } } const reservationStatusEq = (_g = params.reservationStatus) === null || _g === void 0 ? void 0 : _g.$eq; if (typeof reservationStatusEq === 'string') { andConditions.push({ reservationStatus: { $eq: reservationStatusEq } }); } const reservationStatusNe = (_h = params.reservationStatus) === null || _h === void 0 ? void 0 : _h.$ne; if (typeof reservationStatusNe === 'string') { andConditions.push({ reservationStatus: { $ne: reservationStatusNe } }); } const reservationStatusIn = (_j = params.reservationStatus) === null || _j === void 0 ? void 0 : _j.$in; if (Array.isArray(reservationStatusIn)) { andConditions.push({ reservationStatus: { $in: reservationStatusIn } }); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (Array.isArray(params.reservationStatuses)) { andConditions.push({ reservationStatus: { $in: params.reservationStatuses } }); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (params.modifiedFrom instanceof Date) { andConditions.push({ modifiedTime: { $gte: params.modifiedFrom } }); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (params.modifiedThrough instanceof Date) { andConditions.push({ modifiedTime: { $lte: params.modifiedThrough } }); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (params.bookingFrom instanceof Date) { andConditions.push({ bookingTime: { $exists: true, $gte: params.bookingFrom } }); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (params.bookingThrough instanceof Date) { andConditions.push({ bookingTime: { $exists: true, $lte: params.bookingThrough } }); } switch (params.typeOf) { case factory.reservationType.BusReservation: const reservationForTypeOfEq = (_k = params.reservationFor) === null || _k === void 0 ? void 0 : _k.typeOf; if (typeof reservationForTypeOfEq === 'string') { andConditions.push({ 'reservationFor.typeOf': { $exists: true, $eq: reservationForTypeOfEq } }); } const reservationForIdEq = (_m = (_l = params.reservationFor) === null || _l === void 0 ? void 0 : _l.id) === null || _m === void 0 ? void 0 : _m.$eq; if (typeof reservationForIdEq === 'string') { andConditions.push({ 'reservationFor.id': { $exists: true, $eq: reservationForIdEq } }); } const reservationForIdIn = (_p = (_o = params.reservationFor) === null || _o === void 0 ? void 0 : _o.id) === null || _p === void 0 ? void 0 : _p.$in; if (Array.isArray(reservationForIdIn)) { andConditions.push({ 'reservationFor.id': { $exists: true, $in: reservationForIdIn } }); } break; case factory.reservationType.EventReservation: if (typeof ((_q = params.reservationFor) === null || _q === void 0 ? void 0 : _q.id) === 'string') { andConditions.push({ 'reservationFor.id': { $exists: true, $eq: params.reservationFor.id } }); } else { const reservationForIdEq4eventReservation = (_s = (_r = params.reservationFor) === null || _r === void 0 ? void 0 : _r.id) === null || _s === void 0 ? void 0 : _s.$eq; if (typeof reservationForIdEq4eventReservation === 'string') { andConditions.push({ 'reservationFor.id': { $exists: true, $eq: reservationForIdEq4eventReservation } }); } } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (params.reservationFor !== undefined) { // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (params.reservationFor.typeOf !== undefined) { andConditions.push({ 'reservationFor.typeOf': { $exists: true, $eq: params.reservationFor.typeOf } }); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (Array.isArray(params.reservationFor.ids)) { andConditions.push({ 'reservationFor.id': { $exists: true, $in: params.reservationFor.ids } }); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (params.reservationFor.location !== undefined) { // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (Array.isArray(params.reservationFor.location.ids)) { andConditions.push({ 'reservationFor.location.id': { $exists: true, $in: params.reservationFor.location.ids } }); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (Array.isArray(params.reservationFor.location.branchCodes)) { andConditions.push({ 'reservationFor.location.branchCode': { $exists: true, $in: params.reservationFor.location.branchCodes } }); } } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (params.reservationFor.startFrom instanceof Date) { andConditions.push({ 'reservationFor.startDate': { $exists: true, $gte: params.reservationFor.startFrom } }); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (params.reservationFor.startThrough instanceof Date) { andConditions.push({ 'reservationFor.startDate': { $exists: true, $lte: params.reservationFor.startThrough } }); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (params.reservationFor.endFrom instanceof Date) { andConditions.push({ 'reservationFor.endDate': { $exists: true, $gte: params.reservationFor.endFrom } }); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (params.reservationFor.endThrough instanceof Date) { andConditions.push({ 'reservationFor.endDate': { $exists: true, $lte: params.reservationFor.endThrough } }); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (params.reservationFor.superEvent !== undefined) { // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (params.reservationFor.superEvent.id !== undefined) { andConditions.push({ 'reservationFor.superEvent.id': { $exists: true, $eq: params.reservationFor.superEvent.id } }); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (Array.isArray(params.reservationFor.superEvent.ids)) { andConditions.push({ 'reservationFor.superEvent.id': { $exists: true, $in: params.reservationFor.superEvent.ids } }); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (params.reservationFor.superEvent.location !== undefined) { // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (Array.isArray(params.reservationFor.superEvent.location.ids)) { andConditions.push({ 'reservationFor.superEvent.location.id': { $exists: true, $in: params.reservationFor.superEvent.location.ids } }); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (Array.isArray(params.reservationFor.superEvent.location.branchCodes)) { andConditions.push({ 'reservationFor.superEvent.location.branchCode': { $exists: true, $in: params.reservationFor.superEvent.location.branchCodes } }); } } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (params.reservationFor.superEvent.workPerformed !== undefined) { // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (Array.isArray(params.reservationFor.superEvent.workPerformed.ids)) { andConditions.push({ 'reservationFor.superEvent.workPerformed.id': { $exists: true, $in: params.reservationFor.superEvent.workPerformed.ids } }); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (Array.isArray(params.reservationFor.superEvent.workPerformed.identifiers)) { andConditions.push({ 'reservationFor.superEvent.workPerformed.identifier': { $exists: true, $in: params.reservationFor.superEvent.workPerformed.identifiers } }); } } } } break; case factory.reservationType.ReservationPackage: break; default: } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (params.reservedTicket !== undefined) { // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (params.reservedTicket.ticketType !== undefined) { // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (Array.isArray(params.reservedTicket.ticketType.ids)) { andConditions.push({ 'reservedTicket.ticketType.id': { $exists: true, $in: params.reservedTicket.ticketType.ids } }); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (params.reservedTicket.ticketType.category !== undefined) { // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (Array.isArray(params.reservedTicket.ticketType.category.ids)) { andConditions.push({ 'reservedTicket.ticketType.category.id': { $exists: true, $in: params.reservedTicket.ticketType.category.ids } }); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (params.reservedTicket.ticketType.category.codeValue !== undefined && params.reservedTicket.ticketType.category !== null) { if (Array.isArray(params.reservedTicket.ticketType.category.codeValue.$in)) { andConditions.push({ 'reservedTicket.ticketType.category.codeValue': { $exists: true, $in: params.reservedTicket.ticketType.category.codeValue.$in } }); } } } } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (params.reservedTicket.ticketedSeat !== undefined) { // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (Array.isArray(params.reservedTicket.ticketedSeat.seatNumbers)) { andConditions.push({ 'reservedTicket.ticketedSeat.seatNumber': { $exists: true, $in: params.reservedTicket.ticketedSeat.seatNumbers } }); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (Array.isArray(params.reservedTicket.ticketedSeat.seatRows)) { andConditions.push({ 'reservedTicket.ticketedSeat.seatRow': { $exists: true, $in: params.reservedTicket.ticketedSeat.seatRows } }); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (Array.isArray(params.reservedTicket.ticketedSeat.seatSections)) { andConditions.push({ 'reservedTicket.ticketedSeat.seatSection': { $exists: true, $in: params.reservedTicket.ticketedSeat.seatSections } }); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ const ticketedSeatSeatingTypeIn = (_u = (_t = params.reservedTicket.ticketedSeat) === null || _t === void 0 ? void 0 : _t.seatingType) === null || _u === void 0 ? void 0 : _u.$in; if (Array.isArray(ticketedSeatSeatingTypeIn)) { andConditions.push({ 'reservedTicket.ticketedSeat.seatingType': { $exists: true, $in: ticketedSeatSeatingTypeIn } }); } } } const brokerIdRegex = (_v = params.broker) === null || _v === void 0 ? void 0 : _v.id; if (typeof brokerIdRegex === 'string' && brokerIdRegex.length > 0) { andConditions.push({ 'broker.id': { $exists: true, $regex: new RegExp(brokerIdRegex) } }); } const brokerIdentifierAll = (_x = (_w = params.broker) === null || _w === void 0 ? void 0 : _w.identifier) === null || _x === void 0 ? void 0 : _x.$all; if (Array.isArray(brokerIdentifierAll)) { andConditions.push({ 'broker.identifier': { $exists: true, $all: brokerIdentifierAll } }); } const brokerIdentifierIn = (_z = (_y = params.broker) === null || _y === void 0 ? void 0 : _y.identifier) === null || _z === void 0 ? void 0 : _z.$in; if (Array.isArray(brokerIdentifierIn)) { andConditions.push({ 'broker.identifier': { $exists: true, $in: brokerIdentifierIn } }); } const brokerIdentifierNin = (_1 = (_0 = params.broker) === null || _0 === void 0 ? void 0 : _0.identifier) === null || _1 === void 0 ? void 0 : _1.$nin; if (Array.isArray(brokerIdentifierNin)) { andConditions.push({ 'broker.identifier': { $nin: brokerIdentifierNin } }); } const brokerIdentifierElemMatch = (_3 = (_2 = params.broker) === null || _2 === void 0 ? void 0 : _2.identifier) === null || _3 === void 0 ? void 0 : _3.$elemMatch; if (brokerIdentifierElemMatch !== undefined && brokerIdentifierElemMatch !== null) { andConditions.push({ 'broker.identifier': { $exists: true, $elemMatch: brokerIdentifierElemMatch } }); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (params.underName !== undefined) { // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (typeof params.underName.id === 'string' && params.underName.id.length > 0) { andConditions.push({ 'underName.id': { $exists: true, $regex: new RegExp(params.underName.id) } }); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (typeof params.underName.email === 'string') { if (params.underName.email.length > 0) { andConditions.push({ 'underName.email': { $exists: true, $regex: new RegExp(params.underName.email) } }); } } else { const emailRegex = (_4 = params.underName.email) === null || _4 === void 0 ? void 0 : _4.$regex; if (typeof emailRegex === 'string' && emailRegex.length > 0) { const emailOptions = (_5 = params.underName.email) === null || _5 === void 0 ? void 0 : _5.$options; andConditions.push({ 'underName.email': Object.assign({ $exists: true, $regex: new RegExp(emailRegex) }, (typeof emailOptions === 'string') ? { $options: emailOptions } : undefined) }); } } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (typeof params.underName.name === 'string') { if (params.underName.name.length > 0) { andConditions.push({ 'underName.name': { $exists: true, $regex: new RegExp(params.underName.name) } }); } } else { const underNameNameRegex = (_6 = params.underName.name) === null || _6 === void 0 ? void 0 : _6.$regex; if (typeof underNameNameRegex === 'string' && underNameNameRegex.length > 0) { const underNameNameOptions = (_7 = params.underName.name) === null || _7 === void 0 ? void 0 : _7.$options; andConditions.push({ 'underName.name': Object.assign({ $exists: true, $regex: new RegExp(underNameNameRegex) }, (typeof underNameNameOptions === 'string') ? { $options: underNameNameOptions } : undefined) }); } } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (typeof params.underName.telephone === 'string' && params.underName.telephone.length > 0) { andConditions.push({ 'underName.telephone': { $exists: true, $regex: new RegExp(params.underName.telephone) } }); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (typeof params.underName.givenName === 'string') { if (params.underName.givenName.length > 0) { andConditions.push({ 'underName.givenName': { $exists: true, $regex: new RegExp(params.underName.givenName) } }); } } else { const givenNameRegex = (_8 = params.underName.givenName) === null || _8 === void 0 ? void 0 : _8.$regex; if (typeof givenNameRegex === 'string' && givenNameRegex.length > 0) { const givenNameOptions = (_9 = params.underName.givenName) === null || _9 === void 0 ? void 0 : _9.$options; andConditions.push({ 'underName.givenName': Object.assign({ $exists: true, $regex: new RegExp(givenNameRegex) }, (typeof givenNameOptions === 'string') ? { $options: givenNameOptions } : undefined) }); } } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (typeof params.underName.familyName === 'string') { if (params.underName.familyName.length > 0) { andConditions.push({ 'underName.familyName': { $exists: true, $regex: new RegExp(params.underName.familyName) } }); } } else { const familyNameRegex = (_10 = params.underName.familyName) === null || _10 === void 0 ? void 0 : _10.$regex; if (typeof familyNameRegex === 'string' && familyNameRegex.length > 0) { const familyNameOptions = (_11 = params.underName.familyName) === null || _11 === void 0 ? void 0 : _11.$options; andConditions.push({ 'underName.familyName': Object.assign({ $exists: true, $regex: new RegExp(familyNameRegex) }, (typeof familyNameOptions === 'string') ? { $options: familyNameOptions } : undefined) }); } } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (params.underName.identifier !== undefined) { if (Array.isArray(params.underName.identifier.$all)) { andConditions.push({ 'underName.identifier': { $exists: true, $all: params.underName.identifier.$all } }); } if (Array.isArray(params.underName.identifier.$in)) { andConditions.push({ 'underName.identifier': { $exists: true, $in: params.underName.identifier.$in } }); } if (Array.isArray(params.underName.identifier.$nin)) { andConditions.push({ 'underName.identifier': { $nin: params.underName.identifier.$nin } }); } if (params.underName.identifier.$elemMatch !== undefined) { andConditions.push({ 'underName.identifier': { $exists: true, $elemMatch: params.underName.identifier.$elemMatch } }); } } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (Array.isArray(params.underName.identifiers)) { andConditions.push({ 'underName.identifier': { $exists: true, $in: params.underName.identifiers } }); } } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (typeof params.attended === 'boolean') { andConditions.push({ attended: params.attended }); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (typeof params.checkedIn === 'boolean') { andConditions.push({ checkedIn: params.checkedIn }); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (params.additionalProperty !== undefined) { if (Array.isArray(params.additionalProperty.$all)) { andConditions.push({ additionalProperty: { $exists: true, $all: params.additionalProperty.$all } }); } if (Array.isArray(params.additionalProperty.$in)) { andConditions.push({ additionalProperty: { $exists: true, $in: params.additionalProperty.$in } }); } if (Array.isArray(params.additionalProperty.$nin)) { andConditions.push({ additionalProperty: { $nin: params.additionalProperty.$nin } }); } if (params.additionalProperty.$elemMatch !== undefined) { andConditions.push({ additionalProperty: { $exists: true, $elemMatch: params.additionalProperty.$elemMatch } }); } } const programMembershipUsedIdentifierEq = (_13 = (_12 = params.programMembershipUsed) === null || _12 === void 0 ? void 0 : _12.identifier) === null || _13 === void 0 ? void 0 : _13.$eq; if (typeof programMembershipUsedIdentifierEq === 'string') { andConditions.push({ 'programMembershipUsed.identifier': { $exists: true, $eq: programMembershipUsedIdentifierEq } }); } const programMembershipUsedIssuedThroughServiceTypeCodeValueEq = (_17 = (_16 = (_15 = (_14 = params.programMembershipUsed) === null || _14 === void 0 ? void 0 : _14.issuedThrough) === null || _15 === void 0 ? void 0 : _15.serviceType) === null || _16 === void 0 ? void 0 : _16.codeValue) === null || _17 === void 0 ? void 0 : _17.$eq; if (typeof programMembershipUsedIssuedThroughServiceTypeCodeValueEq === 'string') { andConditions.push({ 'programMembershipUsed.issuedThrough.serviceType.codeValue': { $exists: true, $eq: programMembershipUsedIssuedThroughServiceTypeCodeValueEq } }); } const appliesToMovieTicketIdentifierEq = (_21 = (_20 = (_19 = (_18 = params.price) === null || _18 === void 0 ? void 0 : _18.priceComponent) === null || _19 === void 0 ? void 0 : _19.appliesToMovieTicket) === null || _20 === void 0 ? void 0 : _20.identifier) === null || _21 === void 0 ? void 0 : _21.$eq; if (typeof appliesToMovieTicketIdentifierEq === 'string') { andConditions.push({ 'price.priceComponent.appliesToMovieTicket.identifier': { $exists: true, $eq: appliesToMovieTicketIdentifierEq } }); } return andConditions; } /** * 汎用予約カウント */ count(params) { return __awaiter(this, void 0, void 0, function* () { const conditions = ReservationRepo.CREATE_MONGO_CONDITIONS(params); return this.reservationModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {}) .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS }) .exec(); }); } /** * 予約検索 * migrate from search(2024-08-08~) */ projectFields(params, inclusion) { return __awaiter(this, void 0, void 0, function* () { var _a; const conditions = ReservationRepo.CREATE_MONGO_CONDITIONS(params); let projection = {}; if (inclusion !== undefined && inclusion !== null) { projection = { _id: 0, // hide _id(2024-08-08~) id: { $toString: '$_id' } }; for (const [field, value] of Object.entries(inclusion)) { // 厳密に1を指定されたフィールドのみprojectionに追加 if (value === 1 && field !== '_id' && field !== 'id') { projection[field] = 1; } } } else { projection = { _id: 0, // hide _id(2024-08-08~) id: { $toString: '$_id' }, project: 1, provider: 1, typeOf: 1, additionalTicketText: 1, bookingTime: 1, broker: 1, modifiedTime: 1, numSeats: 1, previousReservationStatus: 1, price: 1, priceCurrency: 1, programMembershipUsed: 1, reservationFor: 1, reservationNumber: 1, reservationStatus: 1, reservedTicket: 1, subReservation: 1, underName: 1, checkedIn: 1, attended: 1, additionalProperty: 1, issuedThrough: 1 }; } const query = this.reservationModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection); if (typeof params.limit === 'number' && params.limit > 0) { const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1; query.limit(params.limit) .skip(params.limit * (page - 1)); } // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore else */ if (((_a = params.sort) === null || _a === void 0 ? void 0 : _a.bookingTime) !== undefined) { query.sort({ bookingTime: params.sort.bookingTime }); } return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS }) .lean() .exec(); }); } projectFieldsById(params) { return __awaiter(this, void 0, void 0, function* () { let projection = {}; if (Array.isArray(params.inclusion) && params.inclusion.length > 0) { projection = { _id: 0, // hide _id(2024-08-08~) id: { $toString: '$_id' } }; params.inclusion.forEach((field) => { if (String(field) !== '_id' && field !== 'id') { projection[field] = 1; } }); } else { // discontinue(2024-08-08~) throw new factory.errors.ArgumentNull('inclusion', 'inclusion must be specified'); } const doc = yield this.reservationModel.findById(params.id, projection) .lean() // 2024-08-08~ .exec(); if (doc === null) { throw new factory.errors.NotFound(this.reservationModel.modelName); } return doc; }); } confirmManyIfNotExist(params) { return __awaiter(this, void 0, void 0, function* () { const modifiedTime = new Date(); const bulkWriteOps = []; if (Array.isArray(params.subReservation)) { params.subReservation.forEach((subReservation) => { var _a, _b; let setOnInsert; switch (subReservation.typeOf) { case factory.reservationType.BusReservation: setOnInsert = Object.assign(Object.assign(Object.assign(Object.assign({}, subReservation), { _id: subReservation.id, bookingTime: params.bookingTime, checkedIn: false, attended: false, issuedThrough: params.issuedThrough, project: { id: params.project.id, typeOf: factory.organizationType.Project }, reservationFor: params.reservationFor, reservationNumber: params.reservationNumber, reservationStatus: factory.reservationStatusType.ReservationConfirmed, modifiedTime, // providerを追加(2023-07-19~) provider: params.provider }), (params.underName !== undefined) ? { underName: params.underName } : undefined), (typeof ((_a = params.broker) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') ? { broker: params.broker } : undefined); break; case factory.reservationType.EventReservation: setOnInsert = Object.assign(Object.assign(Object.assign(Object.assign({}, subReservation), { _id: subReservation.id, bookingTime: params.bookingTime, checkedIn: false, attended: false, issuedThrough: params.issuedThrough, project: { id: params.project.id, typeOf: factory.organizationType.Project }, reservationFor: params.reservationFor, reservationNumber: params.reservationNumber, reservationStatus: factory.reservationStatusType.ReservationConfirmed, modifiedTime, // providerを追加(2023-07-19~) provider: params.provider }), (params.underName !== undefined) ? { underName: params.underName } : undefined), (typeof ((_b = params.broker) === null || _b === void 0 ? void 0 : _b.typeOf) === 'string') ? { broker: params.broker } : undefined); break; default: throw new factory.errors.NotImplemented(`${subReservation.typeOf} not implemented`); } bulkWriteOps.push({ updateOne: { filter: { _id: { $eq: subReservation.id } }, update: { $setOnInsert: setOnInsert }, upsert: true } }); }); } if (bulkWriteOps.length > 0) { return this.reservationModel.bulkWrite(bulkWriteOps, { ordered: false }); } }); } /** * 予約取消 */ cancelById(params) { return __awaiter(this, void 0, void 0, function* () { const conditions = Object.assign({ _id: { $eq: String(params.id) } }, (typeof params.previousReservationStatus === 'string') ? { reservationStatus: { $eq: params.previousReservationStatus } } : undefined); const update = { $set: Object.assign({ reservationStatus: factory.reservationStatusType.ReservationCancelled, modifiedTime: params.modifiedTime }, (typeof params.previousReservationStatus === 'string') ? { previousReservationStatus: params.previousReservationStatus } : undefined) }; const doc = yield this.reservationModel.findOneAndUpdate(conditions, update, { new: true, projection: { _id: 1 } }) .lean() // 2024-08-07~ // .select({ __v: 0, createdAt: 0, updatedAt: 0 }) .exec(); // NotFoundであれば状態確認 if (doc === null) { const { reservationStatus } = yield this.projectFieldsById({ id: String(params.id), inclusion: ['reservationStatus'] }); if (reservationStatus === factory.reservationStatusType.ReservationCancelled) { // すでに取消済の場合 return; // return reservation; } else { throw new factory.errors.Argument('id', `Reservation ${params.id} already changed -> ${reservationStatus}`); } } }); } /** * 予約取消 */ cancelByReservationNumber(params) { return __awaiter(this, void 0, void 0, function* () { const conditions = Object.assign({ reservationNumber: { $eq: String(params.reservationNumber) } }, (typeof params.previousReservationStatus === 'string') ? { reservationStatus: { $eq: params.previousReservationStatus } } : undefined); const update = { $set: Object.assign({ reservationStatus: factory.reservationStatusType.ReservationCancelled, modifiedTime: params.modifiedTime }, (typeof params.previousReservationStatus === 'string') ? { previousReservationStatus: params.previousReservationStatus } : undefined) }; return this.reservationModel.updateMany(conditions, update) .exec(); }); } /** * 発券する */ checkInIfNot(params) { return __awaiter(this, void 0, void 0, function* () { var _a, _b; const { now } = params; if (!(now instanceof Date)) { throw new factory.errors.Argument('now', 'must be Date'); } const conditions = []; if (typeof params.id === 'string') { if (params.id.length > 0) { conditions.push({ _id: { $eq: params.id } }); } } else { const idIn = (_a = params.id) === null || _a === void 0 ? void 0 : _a.$in;