@chevre/domain 27.1.0-alpha.2 → 27.1.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/lib/chevre/repo/adminEvent.d.ts +236 -0
  2. package/lib/chevre/repo/adminEvent.js +388 -0
  3. package/lib/chevre/repo/aggregateEvent.d.ts +42 -0
  4. package/lib/chevre/repo/aggregateEvent.js +221 -0
  5. package/lib/chevre/repo/event.d.ts +5 -263
  6. package/lib/chevre/repo/event.js +31 -664
  7. package/lib/chevre/repo/eventSeries.js +24 -24
  8. package/lib/chevre/repository.d.ts +10 -0
  9. package/lib/chevre/repository.js +24 -2
  10. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.d.ts +2 -0
  11. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +1 -1
  12. package/lib/chevre/service/aggregation/event/importFromCOA.d.ts +2 -2
  13. package/lib/chevre/service/aggregation/event/importFromCOA.js +1 -1
  14. package/lib/chevre/service/aggregation/system.d.ts +2 -2
  15. package/lib/chevre/service/aggregation/system.js +1 -1
  16. package/lib/chevre/service/event/saveScreeningEvents.d.ts +2 -2
  17. package/lib/chevre/service/event/saveScreeningEvents.js +1 -1
  18. package/lib/chevre/service/event.d.ts +2 -0
  19. package/lib/chevre/service/event.js +1 -1
  20. package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer.js +2 -3
  21. package/lib/chevre/service/offer/onEventChanged.d.ts +2 -0
  22. package/lib/chevre/service/offer/onEventChanged.js +1 -1
  23. package/lib/chevre/service/project.d.ts +3 -3
  24. package/lib/chevre/service/project.js +1 -1
  25. package/lib/chevre/service/task/aggregateScreeningEvent.js +2 -0
  26. package/lib/chevre/service/task/importEventCapacitiesFromCOA.js +2 -2
  27. package/lib/chevre/service/task/importEventsFromCOA.js +2 -0
  28. package/lib/chevre/service/task/onEventChanged.js +2 -0
  29. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByEventSeries.d.ts +2 -2
  30. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByEventSeries.js +1 -1
  31. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByMovieTheater.d.ts +2 -2
  32. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByMovieTheater.js +1 -1
  33. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByOfferCatalog.d.ts +2 -2
  34. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByOfferCatalog.js +1 -1
  35. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByProduct.d.ts +2 -2
  36. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByProduct.js +1 -1
  37. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByRoom.d.ts +2 -2
  38. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesByRoom.js +1 -1
  39. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesBySeller.d.ts +2 -2
  40. package/lib/chevre/service/task/onResourceDeleted/deleteResourcesBySeller.js +1 -1
  41. package/lib/chevre/service/task/onResourceDeleted.js +2 -2
  42. package/lib/chevre/service/task/syncResourcesFromCOA.js +2 -2
  43. package/package.json +2 -2
