@chevre/domain 20.4.0-alpha.26 → 20.4.0-alpha.28

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.
@@ -0,0 +1,25 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ async function main() {
7
+ await mongoose.connect(<string>process.env.MONGOLAB_URI);
8
+
9
+ const priceSpecificationRepo = new chevre.repository.PriceSpecification(mongoose.connection);
10
+ const result = await priceSpecificationRepo.reIndex();
11
+ console.log(result);
12
+ }
13
+
14
+ main()
15
+ .then()
16
+ .catch(console.error);
17
+ // setInterval(
18
+ // () => {
19
+ // main()
20
+ // .then()
21
+ // .catch(console.error);
22
+ // },
23
+ // // tslint:disable-next-line:no-magic-numbers
24
+ // 60000
25
+ // );
@@ -0,0 +1,29 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ const PROJECT_ID = process.env.PROJECT_ID;
7
+
8
+ async function main() {
9
+ await mongoose.connect(<string>process.env.MONGOLAB_URI);
10
+
11
+ const catalogRepo = new chevre.repository.OfferCatalog(mongoose.connection);
12
+
13
+ console.log('searching...');
14
+ const catalogs = await catalogRepo.search(
15
+ {
16
+ project: { id: { $eq: PROJECT_ID } },
17
+ identifier: { $eq: '0001' },
18
+ sort: { identifier: chevre.factory.sortType.Descending },
19
+ limit: 2,
20
+ page: 1
21
+ }
22
+ );
23
+ console.log('catalogs found', catalogs.map((catalog) => `${catalog.identifier} ${catalog.numberOfItems}`));
24
+ console.log(catalogs.length);
25
+ }
26
+
27
+ main()
28
+ .then(console.log)
29
+ .catch(console.error);
@@ -32,7 +32,9 @@ export declare class MongoRepository {
32
32
  id: string;
33
33
  }): Promise<factory.offerCatalog.IOfferCatalog>;
34
34
  count(params: factory.offerCatalog.ISearchConditions): Promise<number>;
35
- search(params: factory.offerCatalog.ISearchConditions): Promise<factory.offerCatalog.IOfferCatalog[]>;
35
+ search(params: factory.offerCatalog.ISearchConditions): Promise<(Omit<factory.offerCatalog.IOfferCatalog, 'itemListElement'> & {
36
+ numberOfItems?: number;
37
+ })[]>;
36
38
  deleteById(params: {
37
39
  id: string;
38
40
  }): Promise<void>;
@@ -205,24 +205,62 @@ class MongoRepository {
205
205
  search(params) {
206
206
  return __awaiter(this, void 0, void 0, function* () {
207
207
  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
208
+ const matchStages = conditions.map((condition) => {
209
+ return { $match: condition };
212
210
  });
211
+ // numberOfItems集計(2023-02-28~)
212
+ const aggregate = this.offerCatalogModel.aggregate([
213
+ ...(params.sort !== undefined) ? [{ $sort: params.sort }] : [],
214
+ ...matchStages,
215
+ {
216
+ $project: {
217
+ _id: 0,
218
+ name: '$name',
219
+ description: '$description',
220
+ project: '$project',
221
+ typeOf: '$typeOf',
222
+ id: '$_id',
223
+ identifier: '$identifier',
224
+ // itemListElement: '$itemListElement',
225
+ itemOffered: '$itemOffered',
226
+ additionalProperty: '$additionalProperty',
227
+ numberOfItems: {
228
+ $cond: {
229
+ if: { $isArray: '$itemListElement' },
230
+ then: { $size: '$itemListElement' },
231
+ else: 0
232
+ }
233
+ }
234
+ }
235
+ }
236
+ ]);
213
237
  if (typeof params.limit === 'number') {
214
238
  const page = (typeof params.page === 'number') ? params.page : 1;
215
- query.limit(params.limit)
239
+ aggregate.limit(params.limit * page)
216
240
  .skip(params.limit * (page - 1));
217
241
  }
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()));
242
+ return aggregate.exec();
243
+ // const query = this.offerCatalogModel.find(
244
+ // (conditions.length > 0) ? { $and: conditions } : {},
245
+ // {
246
+ // __v: 0,
247
+ // createdAt: 0,
248
+ // updatedAt: 0
249
+ // }
250
+ // );
251
+ // if (typeof params.limit === 'number') {
252
+ // const page: number = (typeof params.page === 'number') ? params.page : 1;
253
+ // query.limit(params.limit)
254
+ // .skip(params.limit * (page - 1));
255
+ // }
256
+ // // tslint:disable-next-line:no-single-line-block-comment
257
+ // /* istanbul ignore else */
258
+ // if (params.sort !== undefined) {
259
+ // query.sort(params.sort);
260
+ // }
261
+ // return query.setOptions({ maxTimeMS: 10000 })
262
+ // .exec()
263
+ // .then((docs) => docs.map((doc) => doc.toObject()));
226
264
  });
