@chevre/domain 22.9.0-alpha.114 → 22.9.0-alpha.116

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 (51) hide show
  1. package/example/src/chevre/offers/projectItemListElement.ts +54 -0
  2. package/example/src/chevre/offers/searchByOfferCatalogIdWithSortIndex.ts +44 -0
  3. package/example/src/chevre/stockHolder/checkRedisKeyCount.ts +1 -1
  4. package/example/src/chevre/upsertOffersByIdentifier.ts +1 -1
  5. package/lib/chevre/repo/aggregateOffer.d.ts +42 -3
  6. package/lib/chevre/repo/aggregateOffer.js +253 -13
  7. package/lib/chevre/repo/mongoose/schemas/note.js +16 -0
  8. package/lib/chevre/repo/note.d.ts +3 -5
  9. package/lib/chevre/repo/note.js +4 -4
  10. package/lib/chevre/repo/offer/offerInCatalogReadOnly.d.ts +136 -0
  11. package/lib/chevre/repo/offer/offerInCatalogReadOnly.js +9 -0
  12. package/lib/chevre/repo/{offer.d.ts → offer/unitPriceInCatalog.d.ts} +10 -105
  13. package/lib/chevre/repo/{offer.js → offer/unitPriceInCatalog.js} +6 -279
  14. package/lib/chevre/repo/offerCatalog.d.ts +9 -1
  15. package/lib/chevre/repo/offerCatalog.js +49 -21
  16. package/lib/chevre/repo/offerCatalogItem.d.ts +15 -0
  17. package/lib/chevre/repo/offerCatalogItem.js +25 -0
  18. package/lib/chevre/repository.d.ts +1 -1
  19. package/lib/chevre/repository.js +1 -1
  20. package/lib/chevre/service/aggregation/event/aggregateOffers.d.ts +1 -1
  21. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.d.ts +1 -1
  22. package/lib/chevre/service/aggregation/event/findEventOffers.d.ts +1 -1
  23. package/lib/chevre/service/assetTransaction/registerService.d.ts +1 -1
  24. package/lib/chevre/service/assetTransaction/reserve/start/createSubReservations.d.ts +1 -1
  25. package/lib/chevre/service/assetTransaction/reserve/start.d.ts +1 -1
  26. package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre.d.ts +1 -1
  27. package/lib/chevre/service/offer/event/authorize.d.ts +1 -1
  28. package/lib/chevre/service/offer/event/importFromCOA.d.ts +2 -2
  29. package/lib/chevre/service/offer/event/importFromCOA.js +1 -1
  30. package/lib/chevre/service/offer/event/searchEventTicketOffers.d.ts +1 -1
  31. package/lib/chevre/service/offer/event/searchOfferAppliesToMovieTicket.d.ts +1 -1
  32. package/lib/chevre/service/offer/event/searchOfferCatalogItemAvailability.d.ts +1 -1
  33. package/lib/chevre/service/offer/event/searchOfferCatalogItemAvailability.js +1 -1
  34. package/lib/chevre/service/offer/event/searchOfferCatalogItems.js +1 -1
  35. package/lib/chevre/service/offer/event/searchOffersByIds.d.ts +1 -1
  36. package/lib/chevre/service/offer/eventServiceByCOA/authorize/validateAcceptedOffers.d.ts +1 -1
  37. package/lib/chevre/service/offer/eventServiceByCOA/authorize.d.ts +1 -1
  38. package/lib/chevre/service/offer/product/searchProductOffers.d.ts +1 -1
  39. package/lib/chevre/service/offer/product.d.ts +1 -1
  40. package/lib/chevre/service/project.d.ts +1 -1
  41. package/lib/chevre/service/task/aggregateOffers.js +4 -4
  42. package/lib/chevre/service/task/aggregateScreeningEvent.js +4 -4
  43. package/lib/chevre/service/task/importOffersFromCOA.js +3 -3
  44. package/lib/chevre/service/task/onResourceUpdated/onAggregateOfferUpdated.d.ts +1 -1
  45. package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.d.ts +1 -1
  46. package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.js +2 -2
  47. package/lib/chevre/service/task/onResourceUpdated.js +3 -6
  48. package/lib/chevre/service/transaction/returnOrder/preStart.d.ts +1 -1
  49. package/lib/chevre/service/transaction/returnOrder.d.ts +1 -1
  50. package/package.json +1 -1
  51. package/example/src/chevre/pullAddOnsFromOffer.ts +0 -26