@@ -0,0 +1,221 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AggregateEventRepo = void 0;
4
+ const factory_1 = require("../factory");
5
+ const event_1 = require("./mongoose/schemas/event");
6
+ /**
7
+ * イベント集計リポジトリ
8
+ */
9
+ class AggregateEventRepo {
10
+ eventModel;
11
+ constructor(connection) {
12
+ this.eventModel = connection.model(event_1.modelName, (0, event_1.createSchema)());
13
+ }
14
+ async aggregateEvent(params) {
15
+ const statuses = await Promise.all([
16
+ factory_1.factory.eventStatusType.EventScheduled,
17
+ factory_1.factory.eventStatusType.EventCancelled,
18
+ factory_1.factory.eventStatusType.EventPostponed
19
+ ].map(async (eventStatus) => {
20
+ const matchConditions = {
21
+ startDate: {
22
+ $gte: params.startFrom,
23
+ $lte: params.startThrough
24
+ },
25
+ typeOf: { $eq: params.typeOf },
26
+ eventStatus: { $eq: eventStatus },
27
+ ...(typeof params.project?.id?.$ne === 'string')
28
+ ? { 'project.id': { $ne: params.project.id.$ne } }
29
+ : undefined
30
+ };
31
+ return this.agggregateByStatus({ matchConditions, status: eventStatus });
32
+ }));
33
+ return { statuses };
34
+ }
35
+ async agggregateByStatus(params) {
36
+ const matchConditions = params.matchConditions;
37
+ const eventStatus = params.status;
38
+ const aggregations = await this.eventModel.aggregate([
39
+ {
40
+ $match: matchConditions
41
+ },
42
+ {
43
+ $project: {
44
+ remainingCapacityRate: {
45
+ $cond: {
46
+ if: {
47
+ $and: [
48
+ { $isNumber: '$maximumAttendeeCapacity' },
49
+ { $isNumber: '$remainingAttendeeCapacity' }
50
+ ]
51
+ },
52
+ then: {
53
+ $cond: {
54
+ if: { $gt: ['$maximumAttendeeCapacity', 0] },
55
+ then: {
56
+ $multiply: [
57
+ { $divide: ['$remainingAttendeeCapacity', '$maximumAttendeeCapacity'] },
58
+ 100
59
+ ]
60
+ },
61
+ else: 0
62
+ }
63
+ },
64
+ else: 0
65
+ }
66
+ },
67
+ eventStatus: '$eventStatus',
68
+ startDate: '$startDate',
69
+ endDate: '$endDate',
70
+ typeOf: '$typeOf',
71
+ maximumAttendeeCapacity: {
72
+ $cond: {
73
+ if: { $isNumber: '$maximumAttendeeCapacity' },
74
+ then: '$maximumAttendeeCapacity',
75
+ else: 0
76
+ }
77
+ },
78
+ remainingAttendeeCapacity: {
79
+ $cond: {
80
+ if: { $isNumber: '$remainingAttendeeCapacity' },
81
+ then: '$remainingAttendeeCapacity',
82
+ else: 0
83
+ }
84
+ },
85
+ reservationCount: {
86
+ $cond: {
87
+ if: { $isNumber: '$aggregateReservation.reservationCount' },
88
+ then: '$aggregateReservation.reservationCount',
89
+ else: 0
90
+ }
91
+ },
92
+ offerCount: {
93
+ $cond: {
94
+ if: { $isNumber: '$aggregateOffer.offerCount' },
95
+ then: '$aggregateOffer.offerCount',
96
+ else: 0
97
+ }
98
+ }
99
+ }
100
+ },
101
+ {
102
+ $group: {
103
+ _id: '$typeOf',
104
+ eventCount: { $sum: 1 },
105
+ reservationCount: { $sum: '$reservationCount' },
106
+ avgOfferCount: { $avg: '$offerCount' },
107
+ maximumAttendeeCapacity: { $sum: '$maximumAttendeeCapacity' },
108
+ remainingAttendeeCapacity: { $sum: '$remainingAttendeeCapacity' },
109
+ avgRemainingCapacityRate: { $avg: '$remainingCapacityRate' },
110
+ maxRemainingCapacityRate: { $max: '$remainingCapacityRate' },
111
+ minRemainingCapacityRate: { $min: '$remainingCapacityRate' }
112
+ }
113
+ },
114
+ {
115
+ $project: {
116
+ _id: 0,
117
+ eventCount: '$eventCount',
118
+ reservationCount: '$reservationCount',
119
+ avgOfferCount: '$avgOfferCount',
120
+ maximumAttendeeCapacity: '$maximumAttendeeCapacity',
121
+ remainingAttendeeCapacity: '$remainingAttendeeCapacity',
122
+ avgRemainingCapacityRate: '$avgRemainingCapacityRate',
123
+ maxRemainingCapacityRate: '$maxRemainingCapacityRate',
124
+ minRemainingCapacityRate: '$minRemainingCapacityRate'
125
+ }
126
+ }
127
+ ])
128
+ .exec();
129
+ const percents = [50, 95, 99];
130
+ if (aggregations.length === 0) {
131
+ return {
132
+ status: eventStatus,
133
+ aggregation: {
134
+ eventCount: 0,
135
+ reservationCount: 0,
136
+ avgOfferCount: 0,
137
+ maximumAttendeeCapacity: 0,
138
+ remainingAttendeeCapacity: 0,
139
+ avgRemainingCapacityRate: 0,
140
+ maxRemainingCapacityRate: 0,
141
+ minRemainingCapacityRate: 0,
142
+ percentilesRemainingCapacityRate: percents.map((percent) => {
143
+ return {
144
+ name: String(percent),
145
+ value: 0
146
+ };
147
+ })
148
+ }
149
+ };
150
+ }
151
+ const ranks4percentile = percents.map((percentile) => {
152
+ return {
153
+ percentile,
154
+ rank: Math.floor(aggregations[0].eventCount * percentile / 100)
155
+ };
156
+ });
157
+ const aggregations2 = await this.eventModel.aggregate([
158
+ {
159
+ $match: matchConditions
160
+ },
161
+ {
162
+ $project: {
163
+ remainingCapacityRate: {
164
+ $cond: {
165
+ if: {
166
+ $and: [
167
+ { $isNumber: '$maximumAttendeeCapacity' },
168
+ { $isNumber: '$remainingAttendeeCapacity' }
169
+ ]
170
+ },
171
+ then: {
172
+ $cond: {
173
+ if: { $gt: ['$maximumAttendeeCapacity', 0] },
174
+ then: {
175
+ $multiply: [
176
+ { $divide: ['$remainingAttendeeCapacity', '$maximumAttendeeCapacity'] },
177
+ 100
178
+ ]
179
+ },
180
+ else: 0
181
+ }
182
+ },
183
+ else: 0
184
+ }
185
+ },
186
+ eventStatus: '$eventStatus',
187
+ startDate: '$startDate',
188
+ endDate: '$endDate',
189
+ typeOf: '$typeOf'
190
+ }
191
+ },
192
+ { $sort: { remainingCapacityRate: 1 } },
193
+ {
194
+ $group: {
195
+ _id: '$typeOf',
196
+ remainingCapacityRates: { $push: '$remainingCapacityRate' }
197
+ }
198
+ },
199
+ {
200
+ $project: {
201
+ _id: 0,
202
+ percentilesRemainingCapacityRate: ranks4percentile.map((rank) => {
203
+ return {
204
+ name: String(rank.percentile),
205
+ value: { $arrayElemAt: ['$remainingCapacityRates', rank.rank] }
206
+ };
207
+ })
208
+ }
209
+ }
210
+ ])
211
+ .exec();
212
+ return {
213
+ status: eventStatus,
214
+ aggregation: {
215
+ ...aggregations[0],
216
+ ...aggregations2[0]
217
+ }
218
+ };
219
+ }
220
+ }
221
+ exports.AggregateEventRepo = AggregateEventRepo;
@@ -1,47 +1,7 @@
1
- import { Connection, FilterQuery, mongo } from 'mongoose';
1
+ import { Connection, FilterQuery } from 'mongoose';
2
2
  import { factory } from '../factory';