227
265
  }
228
266
  deleteById(params) {
@@ -41,4 +41,5 @@ export declare class MongoRepository {
41
41
  deletedCount?: number | undefined;
42
42
  }>;
43
43
  getCursor(conditions: any, projection: any): import("mongoose").QueryCursor<any>;
44
+ reIndex(): Promise<any>;
44
45
  }
@@ -32,7 +32,7 @@ class MongoRepository {
32
32
  }
33
33
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
34
34
  static CREATE_MONGO_CONDITIONS(params) {
35
- var _a, _b, _c, _d, _e, _f;
35
+ var _a, _b, _c, _d, _e, _f, _g;
36
36
  const andConditions = [];
37
37
  const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
38
38
  if (typeof projectIdEq === 'string') {
@@ -146,6 +146,10 @@ class MongoRepository {
146
146
  }
147
147
  });
148
148
  }
149
+ const priceEq = (_g = params.price) === null || _g === void 0 ? void 0 : _g.$eq;
150
+ if (typeof priceEq === 'number') {
151
+ andConditions.push({ price: { $eq: priceEq } });
152
+ }
149
153
  return andConditions;
150
154
  }
151
155
  count(params) {
@@ -248,5 +252,13 @@ class MongoRepository {
248
252
  .sort({ price: factory.sortType.Ascending })
249
253
  .cursor();
250
254
  }
255
+ reIndex() {
256
+ return __awaiter(this, void 0, void 0, function* () {
257
+ // return this.priceSpecificationModel.collection.name;
258
+ return this.priceSpecificationModel.db.db.command({
259
+ reIndex: this.priceSpecificationModel.collection.name
260
+ });
261
+ });
262
+ }
251
263
  }
252
264
  exports.MongoRepository = MongoRepository;
@@ -118,27 +118,12 @@ function addReservations(params) {
118
118
  // 対応アプリケーション条件追加(2023-01-27~)
119
119
  store: { id: (_a = params.availableAtOrFrom) === null || _a === void 0 ? void 0 : _a.id },
120
120
  onlyValid: true,
121
- sort: false,
122
121
  addSortIndex: false,
123
122
  validateOfferRateLimit: true
124
123
  })(repos);
125
124
  ticketOffers = searchEventTicketOffersResult.ticketOffers;
126
125
  availableOffers = searchEventTicketOffersResult.unitPriceOffers;
127
126
  }
128
- // 冗長なfindOffersByOfferCatalogId処理を削除(2023-01-26~)
129
- // let availableOffers: factory.unitPriceOffer.IUnitPriceOffer[] = [];
130
- // // 興行設定があれば興行のカタログを参照する(2022-08-31~)
131
- // const eventOffers = <factory.event.screeningEvent.IOffer | undefined>event.offers;
132
- // if (typeof eventOffers?.itemOffered?.id === 'string') {
133
- // const eventService = <factory.product.IProduct>await repos.product.findById({ id: eventOffers.itemOffered.id });
134
- // if (typeof eventService.hasOfferCatalog?.id === 'string') {
135
- // availableOffers = await repos.offer.findOffersByOfferCatalogId({
136
- // offerCatalog: { id: eventService.hasOfferCatalog.id }
137
- // });
138
- // }
139
- // } else {
140
- // throw new factory.errors.NotFound('event.offers.itemOffered.id');
141
- // }
142
127
  const availableSeatOffers = yield searchAvailableSeatOffers({ acceptedOffers, event: { id: event.id } })(repos);