@@ -0,0 +1,54 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../../lib/index';
5
+
6
+ // const project = { id: String(process.env.PROJECT_ID) };
7
+
8
+ const formatter = new Intl.NumberFormat('ja-JP');
9
+
10
+ // tslint:disable-next-line:max-func-body-length
11
+ async function main() {
12
+ let startTime: [number, number] = process.hrtime();
13
+ let diff: [number, number] = process.hrtime(startTime);
14
+ let result: any;
15
+
16
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
17
+
18
+ const offerCatalogRepo = await chevre.repository.OfferCatalog.createInstance(mongoose.connection);
19
+ const offerCatalogItemRepo = await chevre.repository.OfferCatalogItem.createInstance(mongoose.connection);
20
+
21
+ // startTime = process.hrtime();
22
+ // result = await offerCatalogRepo.searchItemListElementById({
23
+ // id: 'blpc770py',
24
+ // limit: 100,
25
+ // page: 1
26
+ // });
27
+ // diff = process.hrtime(startTime);
28
+ // console.log('diff:', [diff[0], formatter.format(diff[1])]);
29
+ // console.log('result:', result);
30
+
31
+ startTime = process.hrtime();
32
+ result = await offerCatalogRepo.sliceItemListElementById({
33
+ id: 'blpc770py',
34
+ limit: 10,
35
+ page: 1
36
+ });
37
+ diff = process.hrtime(startTime);
38
+ console.log('diff:', [diff[0], formatter.format(diff[1])]);
39
+ console.log('result:', result);
40
+
41
+ startTime = process.hrtime();
42
+ result = await offerCatalogItemRepo.sliceItemListElementById({
43
+ id: '65669285c7b871dba60ed72e',
44
+ limit: 10,
45
+ page: 1
46
+ });
47
+ diff = process.hrtime(startTime);
48
+ console.log('diff:', [diff[0], formatter.format(diff[1])]);
49
+ console.log('result:', result);
50
+ }
51
+
52
+ main()
53
+ .then()
54
+ .catch(console.error);
@@ -0,0 +1,44 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../../lib/index';
5
+
6
+ // const project = { id: String(process.env.PROJECT_ID) };
7
+
8
+ mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
9
+
10
+ // tslint:disable-next-line:max-func-body-length
11
+ async function main() {
12
+ const offerRepo = await chevre.repository.Offer.createInstance(mongoose.connection);
13
+
14
+ const result = await offerRepo.searchByOfferCatalogIdWithSortIndex({
15
+ offerCatalog: { id: '65669285c7b871dba60ed72e', isOfferCatalogItem: true },
16
+ // availableAtOrFrom: { id: params.store?.id },
17
+ // unacceptedPaymentMethod: params.unacceptedPaymentMethod,
18
+ excludeAppliesToMovieTicket: false,
19
+ priceSpecification: {
20
+ appliesToMovieTicket: {
21
+ // serviceOutput: {
22
+ // typeOf: {
23
+ // ...(typeof req.query.priceSpecification?.appliesToMovieTicket?.serviceOutput?.typeOf?.$eq === 'string')
24
+ // ? { $eq: req.query.priceSpecification.appliesToMovieTicket.serviceOutput.typeOf.$eq }
25
+ // : undefined
26
+ // }
27
+ // },
28
+ serviceType: {
29
+ $exists: false
30
+ }
31
+ }
32
+ },
33
+ onlyValid: false,
34
+ useIncludeInDataCatalog: true,
35
+ limit: 10,
36
+ page: 1
37
+ });
38
+ console.log('result:', result);
39
+ console.log(result.offers.map(({ name }) => name));
40
+ }
41
+
42
+ main()
43
+ .then()
44
+ .catch(console.error);
@@ -45,7 +45,7 @@ async function main() {
45
45
  const cursor = eventRepo.getCursor(
46
46
  {
47
47
  'project.id': {
48
- // $eq: 'toei-production',
48
+ $eq: 'toei-production',
49
49
  $in: useMongoAsStockHolderProjects
50
50
  },
51
51
  startDate: {
@@ -10,7 +10,7 @@ const PRICE = 1234;
10
10
  async function main() {
11
11
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
12
12
 
13
- const offerRepo = await chevre.repository.Offer.createInstance(mongoose.connection);
13
+ const offerRepo = await chevre.repository.AggregateOffer.createInstance(mongoose.connection);
14
14
 
15
15
  const result = await offerRepo.upsertByIdentifier(
16
16
  [
@@ -1,5 +1,7 @@
1
- import type { AnyExpression, Connection, FilterQuery, PipelineStage } from 'mongoose';
1
+ import type { BulkWriteResult } from 'mongodb';
2
+ import { AnyExpression, Connection, Document, FilterQuery, PipelineStage } from 'mongoose';
2
3
  import * as factory from '../factory';
4
+ import { IDocType as IAggregateOfferDocType } from './mongoose/schemas/aggregateOffer';
3
5
  type IMatchStage = PipelineStage.Match;
4
6
  type KeyOfUnitPriceOffer = keyof factory.unitPriceOffer.IUnitPriceOffer;
5
7
  type IProjection = {
@@ -57,15 +59,52 @@ export declare class AggregateOfferRepo {
57
59
  };
58
60
  id: string;
59
61
  }): Promise<void>;
60
- getCursor(conditions: any, projection: any): import("mongoose").Cursor<import("mongoose").Document<unknown, {}, import("./mongoose/schemas/aggregateOffer").IDocType> & import("./mongoose/schemas/aggregateOffer").IDocType & Required<{
62
+ getCursor(conditions: any, projection: any): import("mongoose").Cursor<Document<unknown, {}, IAggregateOfferDocType> & IAggregateOfferDocType & Required<{
61
63
  _id: string;
62
- }>, import("mongoose").QueryOptions<import("mongoose").Document<unknown, {}, import("./mongoose/schemas/aggregateOffer").IDocType> & import("./mongoose/schemas/aggregateOffer").IDocType & Required<{
64
+ }>, import("mongoose").QueryOptions<Document<unknown, {}, IAggregateOfferDocType> & IAggregateOfferDocType & Required<{
63
65
  _id: string;
64
66
  }>>>;
65
67
  unsetUnnecessaryFields(params: {
66
68
  filter: FilterQuery<factory.aggregateOffer.IAggregateOffer>;
67
69
  $unset: any;
68
70
  }): Promise<import("mongoose").UpdateWriteOpResult>;
71
+ save(params: factory.unitPriceOffer.IUnitPriceOffer & {}): Promise<{
72
+ id: string;
73
+ }>;
74
+ /**
75
+ * コードをキーにして冪等置換(2023-12-13~)
76
+ */
77
+ upsertByIdentifier(params: Omit<factory.unitPriceOffer.IUnitPriceOffer, 'id'>[]): Promise<{
78
+ bulkWriteResult: BulkWriteResult;
79
+ modifiedOffers: {
80
+ id: string;
81
+ }[];
82
+ } | void>;
83
+ /**
84
+ * sskts専用オファー保管
85
+ */
86
+ saveManyByIdentifier4sskts(params: {
87
+ project: {
88
+ id: string;
89
+ };
90
+ attributes: factory.aggregateOffer.ISubOffer;
91
+ upsert?: boolean;
92
+ }[]): Promise<void>;
93
+ /**
94
+ * プロダクトIDからアドオンを除外する
95
+ */
96
+ pullAddOns(params: {
97
+ project: {
98
+ id: string;
99
+ };
100
+ addOn: {
101
+ itemOffered: {
102
+ id: {
103
+ $in: string[];
104
+ };
105
+ };
106
+ };
107
+ }): Promise<import("mongoose").UpdateWriteOpResult | undefined>;
69
108
  countIncludedInDataCatalog(params: {
70
109
  id: {
71
110
  $eq: string;
@@ -8,6 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
11
22
  Object.defineProperty(exports, "__esModule", { value: true });
12
23
  exports.AggregateOfferRepo = void 0;
13
24
  const createDebug = require("debug");
@@ -434,19 +445,6 @@ class AggregateOfferRepo {
434
445
  }
435
446
  return projectStage;
436
447
  }
437
- // public async count(
438
- // params: Omit<factory.unitPriceOffer.ISearchConditions, 'limit' | 'page' | 'sort'>
439
- // ): Promise<number> {
440
- // const matchStages = AggregateOfferRepo.CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params);
441
- // const result = await this.aggregateOfferModel.aggregate<{ offerCount: number }>([
442
- // ...matchStages,
443
- // {
444
- // $count: 'offerCount'
445
- // }
446
- // ])
447
- // .exec();
448
- // return (result.length > 0) ? result[0].offerCount : 0;
449
- // }
450
448
  search(params, projection) {
451
449
  return __awaiter(this, void 0, void 0, function* () {
452
450
  var _a, _b;
@@ -570,6 +568,248 @@ class AggregateOfferRepo {
570
568
  .exec();
571
569
  });
572
570
  }
571
+ save(params) {
572
+ return __awaiter(this, void 0, void 0, function* () {
573
+ var _a;
574
+ let doc;
575
+ let aggregateOfferId;
576
+ // const { $unset, ...paramsWithoutUnset } = params;
577
+ const paramsWithoutUnset = __rest(params, []);
578
+ // let savedUnitPriceOffer: factory.unitPriceOffer.IUnitPriceOffer;
579
+ if (typeof params.id !== 'string' || params.id.length === 0) {
580
+ const uniqid = yield Promise.resolve().then(() => require('uniqid'));
581
+ const newId = uniqid();
582
+ aggregateOfferId = newId;
583
+ // サブオファー最適化(2023-12-22~)
584
+ // savedUnitPriceOffer = { ...paramsWithoutUnset, id };
585
+ const { id, project } = paramsWithoutUnset, savedUnitPriceOffer = __rest(paramsWithoutUnset, ["id", "project"]);
586
+ const aggregateOffer = {
587
+ typeOf: factory.offerType.AggregateOffer,
588
+ project: params.project,
589
+ offers: [savedUnitPriceOffer]
590
+ };
591
+ doc = yield this.aggregateOfferModel.create(Object.assign(Object.assign({}, aggregateOffer), { _id: newId }));
592
+ }
593
+ else {
594
+ aggregateOfferId = params.id;
595
+ // const unitPriceOffers = <Pick<factory.unitPriceOffer.IUnitPriceOffer, 'id' | 'identifier' | 'project' | 'typeOf'>[]>
596
+ // await this.search(
597
+ // {
598
+ // limit: 1,
599
+ // page: 1,
600
+ // project: { id: { $eq: params.project.id } },
601
+ // id: { $eq: params.id }
602
+ // },
603
+ // { identifier: 1, project: 1, typeOf: 1 }
604
+ // );
605
+ // const originalUnitPriceOffer = unitPriceOffers.shift();
606
+ const aggregateOffers = yield this.search({
607
+ limit: 1,
608
+ page: 1,
609
+ project: { id: { $eq: params.project.id } },
610
+ id: { $eq: params.id }
611
+ });
612
+ const originalUnitPriceOffer = (_a = aggregateOffers.shift()) === null || _a === void 0 ? void 0 : _a.offers.shift();
613
+ if (originalUnitPriceOffer === undefined) {
614
+ throw new factory.errors.NotFound(factory.offerType.Offer);
615
+ }
616
+ // 上書き禁止属性を除外
617
+ const { id, identifier, project, typeOf } = paramsWithoutUnset, updateFields = __rest(paramsWithoutUnset, ["id", "identifier", "project", "typeOf"]);
618
+ // サブオファー最適化(2023-12-22~)
619
+ const subOffer = Object.assign(Object.assign({}, updateFields), {
620
+ // id: originalUnitPriceOffer.id,
621
+ identifier: originalUnitPriceOffer.identifier,
622
+ // project: originalUnitPriceOffer.project,
623
+ typeOf: originalUnitPriceOffer.typeOf });
624
+ doc = yield this.aggregateOfferModel.findOneAndUpdate(
625
+ // { 'offers.id': params.id },
626
+ { _id: params.id }, // _idに変更(2023-12-22~)
627
+ {
628
+ $set: {
629
+ // 'offers.$[offer]': savedUnitPriceOffer
630
+ 'offers.0': subOffer // _idに変更(2023-12-22~)
631
+ }
632
+ }, {
633
+ upsert: false,
634
+ new: true
635
+ // _idに変更(2023-12-22~)
636
+ // arrayFilters: [
637
+ // { 'offer.id': { $eq: params.id } }
638
+ // ]
639
+ })
640
+ .exec();
641
+ }
642
+ if (doc === null) {
643
+ throw new factory.errors.NotFound(this.aggregateOfferModel.modelName);
644
+ }
645
+ return { id: aggregateOfferId };
646
+ });
647
+ }
648
+ /**
649
+ * コードをキーにして冪等置換(2023-12-13~)
650
+ */
651
+ upsertByIdentifier(params) {
652
+ return __awaiter(this, void 0, void 0, function* () {
653
+ const uniqid = yield Promise.resolve().then(() => require('uniqid'));
654
+ const insertBulkWriteOps = [];
655
+ // const updateBulkWriteOps: AnyBulkWriteOperation<factory.aggregateOffer.IAggregateOffer>[] = [];
656
+ const queryFilters = [];
657
+ if (Array.isArray(params)) {
658
+ params.forEach((p) => {
659
+ // リソースのユニークネスを保証するfilter
660
+ const filter = {
661
+ 'project.id': { $eq: p.project.id },
662
+ 'offers.identifier': { $exists: true, $eq: p.identifier }
663
+ };
664
+ queryFilters.push({
665
+ 'project.id': { $eq: p.project.id },
666
+ 'offers.identifier': { $exists: true, $eq: p.identifier }
667
+ });
668
+ const newOfferId = uniqid(); // setOnInsert時のみに利用する新ID
669
+ // サブオファー最適化(2023-12-22~)
670
+ const { project } = p, subOffer = __rest(p, ["project"]);
671
+ const aggregateOffer = {
672
+ project: p.project,
673
+ typeOf: factory.offerType.AggregateOffer,
674
+ offers: [subOffer]
675
+ };
676
+ const setOnInsert = {
677
+ project: aggregateOffer.project,
678
+ typeOf: aggregateOffer.typeOf,
679
+ _id: newOfferId
680
+ };
681
+ const updateFilter = {
682
+ $setOnInsert: setOnInsert,
683
+ $set: { offers: aggregateOffer.offers }
684
+ };
685
+ const updateOneOnInsert = {
686
+ filter,
687
+ update: updateFilter,
688
+ upsert: true
689
+ };
690
+ insertBulkWriteOps.push({ updateOne: updateOneOnInsert });
691
+ });
692
+ }
693
+ if (insertBulkWriteOps.length > 0) {
694
+ const bulkWriteResult = yield this.aggregateOfferModel.bulkWrite(insertBulkWriteOps, { ordered: false });
695
+ // modifiedの場合upsertedIdsに含まれないので、idを検索する
696
+ const modifiedOffers = yield this.aggregateOfferModel.find({ $or: queryFilters },
697
+ // { _id: 1, 'offers.identifier': 1 }
698
+ { _id: 0, id: '$_id' })
699
+ .lean() // lean(2024-09-26~)
700
+ .exec();
701
+ return { bulkWriteResult, modifiedOffers };
702
+ }
703
+ });
704
+ }
705
+ /**
706
+ * sskts専用オファー保管
707
+ */
708
+ // tslint:disable-next-line:max-func-body-length
709
+ saveManyByIdentifier4sskts(params) {
710
+ return __awaiter(this, void 0, void 0, function* () {
711
+ const uniqid = yield Promise.resolve().then(() => require('uniqid'));
712
+ const insertBulkWriteOps = [];
713
+ // const updateBulkWriteOps: AnyBulkWriteOperation[] = [];
714
+ if (Array.isArray(params)) {
715
+ params.forEach((p) => {
716
+ const newOfferId = uniqid();
717
+ // サブオファー最適化(2023-12-22~)
718
+ // const unitPriceOffer: factory.aggregateOffer.ISubOffer = { ...p.attributes, id: newOfferId };
719
+ const subOffer = p.attributes;
720
+ const aggregateOffer = {
721
+ project: { id: p.project.id, typeOf: factory.organizationType.Project },
722
+ typeOf: factory.offerType.AggregateOffer,
723
+ offers: [subOffer]
724
+ };
725
+ insertBulkWriteOps.push({
726
+ updateOne: {
727
+ filter: {
728
+ 'project.id': { $eq: p.project.id },
729
+ 'offers.identifier': { $exists: true, $eq: p.attributes.identifier }
730
+ },
731
+ update: {
732
+ $setOnInsert: {
733
+ // ...aggregateOffer,
734
+ project: aggregateOffer.project,
735
+ typeOf: aggregateOffer.typeOf,
736
+ _id: newOfferId
737
+ },
738
+ $set: { offers: aggregateOffer.offers } // サブオファー最適化(2023-12-22~)
739
+ },
740
+ upsert: true
741
+ }
742
+ });
743
+ // updateBulkWriteOps.push({
744
+ // updateOne: {
745
+ // filter: {
746
+ // 'project.id': { $eq: aggregateOffer.project.id },
747
+ // 'offers.identifier': { $exists: true, $eq: subOffer.identifier }
748
+ // },
749
+ // update: {
750
+ // // 特定の属性のみ更新する(IDを上書きできないので)
751
+ // $set: {
752
+ // 'offers.0.name': subOffer.name,
753
+ // 'offers.0.description': subOffer.description,
754
+ // 'offers.0.alternateName': subOffer.alternateName,
755
+ // 'offers.0.priceSpecification': subOffer.priceSpecification,
756
+ // 'offers.0.additionalProperty': subOffer.additionalProperty,
757
+ // ...(Array.isArray(subOffer.eligibleMembershipType))
758
+ // ? { 'offers.0.eligibleMembershipType': subOffer.eligibleMembershipType }
759
+ // : undefined,
760
+ // ...(Array.isArray(subOffer.eligibleMonetaryAmount))
761
+ // ? { 'offers.0.eligibleMonetaryAmount': subOffer.eligibleMonetaryAmount }
762
+ // : undefined
763
+ // },
764
+ // },
765
+ // upsert: false
766
+ // }
767
+ // });
768
+ });
769
+ }
770
+ if (insertBulkWriteOps.length > 0) {
771
+ yield this.aggregateOfferModel.bulkWrite(insertBulkWriteOps, { ordered: false });
772
+ // await this.aggregateOfferModel.bulkWrite(updateBulkWriteOps, { ordered: false });
773
+ }
774
+ });
775
+ }
776
+ /**
777
+ * プロダクトIDからアドオンを除外する
778
+ */
779
+ pullAddOns(params) {
780
+ return __awaiter(this, void 0, void 0, function* () {
781
+ if (params.addOn.itemOffered.id.$in.length === 0) {
782
+ return;
783
+ }
784
+ const conditions = {
785
+ 'project.id': { $eq: params.project.id },
786
+ 'offers.addOn.itemOffered.id': { $exists: true, $in: params.addOn.itemOffered.id.$in }
787
+ };
788
+ // const updatingOffers = <Pick<factory.unitPriceOffer.IUnitPriceOffer, 'id' | 'identifier'>[]>await this.search(
789
+ // {
790
+ // project: { id: { $eq: params.project.id } },
791
+ // addOn: { itemOffered: { id: { $in: params.addOn.itemOffered.id.$in } } }
792
+ // },
793
+ // { identifier: 1 }
794
+ // );
795
+ return this.aggregateOfferModel.updateMany(conditions, {
796
+ $pull: {
797
+ 'offers.$[offer].addOn': {
798
+ 'itemOffered.id': { $in: params.addOn.itemOffered.id.$in }
799
+ }
800
+ }
801
+ }, {
802
+ arrayFilters: [
803
+ { 'offer.addOn.itemOffered.id': { $exists: true, $in: params.addOn.itemOffered.id.$in } }
804
+ ]
805
+ })
806
+ .exec();
807
+ // if (updatingOffers.length > 0) {
808
+ // // no op
809
+ // }
810
+ // return result;
811
+ });
812
+ }
573
813
  countIncludedInDataCatalog(params) {
574
814
  return __awaiter(this, void 0, void 0, function* () {
575
815
  const aggregate = this.aggregateOfferModel.aggregate([
@@ -45,6 +45,18 @@ const schemaOptions = {
45
45
  }
46
46
  };
47
47
  const indexes = [
48
+ [
49
+ {
50
+ 'project.id': 1,
51
+ 'about.id': 1,
52
+ identifier: 1,
53
+ version: 1
54
+ },
55
+ {
56
+ unique: true,
57
+ name: 'uniqueIdentifier'
58
+ }
59
+ ],
48
60
  [
49
61
  { dateCreated: -1 },
50
62
  { name: 'dateCreated' }
@@ -61,6 +73,10 @@ const indexes = [
61
73
  { 'about.id': 1, dateCreated: -1 },
62
74
  { name: 'aboutId' }
63
75
  ],
76
+ [
77
+ { 'about.typeOf': 1, dateCreated: -1 },
78
+ { name: 'aboutTypeOf' }
79
+ ],
64
80
  [
65
81
  { 'about.orderNumber': 1, dateCreated: -1 },
66
82
  { name: 'aboutOrderNumber' }
@@ -1,5 +1,5 @@
1
1
  import type { BulkWriteResult } from 'mongodb';
2
- import type { Connection } from 'mongoose';
2
+ import type { Connection, FilterQuery } from 'mongoose';
3
3
  import * as factory from '../factory';
4
4
  type INoteDigitalDocument = factory.creativeWork.noteDigitalDocument.INoteDigitalDocument;
5
5
  type IKeyOfProjection = keyof INoteDigitalDocument;
@@ -9,13 +9,11 @@ type IKeyOfProjection = keyof INoteDigitalDocument;
9
9
  export declare class NoteRepo {
10
10
  private readonly noteModel;
11
11
  constructor(connection: Connection);
12
- static CREATE_MONGO_CONDITIONS(params: factory.creativeWork.noteDigitalDocument.ISearchConditions): any[];
12
+ static CREATE_MONGO_CONDITIONS(params: factory.creativeWork.noteDigitalDocument.ISearchConditions): FilterQuery<import("@chevre/factory/lib/creativeWork/noteDigitalDocument").INoteDigitalDocument>[];
13
13
  /**
14
14
  * 検索
15
15
  */
16
- projectFields(params: factory.creativeWork.noteDigitalDocument.ISearchConditions & {
17
- sort: factory.creativeWork.noteDigitalDocument.ISortOrder;
18
- }, inclusion: IKeyOfProjection[]): Promise<(INoteDigitalDocument & {
16
+ projectFields(params: factory.creativeWork.noteDigitalDocument.ISearchConditions, inclusion: IKeyOfProjection[]): Promise<(INoteDigitalDocument & {
19
17
  id: string;
20
18
  })[]>;
21
19
  /**
@@ -90,14 +90,14 @@ class NoteRepo {
90
90
  }
91
91
  const projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1]))));
92
92
  const query = this.noteModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
93
+ if (typeof ((_a = params.sort) === null || _a === void 0 ? void 0 : _a.dateCreated) === 'number') {
94
+ query.sort({ dateCreated: params.sort.dateCreated });
95
+ }
93
96
  if (typeof params.limit === 'number' && params.limit > 0) {
94
97
  const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
95
98
  query.limit(params.limit)
96
99
  .skip(params.limit * (page - 1));
97
100
  }
98
- if (typeof ((_a = params.sort) === null || _a === void 0 ? void 0 : _a.dateCreated) === 'number') {
99
- query.sort({ dateCreated: params.sort.dateCreated });
100
- }
101
101
  return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
102
102
  .lean() // 2024-09-19~
103
103
  .exec();
@@ -124,7 +124,7 @@ class NoteRepo {
124
124
  }
125
125
  // リソースのユニークネスを保証するfilter
126
126
  const filter = {
127
- typeOf: { $eq: factory.creativeWorkType.NoteDigitalDocument },
127
+ // typeOf: { $eq: factory.creativeWorkType.NoteDigitalDocument },
128
128
  'project.id': { $eq: project.id },
129
129
  'about.id': { $eq: about.id },
130
130
  identifier: { $eq: identifier },