3
3
  import * as EventFactory from '../factory/event';
4
- export interface IAttributes4patchUpdate {
5
- typeOf: factory.eventType.ScreeningEvent;
6
- eventStatus?: factory.eventStatusType;
7
- }
8
- export interface IUpdateAggregateReservationParams {
9
- $set: {
10
- aggregateReservation: factory.event.screeningEvent.IAggregateReservation;
11
- aggregateOffer?: Pick<factory.event.screeningEvent.IAggregateOffer, 'aggregateDate' | 'offerCount' | 'typeOf'>;
12
- maximumAttendeeCapacity?: number;
13
- remainingAttendeeCapacity?: number;
14
- checkInCount?: number;
15
- attendeeCount?: number;
16
- };
17
- $unset: {
18
- noExistingAttributeName: 1;
19
- maximumAttendeeCapacity?: '';
20
- remainingAttendeeCapacity?: '';
21
- };
22
- }
23
4
  export type ISearchConditions = factory.event.screeningEvent.ISearchConditions;
24
- interface IAggregationByStatus {
25
- eventCount: number;
26
- reservationCount: number;
27
- avgOfferCount: number;
28
- maximumAttendeeCapacity: number;
29
- remainingAttendeeCapacity: number;
30
- avgRemainingCapacityRate: number;
31
- maxRemainingCapacityRate: number;
32
- minRemainingCapacityRate: number;
33
- percentilesRemainingCapacityRate: {
34
- name: string;
35
- value: number;
36
- }[];
37
- }
38
- interface IStatus {
39
- status: factory.eventStatusType;
40
- aggregation: IAggregationByStatus;
41
- }
42
- interface IAggregateEvent {
43
- statuses: IStatus[];
44
- }
45
5
  export import IMinimizedIndividualEvent = EventFactory.IMinimizedIndividualEvent;
