UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

355 lines (354 loc) 12.2 kB
import type { BulkWriteResult } from 'mongodb'; import type { Connection, Document, FilterQuery } from 'mongoose'; import * as factory from '../factory'; import * as EventFactory from '../factory/event'; import { IDocType } from './mongoose/schemas/event'; type AvailableEventType = factory.eventType.Event | factory.eventType.ScreeningEvent; export interface IAttributes4patchUpdate<T extends AvailableEventType> { typeOf: T; eventStatus?: factory.eventStatusType; } export interface IUpdateAggregateReservationParams { $set: { aggregateReservation: factory.event.event.IAggregateReservation; aggregateOffer?: Pick<factory.event.event.IAggregateOffer, 'aggregateDate' | 'offerCount' | 'typeOf'>; maximumAttendeeCapacity?: number; remainingAttendeeCapacity?: number; checkInCount?: number; attendeeCount?: number; }; $unset: { noExistingAttributeName: 1; maximumAttendeeCapacity?: ''; remainingAttendeeCapacity?: ''; }; } export type ISearchConditions<T extends AvailableEventType> = factory.event.ISearchConditions<T>; interface IAggregationByStatus { eventCount: number; reservationCount: number; avgOfferCount: number; maximumAttendeeCapacity: number; remainingAttendeeCapacity: number; avgRemainingCapacityRate: number; maxRemainingCapacityRate: number; minRemainingCapacityRate: number; percentilesRemainingCapacityRate: { name: string; value: number; }[]; } interface IStatus { status: factory.eventStatusType; aggregation: IAggregationByStatus; } interface IAggregateEvent { statuses: IStatus[]; } export import IMinimizedIndividualEvent = EventFactory.IMinimizedIndividualEvent; type IKeyOfProjection<T extends AvailableEventType> = Exclude<keyof factory.event.IEvent<T>, 'id'> | 'aggregateOffer' | 'superEvent.location.id' | 'offers.itemOffered' | 'offers.itemOffered.id'; type IKeyOfProjection4publicFields<T extends AvailableEventType> = Exclude<keyof factory.event.IEvent<T>, 'id' | 'offers'>; /** * minimizedEvent検索時のprojection候補 * add(2024-07-18~) */ type IKeyOfProjection4minimizedEvent<T extends AvailableEventType> = T extends factory.eventType.ScreeningEvent ? Exclude<keyof IMinimizedIndividualEvent<T>, 'additionalProperty' | 'id'> | 'superEvent.id' | 'location.branchCode' | 'superEvent.workPerformed.identifier' | 'superEvent.location.id' | 'offers.itemOffered' | 'offers.itemOffered.id' | 'offers.offeredThrough' | 'offers.unacceptedPaymentMethod' | 'offers.eligibleQuantity' : T extends factory.eventType.Event ? Exclude<keyof IMinimizedIndividualEvent<T>, 'additionalProperty' | 'id'> | 'superEvent.id' | 'location.branchCode' | 'superEvent.workPerformed.identifier' | 'superEvent.location.id' | 'offers.itemOffered' | 'offers.itemOffered.id' | 'offers.offeredThrough' | 'offers.unacceptedPaymentMethod' | 'offers.eligibleQuantity' : never; type IUnset<T extends AvailableEventType> = { [key in keyof factory.event.IEvent<T>]?: 1; }; /** * イベントリポジトリ */ export declare class EventRepo { private readonly eventModel; constructor(connection: Connection); static CREATE_MONGO_CONDITIONS<T extends AvailableEventType>(conditions: ISearchConditions<T>): FilterQuery<factory.event.IEvent<T>>[]; /** * 複数イベントを作成する */ createManyEvents<T extends AvailableEventType>(params: { attributes: factory.event.IAttributes<T>[]; expectsNoContent: boolean; }): Promise<string[] | void>; /** * 特定の追加特性をキーにして、存在しなければ作成する(複数対応) * 施設コンテンツとルームは1つに限定 * 存在すれば、特定の属性のみ更新する */ upsertManyByAdditionalProperty(params: { events: factory.event.IAttributes<factory.eventType.ScreeningEvent>[]; additionalPropertyFilter: { name: string; }; eventSeries: { /** * 施設コンテンツID */ id: string; }; screeningRoom: { /** * ルームコード */ branchCode: string; }; }, options: { /** * falseの場合setOnInsertのみ * trueの場合setのみ */ update: boolean; }): Promise<{ bulkWriteResult: BulkWriteResult; modifiedEvents: { id: string; }[]; } | void>; /** * イベント部分更新 */ updatePartiallyById<T extends AvailableEventType>(params: { project: { id: string; }; id: string; attributes: IAttributes4patchUpdate<T>; }): Promise<void>; /** * イベントを保管する */ saveEvent<T extends AvailableEventType>(params: { id?: string; attributes: factory.event.IAttributes<T>; /** * ドキュメント作成時には無視される */ $unset?: IUnset<T>; upsert: false; }): Promise<{ id: string; }>; saveManyEvents<T extends AvailableEventType>(params: { id: string; attributes: factory.event.IAttributes<T>; $unset?: IUnset<T>; upsert: boolean; }[]): Promise<void>; save4ttts(params: { oldEventId: string; attributes: factory.event.IAttributes<factory.eventType.ScreeningEvent>; }): Promise<{ id: string; }>; /** * イベントを検索する(inclusion projection) */ projectEventFields<T extends AvailableEventType>(params: ISearchConditions<T>, inclusion: IKeyOfProjection<T>[]): Promise<Omit<factory.event.IEvent<T>, 'aggregateOffer'>[]>; /** * apiで公開属性を検索する(2024-10-13~) */ aggregatePublicFields<T extends AvailableEventType>(params: ISearchConditions<T>, inclusion: IKeyOfProjection4publicFields<T>[], options: { /** * offersを属性をprojectするかどうか */ includeOffers: boolean; /** * offers.seller.makesOfferをprojectするかどうか */ includeSellerMakesOffer: boolean; /** * offers.seller.makesOfferをavailableAtOrFromでfilterする */ sellerMakesOfferAvailableAtIn?: string[]; }): Promise<Omit<factory.event.IEvent<T>, 'aggregateOffer'>[]>; /** * IDのみで検索する * projectionなし */ findAnyEventById<T extends AvailableEventType>(params: { id: { $eq: string; }; project: { id: { $eq: string; }; }; organizer?: { id: { $eq: string; }; }; }): Promise<Omit<factory.event.IEvent<T>, 'aggregateOffer'>>; searchEventIds<T extends AvailableEventType>(params: ISearchConditions<T>): Promise<string[]>; /** * 特定イベントから指定フィールドのみ取得する * イベント IDは必ず返ります */ projectEventFieldsById<T extends AvailableEventType>(params: { id: string; }, inclusion: IKeyOfProjection4minimizedEvent<T>[]): Promise<IMinimizedIndividualEvent<T>>; /** * イベントをキャンセルする */ cancelEvent(params: { project: { id: string; }; id: string; }): Promise<import("mongoose").UpdateWriteOpResult>; /** * 興行イベントのsuperEventを最新の情報に同期する */ syncScreeningEventSeries2screeningEvents(params: { project: { id: string; }; superEventFromDB: Pick<factory.event.screeningEventSeries.IEvent, 'additionalProperty' | 'alternativeHeadline' | 'description' | 'dubLanguage' | 'endDate' | 'headline' | 'id' | 'kanaName' | 'location' | 'name' | 'soundFormat' | 'startDate' | 'subtitleLanguage' | 'typeOf' | 'videoFormat' | 'workPerformed'>; startDate: { $gte: Date; }; }): Promise<void>; deleteEventById(params: { project: { id: string; }; id: string; }): Promise<void>; deleteManyEventByOrganizerId(params: { project: { id: string; }; organizer: { id: string; }; }): Promise<import("mongodb").DeleteResult>; deleteManyEventsByScreeningRoom(params: { project: { id: string; }; location: { /** * ルームコード */ branchCode: string; containedInPlace: { /** * 施設ID */ id: string; }; }; }): Promise<import("mongodb").DeleteResult>; deleteManyBySuperEventId(params: { project: { id: string; }; superEvent: { id: string; }; }): Promise<import("mongodb").DeleteResult>; deleteManyBySuperEventLocationId(params: { project: { id: string; }; superEvent: { location: { id: string; }; }; }): Promise<import("mongodb").DeleteResult>; /** * 興行(プロダクト)から削除する */ deleteManyEventsByItemOfferedId(params: { project: { id: string; }; offers: { itemOffered: { id: { $in: string[]; }; }; }; }): Promise<import("mongodb").DeleteResult>; deleteManyEventsEndedByProject(params: { typeOf: { $in: AvailableEventType[]; }; project: { id: string; }; endDate: { $lte: Date; }; }): Promise<import("mongodb").DeleteResult>; deleteManyEventsEnded(params: { typeOf: { $eq: AvailableEventType; }; endDate: { $lte: Date; }; }): Promise<import("mongodb").DeleteResult>; deleteByProject(params: { project: { id: string; }; }): Promise<void>; /** * 集計属性を更新する */ updateAggregationById(params: { id: string; }, update: IUpdateAggregateReservationParams): Promise<void>; bulkWrite(bulkWriteOps: any[]): Promise<BulkWriteResult & { mongoose?: { validationErrors: import("mongoose").Error[]; } | undefined; }>; getCursor(conditions: FilterQuery<any>, projection: any): import("mongoose").Cursor<Document<unknown, {}, IDocType> & ((import("@chevre/factory/lib/event/anyEvent").IAttributes & { _id: string; } & Required<{ _id: string; }>) | (import("@chevre/factory/lib/event/screeningEvent").IAttributes & { _id: string; aggregateOffer?: factory.event.event.IAggregateOffer; } & Required<{ _id: string; }>)), import("mongoose").QueryOptions<Document<unknown, {}, IDocType> & ((import("@chevre/factory/lib/event/anyEvent").IAttributes & { _id: string; } & Required<{ _id: string; }>) | (import("@chevre/factory/lib/event/screeningEvent").IAttributes & { _id: string; aggregateOffer?: factory.event.event.IAggregateOffer; } & Required<{ _id: string; }>))>>; addAvailableAtOrFrom(params: { id: string; offers: { seller: { makesOffer: factory.event.screeningEvent.ISellerMakesOffer; }; }; }): Promise<void>; unsetUnnecessaryFields<T extends AvailableEventType>(params: { filter: FilterQuery<factory.event.IEvent<T>>; $unset: IUnset<T>; }): Promise<import("mongoose").UpdateWriteOpResult>; aggregateEvent(params: { project?: { id?: { $ne?: string; }; }; startFrom: Date; startThrough: Date; typeOf: AvailableEventType; }): Promise<IAggregateEvent>; private agggregateByStatus; } export {};