@chevre/domain 20.4.0-alpha.8 → 20.4.0

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 (89) hide show
  1. package/example/src/chevre/aggregateEventReservation.ts +2 -1
  2. package/example/src/chevre/deleteMovieTicketCategoryChargePriceSpecs.ts +21 -0
  3. package/example/src/chevre/{deleteReservationTicketUnderNames.ts → deleteTasksByName.ts} +4 -2
  4. package/example/src/chevre/migrateMoneyTransferPendingTransactionIdentifier.ts +96 -0
  5. package/example/src/chevre/reIndex.ts +25 -0
  6. package/example/src/chevre/searchEventTicketOffers.ts +7 -4
  7. package/example/src/chevre/searchOfferCatalogs.ts +14 -16
  8. package/example/src/chevre/searchOffersByCatalog.ts +2 -1
  9. package/example/src/chevre/searchProductOffers.ts +38 -0
  10. package/example/src/chevre/searchTasks.ts +22 -0
  11. package/example/src/chevre/unsetUnnecessaryFields.ts +6 -11
  12. package/lib/chevre/errorHandler.js +1 -0
  13. package/lib/chevre/repo/accountTransaction.d.ts +0 -5
  14. package/lib/chevre/repo/accountTransaction.js +44 -38
  15. package/lib/chevre/repo/assetTransaction.d.ts +1 -0
  16. package/lib/chevre/repo/assetTransaction.js +5 -0
  17. package/lib/chevre/repo/code.d.ts +0 -7
  18. package/lib/chevre/repo/code.js +0 -17
  19. package/lib/chevre/repo/event.d.ts +5 -4
  20. package/lib/chevre/repo/event.js +8 -17
  21. package/lib/chevre/repo/mongoose/model/accountTransaction.js +0 -5
  22. package/lib/chevre/repo/mongoose/model/member.js +5 -2
  23. package/lib/chevre/repo/mongoose/model/offer.js +19 -9
  24. package/lib/chevre/repo/mongoose/model/priceSpecification.js +19 -52
  25. package/lib/chevre/repo/mongoose/model/product.js +15 -2
  26. package/lib/chevre/repo/offer.d.ts +17 -2
  27. package/lib/chevre/repo/offer.js +77 -44
  28. package/lib/chevre/repo/offerCatalog.d.ts +3 -5
  29. package/lib/chevre/repo/offerCatalog.js +78 -37
  30. package/lib/chevre/repo/priceSpecification.d.ts +11 -0
  31. package/lib/chevre/repo/priceSpecification.js +44 -66
  32. package/lib/chevre/repo/task.d.ts +8 -0
  33. package/lib/chevre/repo/task.js +21 -9
  34. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.d.ts +2 -0
  35. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +93 -96
  36. package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.js +3 -1
  37. package/lib/chevre/service/assetTransaction/moneyTransfer.js +19 -11
  38. package/lib/chevre/service/assetTransaction/pay.js +2 -3
  39. package/lib/chevre/service/assetTransaction/registerService/factory.d.ts +1 -1
  40. package/lib/chevre/service/assetTransaction/registerService/factory.js +6 -3
  41. package/lib/chevre/service/assetTransaction/registerService.js +3 -1
  42. package/lib/chevre/service/assetTransaction/reserve/factory/price.d.ts +1 -1
  43. package/lib/chevre/service/assetTransaction/reserve/factory/price.js +0 -7
  44. package/lib/chevre/service/assetTransaction/reserve/factory.d.ts +2 -2
  45. package/lib/chevre/service/assetTransaction/reserve/factory.js +0 -1
  46. package/lib/chevre/service/assetTransaction/reserve.js +47 -17
  47. package/lib/chevre/service/assetTransaction.d.ts +1 -1
  48. package/lib/chevre/service/code.d.ts +0 -8
  49. package/lib/chevre/service/code.js +1 -38
  50. package/lib/chevre/service/delivery.js +12 -3
  51. package/lib/chevre/service/event.js +0 -3
  52. package/lib/chevre/service/moneyTransfer.d.ts +1 -1
  53. package/lib/chevre/service/moneyTransfer.js +7 -8
  54. package/lib/chevre/service/offer/event/authorize.js +5 -5
  55. package/lib/chevre/service/offer/event/factory.js +1 -1
  56. package/lib/chevre/service/offer/event/searchEventTicketOffers.d.ts +7 -7
  57. package/lib/chevre/service/offer/event/searchEventTicketOffers.js +222 -346
  58. package/lib/chevre/service/offer/factory.d.ts +8 -3
  59. package/lib/chevre/service/offer/factory.js +44 -26
  60. package/lib/chevre/service/offer/moneyTransfer/authorize.js +0 -1
  61. package/lib/chevre/service/offer/moneyTransfer/returnMoneyTransfer.js +0 -1
  62. package/lib/chevre/service/offer/product/searchProductOffers.d.ts +11 -1
  63. package/lib/chevre/service/offer/product/searchProductOffers.js +15 -7
  64. package/lib/chevre/service/offer/product.d.ts +11 -4
  65. package/lib/chevre/service/offer/product.js +59 -50
  66. package/lib/chevre/service/payment/any/factory.js +30 -21
  67. package/lib/chevre/service/payment/any.js +11 -4
  68. package/lib/chevre/service/payment/movieTicket/checkByIdentifier.d.ts +22 -0
  69. package/lib/chevre/service/payment/movieTicket/checkByIdentifier.js +183 -0
  70. package/lib/chevre/service/payment/movieTicket/factory.d.ts +1 -1
  71. package/lib/chevre/service/payment/movieTicket/getCredentials.d.ts +13 -0
  72. package/lib/chevre/service/payment/movieTicket/getCredentials.js +45 -0
  73. package/lib/chevre/service/payment/movieTicket/validation.d.ts +15 -0
  74. package/lib/chevre/service/{assetTransaction/pay → payment}/movieTicket/validation.js +8 -7
  75. package/lib/chevre/service/payment/movieTicket.d.ts +10 -22
  76. package/lib/chevre/service/payment/movieTicket.js +15 -210
  77. package/lib/chevre/service/permit.d.ts +5 -1
  78. package/lib/chevre/service/permit.js +18 -11
  79. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +25 -53
  80. package/lib/chevre/service/task/aggregateScreeningEvent.js +2 -0
  81. package/lib/chevre/service/transaction/moneyTransfer.js +0 -1
  82. package/lib/chevre/service/transaction/orderProgramMembership.js +5 -6
  83. package/lib/chevre/settings.d.ts +4 -0
  84. package/lib/chevre/settings.js +8 -2
  85. package/package.json +3 -3
  86. package/example/src/chevre/migrateAccountTitleAdditionalProperties.ts +0 -157
  87. package/lib/chevre/service/assetTransaction/pay/movieTicket/validation.d.ts +0 -14
  88. package/lib/chevre/service/task/deleteAuthorization.d.ts +0 -6
  89. package/lib/chevre/service/task/deleteAuthorization.js +0 -29