46
6
  type IKeyOfProjection = Exclude<keyof factory.event.screeningEvent.IEvent, 'id'> | 'aggregateOffer' | 'superEvent.location.id' | 'offers.itemOffered' | 'offers.itemOffered.id' | 'offers.typeOf';
47
7
  type IKeyOfProjection4publicFields = Exclude<keyof factory.event.screeningEvent.IEvent, 'id' | 'offers'>;
@@ -50,75 +10,13 @@ type IKeyOfProjection4publicFields = Exclude<keyof factory.event.screeningEvent.
50
10
  * add(2024-07-18~)
51
11
  */
52
12
  type IKeyOfProjection4minimizedEvent = Exclude<keyof IMinimizedIndividualEvent, 'additionalProperty' | 'id'> | 'superEvent.id' | 'location.branchCode' | 'superEvent.workPerformed.identifier' | 'superEvent.location.id' | 'offers.itemOffered' | 'offers.itemOffered.id' | 'offers.offeredThrough' | 'offers.unacceptedPaymentMethod' | 'offers.eligibleQuantity';
53
- type IUnset = {
54
- [key in keyof factory.event.screeningEvent.IEvent]?: 1;
55
- };
56
- export type ICreatingEvent4ttts = Pick<factory.event.screeningEvent.IAttributes, 'additionalProperty' | 'doorTime' | 'endDate' | 'eventStatus' | 'location' | 'name' | 'offers' | 'organizer' | 'project' | 'startDate' | 'superEvent' | 'typeOf'> & {
57
- identifier: string;
58
- };
59
13
  /**
60
14
  * イベントリポジトリ
61
15
  */