143
128
  // 仮予約作成
144
129
  const { acceptedOffers4transactionObject, objectSubReservations } = yield createAcceptedOffers4transactionObject({
@@ -225,7 +225,6 @@ function validateAcceptedOffers(params) {
225
225
  event: { id: params.event.id },
226
226
  store: params.store,
227
227
  onlyValid: true,
228
- sort: false,
229
228
  addSortIndex: false,
230
229
  validateOfferRateLimit: true
231
230
  })(repos);
@@ -73,7 +73,6 @@ declare function searchEventTicketOffers(params: {
73
73
  };
74
74
  limit?: number;
75
75
  page?: number;
76
- sort: boolean;
77
76
  addSortIndex: boolean;
78
77
  validateOfferRateLimit: boolean;
79
78
  }): ISearchEventTicketOffersOperation<{
@@ -26,12 +26,18 @@ function searchTicketOffersByItemOffered(params) {
26
26
  if (typeof catalogId !== 'string') {
27
27
  throw new factory.errors.NotFound('itemOffered.hasOfferCatalog');
28
28
  }
29
- const findOffersByOfferCatalogIdResult = yield repos.offer.findOffersByOfferCatalogId(Object.assign({ ids: params.ids, offerCatalog: { id: catalogId }, availableAtOrFrom: { id: (_d = params.store) === null || _d === void 0 ? void 0 : _d.id }, unacceptedPaymentMethod: params.unacceptedPaymentMethod, excludeAppliesToMovieTicket: params.excludeAppliesToMovieTicket, onlyValid: params.onlyValid === true, sort: params.sort }, (!params.sort)
30
- ? {
31
- limit: params.limit,
32
- page: params.page
33
- }
34
- : undefined));
29
+ const findOffersByOfferCatalogIdResult = yield repos.offer.findOffersByOfferCatalogId({
30
+ ids: params.ids,
31
+ offerCatalog: { id: catalogId },
32
+ availableAtOrFrom: { id: (_d = params.store) === null || _d === void 0 ? void 0 : _d.id },
33
+ unacceptedPaymentMethod: params.unacceptedPaymentMethod,
34
+ excludeAppliesToMovieTicket: params.excludeAppliesToMovieTicket,
35
+ onlyValid: params.onlyValid === true,
36
+ // Mongoのpagingを利用するオプション(2023-02-21~)
37
+ limit: params.limit,
38
+ page: params.page,
39
+ sort: false
40
+ });
35
41
  const availableOffers = findOffersByOfferCatalogIdResult.offers;
36
42
  const sortedOfferIds = findOffersByOfferCatalogIdResult.sortedOfferIds;
37
43
  return { availableOffers, sortedOfferIds };
@@ -63,7 +69,6 @@ function searchEventTicketOffersByEvent(params) {
63
69
  store: params.store,
64
70
  limit: params.limit,
65
71
  page: params.page,
66
- sort: params.sort,
67
72
  onlyValid: params.onlyValid,
68
73
  unacceptedPaymentMethod,
69
74
  excludeAppliesToMovieTicket
@@ -271,7 +276,6 @@ function searchEventTicketOffers(params) {
271
276
  store: params.store,
272
277
  limit: params.limit,
273
278
  page: params.page,
274
- sort: params.sort,
275
279
  addSortIndex: params.addSortIndex,
276
280
  validateOfferRateLimit: params.validateOfferRateLimit,
277
281
  onlyValid: params.onlyValid === true
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  ],
11
11
  "dependencies": {
12
12
  "@chevre/factory": "4.291.0",
13
- "@cinerino/sdk": "3.140.0-alpha.19",
13
+ "@cinerino/sdk": "3.141.0",
14
14
  "@motionpicture/coa-service": "9.2.0",
15
15
  "@motionpicture/gmo-service": "5.2.0",
16
16
  "@sendgrid/mail": "6.4.0",
@@ -120,5 +120,5 @@
120
120
  "postversion": "git push origin --tags",
121
121
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
122
122
  },
123
- "version": "20.4.0-alpha.26"
123
+ "version": "20.4.0-alpha.28"
124
124
  }