@@ -10,14 +10,17 @@ const writeConcern = { j: true, w: 'majority', wtimeout: 10000 };
10
10
  */
11
11
  const schema = new mongoose.Schema({
12
12
  project: mongoose.SchemaTypes.Mixed,
13
- typeOf: String,
13
+ typeOf: {
14
+ type: String,
15
+ required: true
16
+ },
14
17
  member: mongoose.SchemaTypes.Mixed
15
18
  }, {
16
19
  collection: 'members',
17
20
  id: true,
18
21
  read: 'primaryPreferred',
19
22
  writeConcern: writeConcern,
20
- strict: false,
23
+ strict: true,
21
24
  useNestedStrict: true,
22
25
  timestamps: {
23
26
  createdAt: 'createdAt',
@@ -11,8 +11,6 @@ const writeConcern = { j: true, w: 'majority', wtimeout: 10000 };
11
11
  const schema = new mongoose.Schema({
12
12
  project: mongoose.SchemaTypes.Mixed,
13
13
  _id: String,
14
- // Stringに変更(2022-08-08~)
15
- // identifier: mongoose.SchemaTypes.Mixed,
16
14
  identifier: String,
17
15
  typeOf: String,
18
16
  name: mongoose.SchemaTypes.Mixed,
@@ -21,16 +19,16 @@ const schema = new mongoose.Schema({
21
19
  color: mongoose.SchemaTypes.Mixed,
22
20
  additionalProperty: [mongoose.SchemaTypes.Mixed],
23
21
  alternateName: mongoose.SchemaTypes.Mixed,
24
- acceptedPaymentMethod: mongoose.SchemaTypes.Mixed,
25
- addOn: mongoose.SchemaTypes.Mixed,
26
- availableAddOn: mongoose.SchemaTypes.Mixed,
22
+ // acceptedPaymentMethod: mongoose.SchemaTypes.Mixed, // 削除(2023-02-27~)
23
+ addOn: [mongoose.SchemaTypes.Mixed],
24
+ // availableAddOn: mongoose.SchemaTypes.Mixed, // 削除(2023-02-27~)
27
25
  availability: String,
28
- availabilityEnds: Date,
29
- availabilityStarts: Date,
30
- availableAtOrFrom: mongoose.SchemaTypes.Mixed,
26
+ // availabilityEnds: Date, // 削除(2023-02-27~)
27
+ // availabilityStarts: Date, // 削除(2023-02-27~)
28
+ availableAtOrFrom: [mongoose.SchemaTypes.Mixed],
31
29
  hasMerchantReturnPolicy: mongoose.SchemaTypes.Mixed,
32
30
  itemOffered: mongoose.SchemaTypes.Mixed,
33
- price: Number,
31
+ // price: Number, // 削除(2023-02-27~)
34
32
  priceCurrency: String,
35
33
  priceSpecification: mongoose.SchemaTypes.Mixed,
36
34
  eligibleCustomerType: mongoose.SchemaTypes.Mixed,
@@ -196,6 +194,18 @@ schema.index({ additionalProperty: 1, 'priceSpecification.price': 1 }, {
196
194
  additionalProperty: { $exists: true }
197
195
  }
198
196
  });
197
+ schema.index({ validFrom: 1, 'priceSpecification.price': 1 }, {
198
+ name: 'searchByValidFrom',
199
+ partialFilterExpression: {
200
+ validFrom: { $exists: true }
201
+ }
202
+ });
203
+ schema.index({ validThrough: 1, 'priceSpecification.price': 1 }, {
204
+ name: 'searchByValidThrough',
205
+ partialFilterExpression: {
206
+ validThrough: { $exists: true }
207
+ }
208
+ });
199
209
  mongoose.model(modelName, schema)
200
210
  .on('index',
201
211
  // tslint:disable-next-line:no-single-line-block-comment
@@ -10,29 +10,24 @@ const writeConcern = { j: true, w: 'majority', wtimeout: 10000 };
10
10
  */
11
11
  const schema = new mongoose.Schema({
12
12
  project: mongoose.SchemaTypes.Mixed,
13
- typeOf: {
14
- type: String,
15
- required: true
16
- },
17
- eligibleQuantity: mongoose.SchemaTypes.Mixed,
18
- eligibleTransactionVolume: [mongoose.SchemaTypes.Mixed],
19
- maxPrice: Number,
20
- minPrice: Number,
21
- price: Number,
13
+ typeOf: { type: String, required: true },
14
+ name: mongoose.SchemaTypes.Mixed,
15
+ price: { type: Number, required: true },
22
16
  priceCurrency: String,
23
17
  validFrom: Date,
24
18
  validThrough: Date,
25
19
  valueAddedTaxIncluded: Boolean,
26
- referenceQuantity: mongoose.SchemaTypes.Mixed,
27
- appliesToSoundFormat: String,
28
- appliesToVideoFormat: String,
29
- priceComponent: [mongoose.SchemaTypes.Mixed]
20
+ // referenceQuantity: mongoose.SchemaTypes.Mixed,
21
+ // appliesToSoundFormat: String,
22
+ appliesToCategoryCode: mongoose.SchemaTypes.Mixed,
23
+ appliesToMovieTicket: mongoose.SchemaTypes.Mixed,
24
+ appliesToVideoFormat: String
30
25
  }, {
31
26
  collection: 'priceSpecifications',
32
27
  id: true,
33
28
  read: 'primaryPreferred',
34
29
  writeConcern: writeConcern,
35
- strict: false,
30
+ strict: true,
36
31
  useNestedStrict: true,
37
32
  timestamps: {
38
33
  createdAt: 'createdAt',
@@ -54,53 +49,25 @@ const schema = new mongoose.Schema({
54
49
  exports.schema = schema;
55
50
  schema.index({ createdAt: 1 }, { name: 'searchByCreatedAt' });
56
51
  schema.index({ updatedAt: 1 }, { name: 'searchByUpdatedAt' });
57
- schema.index({ price: 1 }, {
58
- name: 'searchByPrice',
59
- partialFilterExpression: {
60
- price: { $exists: true }
61
- }
62
- });
63
- schema.index({ 'priceComponent.typeOf': 1 }, {
64
- name: 'searchByPriceComponentTypeOf',
65
- partialFilterExpression: {
66
- 'priceComponent.typeOf': { $exists: true }
67
- }
68
- });
69
- schema.index({ 'project.id': 1, price: 1 }, {
70
- name: 'searchByProjectId-v20220721'
71
- });
72
- schema.index({ typeOf: 1, price: 1 }, {
73
- name: 'searchByTypeOf-v2',
74
- partialFilterExpression: {
75
- price: { $exists: true }
76
- }
77
- });
78
- schema.index({ appliesToSoundFormat: 1, price: 1 }, {
79
- name: 'searchByAppliesToSoundFormat',
80
- partialFilterExpression: {
81
- appliesToSoundFormat: { $exists: true },
82
- price: { $exists: true }
83
- }
84
- });
52
+ schema.index({ price: 1 }, { name: 'searchByPrice' });
53
+ schema.index({ 'project.id': 1, price: 1 }, { name: 'searchByProjectId' });
54
+ schema.index({ typeOf: 1, price: 1 }, { name: 'searchByTypeOf' });
85
55
  schema.index({ appliesToVideoFormat: 1, price: 1 }, {
86
56
  name: 'searchByAppliesToVideoFormat',
87
57
  partialFilterExpression: {
88
- appliesToVideoFormat: { $exists: true },
89
- price: { $exists: true }
58
+ appliesToVideoFormat: { $exists: true }
90
59
  }
91
60
  });
92
- schema.index({ appliesToMovieTicketType: 1, price: 1 }, {
93
- name: 'searchByAppliesToMovieTicketType',
61
+ schema.index({ 'appliesToMovieTicket.serviceType': 1, price: 1 }, {
62
+ name: 'searchByAppliesToMovieTicketServiceType',
94
63
  partialFilterExpression: {
95
- appliesToMovieTicketType: { $exists: true },
96
- price: { $exists: true }
64
+ 'appliesToMovieTicket.serviceType': { $exists: true }
97
65
  }
98
66
  });
99
- schema.index({ 'appliesToMovieTicket.serviceType': 1, price: 1 }, {
100
- name: 'searchByAppliesToMovieTicketServiceType',
67
+ schema.index({ 'appliesToMovieTicket.serviceOutput.typeOf': 1, price: 1 }, {
68
+ name: 'searchByAppliesToMovieTicketServiceOutputTypeOf',
101
69
  partialFilterExpression: {
102
- 'appliesToMovieTicket.serviceType': { $exists: true },
103
- price: { $exists: true }
70
+ 'appliesToMovieTicket.serviceOutput.typeOf': { $exists: true }
104
71
  }
105
72
  });
106
73
  schema.index({ appliesToCategoryCode: 1, price: 1 }, {
@@ -13,13 +13,26 @@ const schema = new mongoose.Schema({
13
13
  typeOf: {
14
14
  type: String,
15
15
  required: true
16
- }
16
+ },
17
+ additionalProperty: [mongoose.SchemaTypes.Mixed],
18
+ availableChannel: mongoose.SchemaTypes.Mixed,
19
+ description: mongoose.SchemaTypes.Mixed,
20
+ hasOfferCatalog: mongoose.SchemaTypes.Mixed,
21
+ name: mongoose.SchemaTypes.Mixed,
22
+ offers: [mongoose.SchemaTypes.Mixed],
23
+ productID: {
24
+ type: String,
25
+ required: true
26
+ },
27
+ provider: [mongoose.SchemaTypes.Mixed],
28
+ serviceOutput: mongoose.SchemaTypes.Mixed,
29
+ serviceType: mongoose.SchemaTypes.Mixed
17
30
  }, {
18
31
  collection: 'products',
19
32
  id: true,
20
33
  read: 'primaryPreferred',
21
34
  writeConcern: writeConcern,
22
- strict: false,
35
+ strict: true,
23
36
  useNestedStrict: true,
24
37
  timestamps: {
25
38
  createdAt: 'createdAt',
@@ -1,5 +1,8 @@
1
1
  import { Connection } from 'mongoose';
2
2
  import * as factory from '../factory';
3
+ interface IProjection {
4
+ [key: string]: 0 | 1;
5
+ }
3
6
  /**
4
7
  * オファーリポジトリ
5
8
  */
@@ -23,15 +26,22 @@ export declare class MongoRepository {
23
26
  availableAtOrFrom?: {
24
27
  id?: string;
25
28
  };
29
+ unacceptedPaymentMethod?: string[];
30
+ excludeAppliesToMovieTicket: boolean;
31
+ onlyValid?: boolean;
26
32
  limit?: number;
27
33
  page?: number;
28
34
  sort: boolean;
29
- }): Promise<factory.unitPriceOffer.IUnitPriceOffer[]>;
35
+ projection?: IProjection;
36
+ }): Promise<{
37
+ offers: factory.unitPriceOffer.IUnitPriceOffer[];
38
+ sortedOfferIds: string[];
39
+ }>;
30
40
  findById(params: {
31
41
  id: string;
32
42
  }): Promise<factory.unitPriceOffer.IUnitPriceOffer>;
33
43
  count(params: factory.unitPriceOffer.ISearchConditions): Promise<number>;
34
- search(params: factory.unitPriceOffer.ISearchConditions): Promise<factory.unitPriceOffer.IUnitPriceOffer[]>;
44
+ search(params: factory.unitPriceOffer.ISearchConditions, projection?: IProjection): Promise<factory.unitPriceOffer.IUnitPriceOffer[]>;
35
45
  save(params: factory.unitPriceOffer.IUnitPriceOffer): Promise<factory.unitPriceOffer.IUnitPriceOffer>;
36
46
  saveManyByIdentifier(params: {
37
47
  attributes: factory.unitPriceOffer.IUnitPriceOffer;
@@ -46,4 +56,9 @@ export declare class MongoRepository {
46
56
  };
47
57
  }): Promise<void>;
48
58
  getCursor(conditions: any, projection: any): import("mongoose").QueryCursor<any>;
59
+ unsetUnnecessaryFields(params: {
60
+ filter: any;
61
+ $unset: any;
62
+ }): Promise<import("mongoose").UpdateWriteOpResult>;
49
63
  }
64
+ export {};
@@ -35,7 +35,7 @@ class MongoRepository {
35
35
  }
36
36
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
37
37
  static CREATE_OFFER_MONGO_CONDITIONS(params) {
38
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24;
38
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31;
39
39
  // MongoDB検索条件
40
40
  const andConditions = [];
41
41
  const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
@@ -166,7 +166,15 @@ class MongoRepository {
166
166
  }
167
167
  });
168
168
  }
169
- const appliesToMovieTicketServiceTypeEq = (_w = (_v = (_u = params.priceSpecification) === null || _u === void 0 ? void 0 : _u.appliesToMovieTicket) === null || _v === void 0 ? void 0 : _v.serviceType) === null || _w === void 0 ? void 0 : _w.$eq;
169
+ const appliesToMovieTicketServiceTypeExist = (_w = (_v = (_u = params.priceSpecification) === null || _u === void 0 ? void 0 : _u.appliesToMovieTicket) === null || _v === void 0 ? void 0 : _v.serviceType) === null || _w === void 0 ? void 0 : _w.$exists;
170
+ if (typeof appliesToMovieTicketServiceTypeExist === 'boolean') {
171
+ andConditions.push({
172
+ 'priceSpecification.appliesToMovieTicket.serviceType': {
173
+ $exists: appliesToMovieTicketServiceTypeExist
174
+ }
175
+ });
176
+ }
177
+ const appliesToMovieTicketServiceTypeEq = (_z = (_y = (_x = params.priceSpecification) === null || _x === void 0 ? void 0 : _x.appliesToMovieTicket) === null || _y === void 0 ? void 0 : _y.serviceType) === null || _z === void 0 ? void 0 : _z.$eq;
170
178
  if (typeof appliesToMovieTicketServiceTypeEq === 'string') {
171
179
  andConditions.push({
172
180
  'priceSpecification.appliesToMovieTicket.serviceType': {
@@ -175,7 +183,7 @@ class MongoRepository {
175
183
  }
176
184
  });
177
185
  }
178
- const appliesToMovieTicketServiceOutputTypeOfEq = (_0 = (_z = (_y = (_x = params.priceSpecification) === null || _x === void 0 ? void 0 : _x.appliesToMovieTicket) === null || _y === void 0 ? void 0 : _y.serviceOutput) === null || _z === void 0 ? void 0 : _z.typeOf) === null || _0 === void 0 ? void 0 : _0.$eq;
186
+ const appliesToMovieTicketServiceOutputTypeOfEq = (_3 = (_2 = (_1 = (_0 = params.priceSpecification) === null || _0 === void 0 ? void 0 : _0.appliesToMovieTicket) === null || _1 === void 0 ? void 0 : _1.serviceOutput) === null || _2 === void 0 ? void 0 : _2.typeOf) === null || _3 === void 0 ? void 0 : _3.$eq;
179
187
  if (typeof appliesToMovieTicketServiceOutputTypeOfEq === 'string') {
180
188
  andConditions.push({
181
189
  'priceSpecification.appliesToMovieTicket.serviceOutput.typeOf': {
@@ -184,8 +192,16 @@ class MongoRepository {
184
192
  }
185
193
  });
186
194
  }
195
+ const appliesToMovieTicketServiceOutputTypeOfNin = (_7 = (_6 = (_5 = (_4 = params.priceSpecification) === null || _4 === void 0 ? void 0 : _4.appliesToMovieTicket) === null || _5 === void 0 ? void 0 : _5.serviceOutput) === null || _6 === void 0 ? void 0 : _6.typeOf) === null || _7 === void 0 ? void 0 : _7.$nin;
196
+ if (Array.isArray(appliesToMovieTicketServiceOutputTypeOfNin)) {
197
+ andConditions.push({
198
+ 'priceSpecification.appliesToMovieTicket.serviceOutput.typeOf': {
199
+ $nin: appliesToMovieTicketServiceOutputTypeOfNin
200
+ }
201
+ });
202
+ }
187
203
  if (params.priceSpecification !== undefined && params.priceSpecification !== null) {
188
- const priceSpecificationPriceGte = (_1 = params.priceSpecification.price) === null || _1 === void 0 ? void 0 : _1.$gte;
204
+ const priceSpecificationPriceGte = (_8 = params.priceSpecification.price) === null || _8 === void 0 ? void 0 : _8.$gte;
189
205
  if (typeof priceSpecificationPriceGte === 'number') {
190
206
  andConditions.push({
191
207
  'priceSpecification.price': {
@@ -194,7 +210,7 @@ class MongoRepository {
194
210
  }
195
211
  });
196
212
  }
197
- const priceSpecificationPriceLte = (_2 = params.priceSpecification.price) === null || _2 === void 0 ? void 0 : _2.$lte;
213
+ const priceSpecificationPriceLte = (_9 = params.priceSpecification.price) === null || _9 === void 0 ? void 0 : _9.$lte;
198
214
  if (typeof priceSpecificationPriceLte === 'number') {
199
215
  andConditions.push({
200
216
  'priceSpecification.price': {
@@ -203,7 +219,7 @@ class MongoRepository {
203
219
  }
204
220
  });
205
221
  }
206
- const accountsReceivableGte = (_4 = (_3 = params.priceSpecification.accounting) === null || _3 === void 0 ? void 0 : _3.accountsReceivable) === null || _4 === void 0 ? void 0 : _4.$gte;
222
+ const accountsReceivableGte = (_11 = (_10 = params.priceSpecification.accounting) === null || _10 === void 0 ? void 0 : _10.accountsReceivable) === null || _11 === void 0 ? void 0 : _11.$gte;
207
223
  if (typeof accountsReceivableGte === 'number') {
208
224
  andConditions.push({
209
225
  'priceSpecification.accounting.accountsReceivable': {
@@ -212,7 +228,7 @@ class MongoRepository {
212
228
  }
213
229
  });
214
230
  }
215
- const accountsReceivableLte = (_6 = (_5 = params.priceSpecification.accounting) === null || _5 === void 0 ? void 0 : _5.accountsReceivable) === null || _6 === void 0 ? void 0 : _6.$lte;
231
+ const accountsReceivableLte = (_13 = (_12 = params.priceSpecification.accounting) === null || _12 === void 0 ? void 0 : _12.accountsReceivable) === null || _13 === void 0 ? void 0 : _13.$lte;
216
232
  if (typeof accountsReceivableLte === 'number') {
217
233
  andConditions.push({
218
234
  'priceSpecification.accounting.accountsReceivable': {
@@ -221,7 +237,7 @@ class MongoRepository {
221
237
  }
222
238
  });
223
239
  }
224
- const accountingCodeValueEq = (_9 = (_8 = (_7 = params.priceSpecification.accounting) === null || _7 === void 0 ? void 0 : _7.operatingRevenue) === null || _8 === void 0 ? void 0 : _8.codeValue) === null || _9 === void 0 ? void 0 : _9.$eq;
240
+ const accountingCodeValueEq = (_16 = (_15 = (_14 = params.priceSpecification.accounting) === null || _14 === void 0 ? void 0 : _14.operatingRevenue) === null || _15 === void 0 ? void 0 : _15.codeValue) === null || _16 === void 0 ? void 0 : _16.$eq;
225
241
  if (typeof accountingCodeValueEq === 'string') {
226
242
  andConditions.push({
227
243
  'priceSpecification.accounting.operatingRevenue.codeValue': {
@@ -230,7 +246,7 @@ class MongoRepository {
230
246
  }
231
247
  });
232
248
  }
233
- const accountingCodeValueIn = (_12 = (_11 = (_10 = params.priceSpecification.accounting) === null || _10 === void 0 ? void 0 : _10.operatingRevenue) === null || _11 === void 0 ? void 0 : _11.codeValue) === null || _12 === void 0 ? void 0 : _12.$in;
249
+ const accountingCodeValueIn = (_19 = (_18 = (_17 = params.priceSpecification.accounting) === null || _17 === void 0 ? void 0 : _17.operatingRevenue) === null || _18 === void 0 ? void 0 : _18.codeValue) === null || _19 === void 0 ? void 0 : _19.$in;
234
250
  if (Array.isArray(accountingCodeValueIn)) {
235
251
  andConditions.push({
236
252
  'priceSpecification.accounting.operatingRevenue.codeValue': {
@@ -239,7 +255,7 @@ class MongoRepository {
239
255
  }
240
256
  });
241
257
  }
242
- const referenceQuantityValueEq = (_14 = (_13 = params.priceSpecification.referenceQuantity) === null || _13 === void 0 ? void 0 : _13.value) === null || _14 === void 0 ? void 0 : _14.$eq;
258
+ const referenceQuantityValueEq = (_21 = (_20 = params.priceSpecification.referenceQuantity) === null || _20 === void 0 ? void 0 : _20.value) === null || _21 === void 0 ? void 0 : _21.$eq;
243
259
  if (typeof referenceQuantityValueEq === 'number') {
244
260
  andConditions.push({
245
261
  'priceSpecification.referenceQuantity.value': {
@@ -249,7 +265,7 @@ class MongoRepository {
249
265
  });
250
266
  }
251
267
  }
252
- const availableAtOrFromIdEq = (_16 = (_15 = params.availableAtOrFrom) === null || _15 === void 0 ? void 0 : _15.id) === null || _16 === void 0 ? void 0 : _16.$eq;
268
+ const availableAtOrFromIdEq = (_23 = (_22 = params.availableAtOrFrom) === null || _22 === void 0 ? void 0 : _22.id) === null || _23 === void 0 ? void 0 : _23.$eq;
253
269
  if (typeof availableAtOrFromIdEq === 'string') {
254
270
  andConditions.push({
255
271
  'availableAtOrFrom.id': {
@@ -258,7 +274,7 @@ class MongoRepository {
258
274
  }
259
275
  });
260
276
  }
261
- const availableAtOrFromIdIn = (_18 = (_17 = params.availableAtOrFrom) === null || _17 === void 0 ? void 0 : _17.id) === null || _18 === void 0 ? void 0 : _18.$in;
277
+ const availableAtOrFromIdIn = (_25 = (_24 = params.availableAtOrFrom) === null || _24 === void 0 ? void 0 : _24.id) === null || _25 === void 0 ? void 0 : _25.$in;
262
278
  if (Array.isArray(availableAtOrFromIdIn)) {
263
279
  andConditions.push({
264
280
  'availableAtOrFrom.id': {
@@ -267,7 +283,7 @@ class MongoRepository {
267
283
  }
268
284
  });
269
285
  }
270
- const addOnItemOfferedIdEq = (_21 = (_20 = (_19 = params.addOn) === null || _19 === void 0 ? void 0 : _19.itemOffered) === null || _20 === void 0 ? void 0 : _20.id) === null || _21 === void 0 ? void 0 : _21.$eq;
286
+ const addOnItemOfferedIdEq = (_28 = (_27 = (_26 = params.addOn) === null || _26 === void 0 ? void 0 : _26.itemOffered) === null || _27 === void 0 ? void 0 : _27.id) === null || _28 === void 0 ? void 0 : _28.$eq;
271
287
  if (typeof addOnItemOfferedIdEq === 'string') {
272
288
  andConditions.push({
273
289
  'addOn.itemOffered.id': {
@@ -276,7 +292,7 @@ class MongoRepository {
276
292
  }
277
293
  });
278
294
  }
279
- const hasMerchantReturnPolicyIdEq = (_23 = (_22 = params.hasMerchantReturnPolicy) === null || _22 === void 0 ? void 0 : _22.id) === null || _23 === void 0 ? void 0 : _23.$eq;
295
+ const hasMerchantReturnPolicyIdEq = (_30 = (_29 = params.hasMerchantReturnPolicy) === null || _29 === void 0 ? void 0 : _29.id) === null || _30 === void 0 ? void 0 : _30.$eq;
280
296
  if (typeof hasMerchantReturnPolicyIdEq === 'string') {
281
297
  andConditions.push({
282
298
  'hasMerchantReturnPolicy.id': {
@@ -285,7 +301,7 @@ class MongoRepository {
285
301
  }
286
302
  });
287
303
  }
288
- const additionalPropertyElemMatch = (_24 = params.additionalProperty) === null || _24 === void 0 ? void 0 : _24.$elemMatch;
304
+ const additionalPropertyElemMatch = (_31 = params.additionalProperty) === null || _31 === void 0 ? void 0 : _31.$elemMatch;
289
305
  if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
290
306
  andConditions.push({
291
307
  additionalProperty: {
@@ -294,6 +310,20 @@ class MongoRepository {
294
310
  }
295
311
  });
296
312
  }
313
+ if (params.onlyValid === true) {
314
+ const now = new Date();
315
+ andConditions.push({
316
+ $or: [
317
+ { validFrom: { $exists: false } },
318
+ { validFrom: { $exists: true, $lte: now } }
319
+ ]
320
+ }, {
321
+ $or: [
322
+ { validThrough: { $exists: false } },
323
+ { validThrough: { $exists: true, $gte: now } }
324
+ ]
325
+ });
326
+ }
297
327
  return andConditions;
298
328
  }
299
329
  /**
@@ -324,37 +354,32 @@ class MongoRepository {
324
354
  const sortedOfferIds = (Array.isArray(itemListElements))
325
355
  ? itemListElements.map((element) => element.id)
326
356
  : [];
327
- // const offerCatalog = await this.offerCatalogModel.findById(
328
- // params.offerCatalog.id,
329
- // {
330
- // itemListElement: 1
331
- // }
332
- // )
333
- // .exec()
334
- // .then((doc) => {
335
- // if (doc === null) {
336
- // throw new factory.errors.NotFound(this.offerCatalogModel.modelName);
337
- // }
338
- // return <Pick<factory.offerCatalog.IOfferCatalog, 'itemListElement'>>doc.toObject();
339
- // });
340
- // let sortedOfferIds: string[] = (Array.isArray(offerCatalog.itemListElement))
341
- // ? offerCatalog.itemListElement.map((element) => element.id)
342
- // : [];
343
- // const filteredIds = params.ids;
344
- // if (Array.isArray(filteredIds)) {
345
- // sortedOfferIds = sortedOfferIds.filter((id) => filteredIds.includes(id));
346
- // }
347
357
  let offers = [];
348
358
  if (sortedOfferIds.length > 0) {
349
- offers = yield this.search(Object.assign({ id: { $in: sortedOfferIds } }, (typeof ((_a = params.availableAtOrFrom) === null || _a === void 0 ? void 0 : _a.id) === 'string')
359
+ const searchOffersConditions = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ id: { $in: sortedOfferIds } }, (typeof ((_a = params.availableAtOrFrom) === null || _a === void 0 ? void 0 : _a.id) === 'string')
350
360
  ? { availableAtOrFrom: { id: { $eq: params.availableAtOrFrom.id } } }
351
- : undefined));
361
+ : undefined), { priceSpecification: {
362
+ appliesToMovieTicket: Object.assign(Object.assign({}, (Array.isArray(params.unacceptedPaymentMethod) && params.unacceptedPaymentMethod.length > 0)
363
+ ? {
364
+ serviceOutput: {
365
+ typeOf: { $nin: params.unacceptedPaymentMethod }
366
+ }
367
+ }
368
+ : undefined), (params.excludeAppliesToMovieTicket)
369
+ ? {
370
+ serviceType: { $exists: false }
371
+ }
372
+ : undefined)
373
+ }, onlyValid: params.onlyValid === true }), (typeof params.limit === 'number' && typeof params.page === 'number')
374
+ ? { sort: { _id: factory.sortType.Ascending } }
375
+ : undefined), (typeof params.limit === 'number') ? { limit: params.limit } : undefined), (typeof params.page === 'number') ? { page: params.page } : undefined);
376
+ offers = yield this.search(searchOffersConditions, params.projection);
352
377
  if (params.sort) {
353
378
  // sorting
354
379
  offers = offers.sort((a, b) => sortedOfferIds.indexOf(String(a.id)) - sortedOfferIds.indexOf(String(b.id)));
355
380
  }
356
381
  }
357
- return offers;
382
+ return { offers, sortedOfferIds };
358
383
  });
359
384
  }
360
385
  findById(params) {
@@ -379,14 +404,16 @@ class MongoRepository {
379
404
  .exec();
380
405
  });
381
406
  }
382
- search(params) {
407
+ search(params, projection) {
383
408
  return __awaiter(this, void 0, void 0, function* () {
384
409
  const conditions = MongoRepository.CREATE_OFFER_MONGO_CONDITIONS(params);
385
- const query = this.offerModel.find((conditions.length > 0) ? { $and: conditions } : {}, {
386
- __v: 0,
387
- createdAt: 0,
388
- updatedAt: 0
389
- });
410
+ const positiveProjectionExists = (projection !== undefined && projection !== null)
411
+ ? Object.values(projection)
412
+ .some((value) => value !== 0)
413
+ : false;
414
+ const query = this.offerModel.find((conditions.length > 0) ? { $and: conditions } : {}, (positiveProjectionExists)
415
+ ? projection
416
+ : Object.assign(Object.assign({}, projection), { __v: 0, createdAt: 0, updatedAt: 0 }));
390
417
  if (typeof params.limit === 'number') {
391
418
  const page = (typeof params.page === 'number') ? params.page : 1;
392
419
  query.limit(params.limit)
@@ -475,5 +502,11 @@ class MongoRepository {
475
502
  .sort({ 'priceSpecification.price': factory.sortType.Descending })
476
503
  .cursor();
477
504
  }
505
+ unsetUnnecessaryFields(params) {
506
+ return __awaiter(this, void 0, void 0, function* () {
507
+ return this.offerModel.updateMany(params.filter, { $unset: params.$unset })
508
+ .exec();
509
+ });
510
+ }
478
511
  }
479
512
  exports.MongoRepository = MongoRepository;
@@ -28,11 +28,9 @@ export declare class MongoRepository {
28
28
  };
29
29
  };
30
30
  }): Promise<void>;
31
- findById(params: {
32
- id: string;
33
- }): Promise<factory.offerCatalog.IOfferCatalog>;
34
- count(params: factory.offerCatalog.ISearchConditions): Promise<number>;
35
- search(params: factory.offerCatalog.ISearchConditions): Promise<factory.offerCatalog.IOfferCatalog[]>;
31
+ search(params: factory.offerCatalog.ISearchConditions): Promise<(Omit<factory.offerCatalog.IOfferCatalog, 'itemListElement'> & {
32
+ numberOfItems?: number;
33
+ })[]>;
36
34
  deleteById(params: {
37
35
  id: string;
38
36
  }): Promise<void>;
@@ -178,51 +178,92 @@ class MongoRepository {
178
178
  .exec();
179
179
  });
180
180
  }
181
- findById(params) {
182
- return __awaiter(this, void 0, void 0, function* () {
183
- const doc = yield this.offerCatalogModel.findOne({
184
- _id: params.id
185
- }, {
186
- __v: 0,
187
- createdAt: 0,
188
- updatedAt: 0
189
- })
190
- .exec();
191
- if (doc === null) {
192
- throw new factory.errors.NotFound(this.offerCatalogModel.modelName);
193
- }
194
- return doc.toObject();
195
- });
196
- }
197
- count(params) {
198
- return __awaiter(this, void 0, void 0, function* () {
199
- const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
200
- return this.offerCatalogModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {})
201
- .setOptions({ maxTimeMS: 10000 })
202
- .exec();
203
- });
204
- }
181
+ // public async findById(params: {
182
+ // id: string;
183
+ // }): Promise<factory.offerCatalog.IOfferCatalog> {
184
+ // const doc = await this.offerCatalogModel.findOne(
185
+ // {
186
+ // _id: params.id
187
+ // },
188
+ // {
189
+ // __v: 0,
190
+ // createdAt: 0,
191
+ // updatedAt: 0
192
+ // }
193
+ // )
194
+ // .exec();
195
+ // if (doc === null) {
196
+ // throw new factory.errors.NotFound(this.offerCatalogModel.modelName);
197
+ // }
198
+ // return doc.toObject();
199
+ // }
200
+ // public async count(
201
+ // params: factory.offerCatalog.ISearchConditions
202
+ // ): Promise<number> {
203
+ // const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
204
+ // return this.offerCatalogModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {})
205
+ // .setOptions({ maxTimeMS: 10000 })
206
+ // .exec();
207
+ // }
205
208
  search(params) {
206
209
  return __awaiter(this, void 0, void 0, function* () {
207
210
  const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
208
- const query = this.offerCatalogModel.find((conditions.length > 0) ? { $and: conditions } : {}, {
209
- __v: 0,
210
- createdAt: 0,
211
- updatedAt: 0
211
+ const matchStages = conditions.map((condition) => {
212
+ return { $match: condition };
212
213
  });
214
+ // numberOfItems集計(2023-02-28~)
215
+ const aggregate = this.offerCatalogModel.aggregate([
216
+ ...(params.sort !== undefined) ? [{ $sort: params.sort }] : [],
217
+ ...matchStages,
218
+ {
219
+ $project: {
220
+ _id: 0,
221
+ name: '$name',
222
+ description: '$description',
223
+ project: '$project',
224
+ typeOf: '$typeOf',
225
+ id: '$_id',
226
+ identifier: '$identifier',
227
+ // itemListElement: '$itemListElement',
228
+ itemOffered: '$itemOffered',
229
+ additionalProperty: '$additionalProperty',
230
+ numberOfItems: {
231
+ $cond: {
232
+ if: { $isArray: '$itemListElement' },
233
+ then: { $size: '$itemListElement' },
234
+ else: 0
235
+ }
236
+ }
237
+ }
238
+ }
239
+ ]);
213
240
  if (typeof params.limit === 'number') {
214
241
  const page = (typeof params.page === 'number') ? params.page : 1;
215
- query.limit(params.limit)
242
+ aggregate.limit(params.limit * page)
216
243
  .skip(params.limit * (page - 1));
217
244
  }
218
- // tslint:disable-next-line:no-single-line-block-comment
219
- /* istanbul ignore else */
220
- if (params.sort !== undefined) {
221
- query.sort(params.sort);
222
- }
223
- return query.setOptions({ maxTimeMS: 10000 })
224
- .exec()
225
- .then((docs) => docs.map((doc) => doc.toObject()));
245
+ return aggregate.exec();
246
+ // const query = this.offerCatalogModel.find(
247
+ // (conditions.length > 0) ? { $and: conditions } : {},
248
+ // {
249
+ // __v: 0,
250
+ // createdAt: 0,
251
+ // updatedAt: 0
252
+ // }
253
+ // );
254
+ // if (typeof params.limit === 'number') {
255
+ // const page: number = (typeof params.page === 'number') ? params.page : 1;
256
+ // query.limit(params.limit)
257
+ // .skip(params.limit * (page - 1));
258
+ // }
259
+ // // tslint:disable-next-line:no-single-line-block-comment
260
+ // /* istanbul ignore else */
261
+ // if (params.sort !== undefined) {
262
+ // query.sort(params.sort);
263
+ // }
264
+ // return query.setOptions({ maxTimeMS: 10000 })
265
+ // .exec()
266
+ // .then((docs) => docs.map((doc) => doc.toObject()));
226
267
  });
227
268
  }
228
269
  deleteById(params) {