62
16
  export declare class EventRepo {
63
17
  private readonly eventModel;
64
18
  constructor(connection: Connection);
65
- /**
66
- * イベントIDを生成する
67
- */
68
- static CREATE_ID(): string;
69
19
  static CREATE_MONGO_CONDITIONS(conditions: ISearchConditions): FilterQuery<factory.event.screeningEvent.IEvent>[];
70
- /**
71
- * イベントコードをキーにして冪等置換
72
- */
73
- upsertManyScreeningEventByIdentifier(params: {
74
- $set: factory.event.screeningEvent.IAttributes & {
75
- id?: never;
76
- };
77
- $unset: IUnset;
78
- }[], options: {
79
- /**
80
- * falseの場合setOnInsertのみ
81
- * trueの場合setのみ
82
- */
83
- update: boolean;
84
- }): Promise<{
85
- bulkWriteResult?: mongo.BulkWriteResult;
86
- modifiedEvents: {
87
- id: string;
88
- }[];
89
- }>;
90
- /**
91
- * イベント部分更新
92
- */
93
- updatePartiallyById(params: {
94
- project: {
95
- id: string;
96
- };
97
- id: string;
98
- attributes: IAttributes4patchUpdate;
99
- }): Promise<void>;
100
- /**
101
- * 単一イベント編集
102
- */
103
- updateEventById(params: {
104
- id: string;
105
- attributes: factory.event.screeningEvent.IAttributes & {
106
- id?: never;
107
- };
108
- /**
109
- * ドキュメント作成時には無視される
110
- */
111
- $unset?: IUnset;
112
- }): Promise<void>;
113
- /**
114
- * sskts専用
115
- */
116
- saveManyEvents(params: {
117
- id: string;
118
- attributes: factory.event.screeningEvent.IAttributes;
119
- $unset?: IUnset;
120
- upsert: boolean;
121
- }[]): Promise<void>;
122
20
  /**
123
21
  * イベントを検索する(inclusion projection)
124
22
  */
@@ -159,7 +57,10 @@ export declare class EventRepo {
159
57
  };
160
58
  };
161
59
  }): Promise<Omit<factory.event.screeningEvent.IEvent, 'aggregateOffer'>>;
