@chevre/domain 25.2.0-alpha.40 → 25.2.0-alpha.41

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.
@@ -138,7 +138,11 @@ export declare class OfferRepo implements OfferInCatalogReadOnlyRepo {
138
138
  unacceptedPaymentMethod: string[];
139
139
  }): Promise<boolean>;
140
140
  count(params: Omit<factory.unitPriceOffer.ISearchConditions, 'limit' | 'page' | 'sort'>): Promise<number>;
141
+ /**
142
+ * @deprecated use findUnitPriceOffers
143
+ */
141
144
  search(params: factory.unitPriceOffer.ISearchConditions, projection?: IProjection): Promise<IOfferInCatalog[]>;
145
+ findUnitPriceOffers(params: factory.unitPriceOffer.ISearchConditions, projection?: IProjection): Promise<IOfferInCatalog[]>;
142
146
  /**
143
147
  * サブカタログから集計オファーIDリストを検索する
144
148
  */
@@ -384,6 +384,9 @@ class OfferRepo {
384
384
  .exec();
385
385
  return (result.length > 0) ? result[0].offerCount : 0;
386
386
  }
387
+ /**
388
+ * @deprecated use findUnitPriceOffers
389
+ */
387
390
  async search(params, projection) {
388
391
  const matchStages = aggregateOffer_1.AggregateOfferRepo.CREATE_MATCH_STAGE(params);
389
392
  const projectStage = OfferRepo.CREATE_AGGREGATE_OFFERS_PROJECTION({ ...projection });
@@ -421,6 +424,43 @@ class OfferRepo {
421
424
  }
422
425
  return aggregate.exec();
423
426
  }
427
+ async findUnitPriceOffers(params, projection) {
428
+ const matchStages = aggregateOffer_1.AggregateOfferRepo.CREATE_MATCH_STAGE(params);
429
+ const projectStage = OfferRepo.CREATE_AGGREGATE_OFFERS_PROJECTION({ ...projection });
430
+ const sortByPrice = params.sort?.['priceSpecification.price'];
431
+ const sortByIdentifier = params.sort?.identifier;
432
+ const aggregate = this.aggregateOfferModel.aggregate([
433
+ ...matchStages, // match -> unwind(2026-07-23~)
434
+ {
435
+ $unwind: {
436
+ path: '$offers',
437
+ includeArrayIndex: OFFERS_ARRAY_INDEX_NAME
438
+ }
439
+ },
440
+ ...(typeof sortByPrice === 'number' || typeof sortByIdentifier === 'number')
441
+ ? [
442
+ {
443
+ $sort: {
444
+ ...(typeof sortByPrice === 'number')
445
+ ? { 'offers.priceSpecification.price': sortByPrice }
446
+ : undefined,
447
+ ...(typeof sortByIdentifier === 'number')
448
+ ? { 'offers.identifier': sortByIdentifier }
449
+ : undefined
450
+ }
451
+ }
452
+ ]
453
+ : [],
454
+ { $project: projectStage }
455
+ ]);
456
+ /* istanbul ignore else */
457
+ if (typeof params.limit === 'number' && params.limit > 0) {
458
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
459
+ aggregate.limit(params.limit * page)
460
+ .skip(params.limit * (page - 1));
461
+ }
462
+ return aggregate.exec();
463
+ }
424
464
  /**
425
465
  * サブカタログから集計オファーIDリストを検索する
426
466
  */
@@ -310,7 +310,8 @@ function validateAcceptedOffers(params) {
310
310
  // 指定された単価オファーを検索
311
311
  // ticketCodeで検索(2023-03-22~)
312
312
  if (offerIdentifiers.length > 0) {
313
- availableUnitPriceOffers = await repos.offer.search({
313
+ // availableUnitPriceOffers = await repos.offer.search({
314
+ availableUnitPriceOffers = await repos.offer.findUnitPriceOffers({
314
315
  identifier: { $in: offerIdentifiers },
315
316
  project: { id: { $eq: params.project.id } }
316
317
  });
@@ -11,7 +11,7 @@ function createInformOfferTasks(params, setting) {
11
11
  }
12
12
  // const informResources = settings.onResourceUpdated.informResource;
13
13
  const informResources = setting?.onResourceUpdated?.informResource;
14
- const offers = await repos.offer.search({
14
+ const offers = await repos.offer.findUnitPriceOffers({
15
15
  id: { $in: params.ids }
16
16
  }, { typeOf: 1, name: 1, priceSpecification: 1, additionalProperty: 1, identifier: 1, project: 1 });
17
17
  const offers4inform = offers.map(({ id, typeOf, name, priceSpecification, additionalProperty, identifier, project }) => {
@@ -88,7 +88,7 @@ function prepareUnitPriceOfferConditions(params) {
88
88
  }
89
89
  const conditions = [];
90
90
  const offerIds = [...new Set(params.acceptedOffers.map((o) => String(o.id)))];
91
- const unitPriceOffers = await repos.offer.search({
91
+ const unitPriceOffers = await repos.offer.findUnitPriceOffers({
92
92
  id: { $in: offerIds }
93
93
  }, {
94
94
  acceptedPaymentMethod: 1,
@@ -28,7 +28,7 @@ function preStart(params) {
28
28
  await validateOrder({ orders })();
29
29
  let offers = [];
30
30
  if (offerIds.length > 0) {
31
- offers = await repos.offer.search({
31
+ offers = await repos.offer.findUnitPriceOffers({
32
32
  id: { $in: offerIds }
33
33
  });
34
34
  }
package/package.json CHANGED
@@ -88,5 +88,5 @@
88
88
  "postversion": "git push origin --tags",
89
89
  "prepublishOnly": "npm run clean && npm run build"
90
90
  },
91
- "version": "25.2.0-alpha.40"
91
+ "version": "25.2.0-alpha.41"
92
92
  }