@chevre/domain 21.2.0-alpha.128 → 21.2.0-alpha.129

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.
@@ -24,6 +24,13 @@ async function main() {
24
24
  });
25
25
  console.log(holdReservations[0]?.reservationFor.aggregateReservation, holdReservations[0]?.objectSize);
26
26
  console.log(holdReservations.length);
27
+
28
+ const aggregations = await stockHolderRepo.aggregateByReservationFor({
29
+ // reservationFor: { id: { $eq: 'xxx' } },
30
+ limit: 100,
31
+ page: 1
32
+ });
33
+ console.log(aggregations);
27
34
  }
28
35
 
29
36
  main()
@@ -174,6 +174,32 @@ export declare class StockHolderRepository {
174
174
  };
175
175
  };
176
176
  }): Promise<ISearchResult[]>;
177
+ /**
178
+ * 汎用的な集計(mongooseのみ対応)
179
+ */
180
+ aggregateByReservationFor(params: {
181
+ limit?: number;
182
+ page?: number;
183
+ project?: {
184
+ id?: {
185
+ $eq?: string;
186
+ };
187
+ };
188
+ reservationFor?: {
189
+ id?: {
190
+ $eq?: string;
191
+ };
192
+ };
193
+ }): Promise<{
194
+ typeOf: 'AggregateReservation';
195
+ reservationCount: number;
196
+ reservationFor: {
197
+ id: string;
198
+ startDate: Date;
199
+ };
200
+ reservationPackageCount: number;
201
+ objectSize: number;
202
+ }[]>;
177
203
  private checkIfConflicted;
178
204
  private initializeHoldReservation;
179
205
  }
@@ -555,6 +555,43 @@ class StockHolderRepository {
555
555
  .exec();
556
556
  });
557
557
  }
558
+ /**
559
+ * 汎用的な集計(mongooseのみ対応)
560
+ */
561
+ aggregateByReservationFor(params) {
562
+ var _a, _b, _c, _d;
563
+ return __awaiter(this, void 0, void 0, function* () {
564
+ const matchStages = [];
565
+ const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
566
+ if (typeof projectIdEq === 'string') {
567
+ matchStages.push({ $match: { 'project.id': { $eq: projectIdEq } } });
568
+ }
569
+ const reservationForIdEq = (_d = (_c = params.reservationFor) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.$eq;
570
+ if (typeof reservationForIdEq === 'string') {
571
+ matchStages.push({ $match: { 'reservationFor.id': { $eq: reservationForIdEq } } });
572
+ }
573
+ const aggregate = this.holdReservationModel.aggregate([
574
+ ...matchStages,
575
+ {
576
+ $project: {
577
+ _id: 0,
578
+ typeOf: '$typeOf',
579
+ reservationCount: '$reservationCount',
580
+ reservationFor: '$reservationFor',
581
+ reservationPackageCount: { $size: '$reservations' },
582
+ objectSize: { $bsonSize: '$$ROOT' }
583
+ }
584
+ }
585
+ ]);
586
+ if (typeof params.limit === 'number' && params.limit > 0) {
587
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
588
+ aggregate.limit(params.limit * page)
589
+ .skip(params.limit * (page - 1));
590
+ }
591
+ return aggregate.option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
592
+ .exec();
593
+ });
594
+ }
558
595
  checkIfConflicted(params) {
559
596
  return __awaiter(this, void 0, void 0, function* () {
560
597
  // 旧キーと新キーの両方存在検証(念のため)
package/package.json CHANGED
@@ -117,5 +117,5 @@
117
117
  "postversion": "git push origin --tags",
118
118
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
119
119
  },
120
- "version": "21.2.0-alpha.128"
120
+ "version": "21.2.0-alpha.129"
121
121
  }