162
- searchEventIds(params: ISearchConditions): Promise<string[]>;
60
+ /**
61
+ * COAイベントキャンセル時に使用
62
+ */
63
+ searchEventIds(params: Pick<ISearchConditions, 'project' | 'typeOf' | 'superEvent' | 'startFrom' | 'startThrough'>): Promise<string[]>;
163
64
  /**
164
65
  * 特定イベントから指定フィールドのみ取得する
165
66
  * イベント IDは必ず返ります
@@ -167,164 +68,5 @@ export declare class EventRepo {
167
68
  projectEventFieldsById(params: {
168
69
  id: string;
169
70
  }, inclusion: IKeyOfProjection4minimizedEvent[]): Promise<IMinimizedIndividualEvent>;
170
- /**
171
- * イベントをキャンセルする
172
- */
173
- cancelEvent(params: {
174
- project: {
175
- id: string;
176
- };
177
- id: string;
178
- }): Promise<import("mongoose").UpdateWriteOpResult>;
179
- /**
180
- * 興行イベントのsuperEventを最新の情報に同期する
181
- */
182
- syncScreeningEventSeries2screeningEvents(params: {
183
- project: {
184
- id: string;
185
- };
186
- superEventFromDB: Pick<factory.eventSeries.IEvent, 'additionalProperty' | 'alternativeHeadline' | 'description' | 'dubLanguage' | 'endDate' | 'headline' | 'id' | 'kanaName' | 'location' | 'name' | 'soundFormat' | 'startDate' | 'subtitleLanguage' | 'typeOf' | 'workPerformed'>;
187
- startDate: {
188
- $gte: Date;
189
- };
190
- }): Promise<void>;
191
- deleteEventById(params: {
192
- project: {
193
- id: string;
194
- };
195
- id: string;
196
- }): Promise<void>;
197
- deleteManyEventByOrganizerId(params: {
198
- project: {
199
- id: string;
200
- };
201
- organizer: {
202
- id: string;
203
- };
204
- }): Promise<mongo.DeleteResult>;
205
- deleteManyEventsByScreeningRoom(params: {
206
- project: {
207
- id: string;
208
- };
209
- location: {
210
- /**
211
- * ルームコード
212
- */
213
- branchCode: string;
214
- containedInPlace: {
215
- /**
216
- * 施設ID
217
- */
218
- id: string;
219
- };
220
- };
221
- }): Promise<mongo.DeleteResult>;
222
- deleteManyBySuperEventId(params: {
223
- project: {
224
- id: string;
225
- };
226
- superEvent: {
227
- id: string;
228
- };
229
- }): Promise<mongo.DeleteResult>;
230
- deleteManyBySuperEventLocationId(params: {
231
- project: {
232
- id: string;
233
- };
234
- superEvent: {
235
- location: {
236
- id: string;
237
- };
238
- };
239
- }): Promise<mongo.DeleteResult>;
240
- /**
241
- * 興行(プロダクト)から削除する
242
- */
243
- deleteManyEventsByItemOfferedId(params: {
244
- project: {
245
- id: string;
246
- };
247
- offers: {
248
- itemOffered: {
249
- id: {
250
- $in: string[];
251
- };
252
- };
253
- };
254
- }): Promise<mongo.DeleteResult>;
255
- deleteManyEventsEndedByProject(params: {
256
- typeOf: {
257
- $in: factory.eventType.ScreeningEvent[];
258
- };
259
- project: {
260
- id: string;
261
- };
262
- endDate: {
263
- $lte: Date;
264
- };
265
- }): Promise<mongo.DeleteResult>;
266
- deleteManyEventsEnded(params: {
267
- typeOf: {
268
- $eq: factory.eventType.ScreeningEvent;
269
- };
270
- endDate: {
271
- $lte: Date;
272
- };
273
- }): Promise<mongo.DeleteResult>;
274
- deleteByProject(params: {
275
- project: {
276
- id: string;
277
- };
278
- }): Promise<void>;
279
- /**
280
- * 集計属性を更新する
281
- */
282
- updateAggregationById(params: {
283
- id: string;
284
- }, update: IUpdateAggregateReservationParams): Promise<void>;
285
- bulkWrite(bulkWriteOps: any[]): Promise<mongo.BulkWriteResult & {
286
- mongoose?: {
287
- validationErrors: import("mongoose").Error[];
288
- } | undefined;
289
- }>;
290
- getCursor(conditions: FilterQuery<any>, projection: any): import("mongoose").Cursor<import("mongoose").Document<unknown, Record<string, never>, import("@chevre/factory/lib/chevre/event/screeningEvent").IAttributes & {
291
- _id: string;
292
- aggregateOffer?: factory.event.screeningEvent.IAggregateOffer;
293
- }, import("./mongoose/virtuals").IVirtuals, {}> & import("@chevre/factory/lib/chevre/event/screeningEvent").IAttributes & {
294
- _id: string;
295
- aggregateOffer?: factory.event.screeningEvent.IAggregateOffer;
296
- } & Required<{
297
- _id: string;
298
- }> & {
299
- __v: number;
300
- }, import("mongoose").QueryOptions<import("@chevre/factory/lib/chevre/event/screeningEvent").IAttributes & {
301
- _id: string;
302
- aggregateOffer?: factory.event.screeningEvent.IAggregateOffer;
303
- }>, (import("mongoose").Document<unknown, Record<string, never>, import("@chevre/factory/lib/chevre/event/screeningEvent").IAttributes & {
304
- _id: string;
305
- aggregateOffer?: factory.event.screeningEvent.IAggregateOffer;
306
- }, import("./mongoose/virtuals").IVirtuals, {}> & import("@chevre/factory/lib/chevre/event/screeningEvent").IAttributes & {
307
- _id: string;
308
- aggregateOffer?: factory.event.screeningEvent.IAggregateOffer;
309
- } & Required<{
310
- _id: string;
311
- }> & {
312
- __v: number;
313
- }) | null>;
314
- unsetUnnecessaryFields(params: {
315
- filter: FilterQuery<factory.event.screeningEvent.IEvent>;
316
- $unset: IUnset;
317
- }): Promise<import("mongoose").UpdateWriteOpResult>;
318
- aggregateEvent(params: {
319
- project?: {
320
- id?: {
321
- $ne?: string;
322
- };
323
- };
324
- startFrom: Date;
325
- startThrough: Date;
326
- typeOf: factory.eventType.ScreeningEvent;
327
- }): Promise<IAggregateEvent>;
328
- private agggregateByStatus;
329
71
  }
330
72
  export {};