@chevre/domain 21.8.0-alpha.67 → 21.8.0-alpha.68

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.
@@ -16,6 +16,13 @@ async function main() {
16
16
  );
17
17
  console.log(catalog);
18
18
  console.log(catalog.itemListElement.length);
19
+
20
+ const firstElement = await offerCatalogRepo.findFirstItemListElementById(
21
+ {
22
+ id: '0001'
23
+ }
24
+ );
25
+ console.log('firstElement:', firstElement);
19
26
  }
20
27
 
21
28
  main()
@@ -16,11 +16,12 @@ async function main() {
16
16
  });
17
17
  await client.connect();
18
18
 
19
- await mongoose.connect(<string>process.env.MONGOLAB_URI);
19
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
20
20
 
21
21
  const eventRepo = new chevre.repository.Event(mongoose.connection);
22
22
  const priceSpecificationRepo = new chevre.repository.PriceSpecification(mongoose.connection);
23
23
  const offerRepo = new chevre.repository.Offer(mongoose.connection);
24
+ const offerCatalogRepo = new chevre.repository.OfferCatalog(mongoose.connection);
24
25
  const offerRateLimitRepo = new chevre.repository.rateLimit.Offer(client);
25
26
  const productRepo = new chevre.repository.Product(mongoose.connection);
26
27
 
@@ -36,6 +37,7 @@ async function main() {
36
37
  })({
37
38
  event: eventRepo,
38
39
  offer: offerRepo,
40
+ offerCatalog: offerCatalogRepo,
39
41
  offerRateLimit: offerRateLimitRepo,
40
42
  priceSpecification: priceSpecificationRepo,
41
43
  product: productRepo
@@ -9,19 +9,21 @@ async function main() {
9
9
 
10
10
  const offerRepo = new chevre.repository.Offer(mongoose.connection);
11
11
 
12
- const { offers } = await offerRepo.searchByOfferCatalogIdWithSortIndex({
13
- limit: 100,
12
+ const { offers, sortedOfferIds } = await offerRepo.searchByOfferCatalogIdWithSortIndex({
13
+ limit: 10,
14
14
  page: 1,
15
15
  // ids: ['xx', 'xxx', '1001', '901'],
16
- offerCatalog: {
17
- id: '0004'
16
+ subOfferCatalog: {
17
+ id: 'xxx'
18
18
  },
19
19
  excludeAppliesToMovieTicket: false,
20
20
  useIncludeInDataCatalog: true
21
21
  });
22
22
  // console.log(offers);
23
23
  console.log(offers.map((offer) => {
24
- return `${offer.project?.id} ${offer.identifier} ${offer.priceSpecification?.price} ${offer.name?.ja} ${offer.id} ${offer.offerIndex}`;
24
+ const sortIndex = sortedOfferIds.findIndex((s) => s === offer.id);
25
+
26
+ return `${offer.project?.id} ${offer.identifier} ${offer.priceSpecification?.price} ${offer.name?.ja} ${offer.id} ${offer.offerIndex} ${sortIndex}`;
25
27
  }));
26
28
  console.log(offers.length);
27
29
  console.log('USE_AGGREGATE_OFFERS_AS_PRIMARY:', process.env.USE_AGGREGATE_OFFERS_AS_PRIMARY);
@@ -28,7 +28,10 @@ export declare class MongoRepository {
28
28
  * 必ずカタログデータから単価オファーIDを参照する
29
29
  */
30
30
  searchAllByOfferCatalogId(params: {
31
- offerCatalog: {
31
+ subOfferCatalog: {
32
+ /**
33
+ * サブカタログID
34
+ */
32
35
  id: string;
33
36
  };
34
37
  projection?: IProjection;
@@ -44,7 +47,10 @@ export declare class MongoRepository {
44
47
  * 指定したIDの単価オファーだけ取得
45
48
  */
46
49
  ids: string[];
47
- offerCatalog: {
50
+ subOfferCatalog: {
51
+ /**
52
+ * サブカタログID
53
+ */
48
54
  id: string;
49
55
  };
50
56
  availableAtOrFrom?: {
@@ -64,7 +70,10 @@ export declare class MongoRepository {
64
70
  * カタログ内ソートインデックスはsortedOfferIdsで判断する
65
71
  */
66
72
  searchByOfferCatalogIdWithSortIndex(params: {
67
- offerCatalog: {
73
+ subOfferCatalog: {
74
+ /**
75
+ * サブカタログID
76
+ */
68
77
  id: string;
69
78
  };
70
79
  availableAtOrFrom?: {
@@ -441,7 +441,7 @@ class MongoRepository {
441
441
  */
442
442
  searchAllByOfferCatalogId(params) {
443
443
  return __awaiter(this, void 0, void 0, function* () {
444
- const matchStages = [{ $match: { _id: { $eq: params.offerCatalog.id } } }];
444
+ const matchStages = [{ $match: { _id: { $eq: params.subOfferCatalog.id } } }];
445
445
  const itemListElements = yield this.offerCatalogModel.aggregate([
446
446
  { $unwind: '$itemListElement' },
447
447
  ...matchStages,
@@ -483,7 +483,7 @@ class MongoRepository {
483
483
  aggregateOfferIds = searchDistinctAggregateOfferIdsResult;
484
484
  }
485
485
  // aggregateで再実装(2023-01-26~)
486
- const matchStages = [{ $match: { _id: { $eq: params.offerCatalog.id } } }];
486
+ const matchStages = [{ $match: { _id: { $eq: params.subOfferCatalog.id } } }];
487
487
  if (Array.isArray(aggregateOfferIds)) {
488
488
  matchStages.push({ $match: { 'itemListElement.id': { $exists: true, $in: aggregateOfferIds } } });
489
489
  }
@@ -548,7 +548,7 @@ class MongoRepository {
548
548
  // aggregateOfferIds = searchDistinctAggregateOfferIdsResult;
549
549
  // }
550
550
  // aggregateで再実装(2023-01-26~)
551
- const matchStages = [{ $match: { _id: { $eq: params.offerCatalog.id } } }];
551
+ const matchStages = [{ $match: { _id: { $eq: params.subOfferCatalog.id } } }];
552
552
  // if (Array.isArray(aggregateOfferIds)) {
553
553
  // matchStages.push({ $match: { 'itemListElement.id': { $exists: true, $in: aggregateOfferIds } } });
554
554
  // }
@@ -569,7 +569,7 @@ class MongoRepository {
569
569
  let offers = [];
570
570
  if (sortedOfferIds.length > 0) {
571
571
  const searchOffersConditions = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (params.useIncludeInDataCatalog)
572
- ? { includedInDataCatalog: { id: { $in: [params.offerCatalog.id] } } }
572
+ ? { includedInDataCatalog: { id: { $in: [params.subOfferCatalog.id] } } }
573
573
  : { parentOffer: { id: { $in: sortedOfferIds } } }), (typeof ((_a = params.availableAtOrFrom) === null || _a === void 0 ? void 0 : _a.id) === 'string')
574
574
  ? { availableAtOrFrom: { id: { $eq: params.availableAtOrFrom.id } } }
575
575
  : undefined), { priceSpecification: {
@@ -82,12 +82,22 @@ export declare class MongoRepository {
82
82
  };
83
83
  }): Promise<import("mongodb").UpdateResult | undefined>;
84
84
  search(params: factory.offerCatalog.ISearchConditions): Promise<IAggregatedOfferCatalog[]>;
85
+ /**
86
+ * 強制的に親カタログのみ検索する
87
+ */
88
+ searchParentCatalogsForcibly(params: factory.offerCatalog.ISearchConditions): Promise<IAggregatedOfferCatalog[]>;
85
89
  findItemListElementById(params: {
86
90
  id: string;
87
91
  project: {
88
92
  id: string;
89
93
  };
90
94
  }): Promise<Pick<factory.offerCatalog.IOfferCatalog, 'itemListElement'>>;
95
+ /**
96
+ * 一つ目のitemListElementを取得する
97
+ */
98
+ findFirstItemListElementById(params: {
99
+ id: string;
100
+ }): Promise<factory.offerCatalog.IItemListElement>;
91
101
  deleteById(params: {
92
102
  id: string;
93
103
  }): Promise<void>;
@@ -282,6 +282,14 @@ class MongoRepository {
282
282
  return aggregate.exec();
283
283
  });
284
284
  }
285
+ /**
286
+ * 強制的に親カタログのみ検索する
287
+ */
288
+ searchParentCatalogsForcibly(params) {
289
+ return __awaiter(this, void 0, void 0, function* () {
290
+ return this.search(Object.assign(Object.assign({}, params), { itemListElement: Object.assign(Object.assign({}, params.itemListElement), { typeOf: { $eq: factory.offerType.Offer } }) }));
291
+ });
292
+ }
285
293
  findItemListElementById(params) {
286
294
  return __awaiter(this, void 0, void 0, function* () {
287
295
  const doc = yield this.offerCatalogModel.findOne({
@@ -295,6 +303,30 @@ class MongoRepository {
295
303
  return doc.toObject();
296
304
  });
297
305
  }
306
+ /**
307
+ * 一つ目のitemListElementを取得する
308
+ */
309
+ findFirstItemListElementById(params) {
310
+ var _a;
311
+ return __awaiter(this, void 0, void 0, function* () {
312
+ const aggregate = this.offerCatalogModel.aggregate([
313
+ {
314
+ $match: { _id: { $eq: params.id } }
315
+ },
316
+ {
317
+ $project: {
318
+ firstElement: { $first: '$itemListElement' }
319
+ }
320
+ }
321
+ ]);
322
+ const catalogs = yield aggregate.exec();
323
+ const firstElement = (_a = catalogs.shift()) === null || _a === void 0 ? void 0 : _a.firstElement;
324
+ if (firstElement === undefined) {
325
+ throw new factory.errors.NotFound(this.offerCatalogModel.modelName);
326
+ }
327
+ return firstElement;
328
+ });
329
+ }
298
330
  deleteById(params) {
299
331
  return __awaiter(this, void 0, void 0, function* () {
300
332
  yield this.offerCatalogModel.findOneAndRemove({
@@ -1,12 +1,14 @@
1
1
  import { MongoRepository as ActionRepo } from '../../../repo/action';
2
2
  import { MongoRepository as EventRepo } from '../../../repo/event';
3
3
  import { MongoRepository as OfferRepo } from '../../../repo/offer';
4
+ import { MongoRepository as OfferCatalogRepo } from '../../../repo/offerCatalog';
4
5
  import { MongoRepository as PlaceRepo } from '../../../repo/place';
5
6
  import { MongoRepository as ProductRepo } from '../../../repo/product';
6
7
  export type IAggregateOperation<T> = (repos: {
7
8
  action: ActionRepo;
8
9
  event: EventRepo;
9
10
  offer: OfferRepo;
11
+ offerCatalog: OfferCatalogRepo;
10
12
  place: PlaceRepo;
11
13
  product: ProductRepo;
12
14
  }) => Promise<T>;
@@ -1,5 +1,6 @@
1
1
  import { IMinimizedIndividualEvent } from '../../../repo/event';
2
2
  import { MongoRepository as OfferRepo } from '../../../repo/offer';
3
+ import { MongoRepository as OfferCatalogRepo } from '../../../repo/offerCatalog';
3
4
  import { MongoRepository as ProductRepo } from '../../../repo/product';
4
5
  import * as factory from '../../../factory';
5
6
  /**
@@ -9,6 +10,7 @@ import * as factory from '../../../factory';
9
10
  export declare function findEventOffers(params: {
10
11
  event: IMinimizedIndividualEvent<factory.eventType.ScreeningEvent> | IMinimizedIndividualEvent<factory.eventType.Event>;
11
12
  }): (repos: {
12
- product: ProductRepo;
13
13
  offer: OfferRepo;
14
+ offerCatalog: OfferCatalogRepo;
15
+ product: ProductRepo;
14
16
  }) => Promise<factory.unitPriceOffer.IUnitPriceOffer[]>;
@@ -24,9 +24,16 @@ function findEventOffers(params) {
24
24
  const eventOffers = params.event.offers;
25
25
  if (typeof ((_a = eventOffers === null || eventOffers === void 0 ? void 0 : eventOffers.itemOffered) === null || _a === void 0 ? void 0 : _a.id) === 'string') {
26
26
  const eventService = yield repos.product.findById({ id: eventOffers.itemOffered.id }, ['hasOfferCatalog'], []);
27
- if (typeof ((_b = eventService.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.id) === 'string') {
27
+ const offerCatalogId = (_b = eventService.hasOfferCatalog) === null || _b === void 0 ? void 0 : _b.id;
28
+ if (typeof offerCatalogId === 'string') {
29
+ // サブカタログIDを決定
30
+ let subOfferCatalogId = offerCatalogId;
31
+ const offerCatalogFirstElement = yield repos.offerCatalog.findFirstItemListElementById({ id: offerCatalogId });
32
+ if (offerCatalogFirstElement.typeOf === 'OfferCatalog') {
33
+ subOfferCatalogId = offerCatalogFirstElement.id;
34
+ }
28
35
  const { offers } = yield repos.offer.searchAllByOfferCatalogId({
29
- offerCatalog: { id: eventService.hasOfferCatalog.id }
36
+ subOfferCatalog: { id: subOfferCatalogId }
30
37
  });
31
38
  availableOffers = offers;
32
39
  }
@@ -1,5 +1,6 @@
1
1
  import { MongoRepository as EventRepo } from '../../../repo/event';
2
2
  import { MongoRepository as OfferRepo } from '../../../repo/offer';
3
+ import { MongoRepository as OfferCatalogRepo } from '../../../repo/offerCatalog';
3
4
  import { MongoRepository as PriceSpecificationRepo } from '../../../repo/priceSpecification';
4
5
  import { MongoRepository as ProductRepo } from '../../../repo/product';
5
6
  import { RedisRepository as OfferRateLimitRepo } from '../../../repo/rateLimit/offer';
@@ -8,6 +9,7 @@ interface ISearchEventTicketOffersRepos {
8
9
  event: EventRepo;
9
10
  priceSpecification: PriceSpecificationRepo;
10
11
  offer: OfferRepo;
12
+ offerCatalog: OfferCatalogRepo;
11
13
  offerRateLimit: OfferRateLimitRepo;
12
14
  product: ProductRepo;
13
15
  }
@@ -26,6 +26,12 @@ function searchTicketOffersByItemOffered(params) {
26
26
  if (typeof catalogId !== 'string') {
27
27
  throw new factory.errors.NotFound('itemOffered.hasOfferCatalog');
28
28
  }
29
+ // サブカタログIDを決定
30
+ let subOfferCatalogId = catalogId;
31
+ const offerCatalogFirstElement = yield repos.offerCatalog.findFirstItemListElementById({ id: catalogId });
32
+ if (offerCatalogFirstElement.typeOf === 'OfferCatalog') {
33
+ subOfferCatalogId = offerCatalogFirstElement.id;
34
+ }
29
35
  if (params.withSortIndex) {
30
36
  // addSortIndexの場合はid指定廃止(2023-09-13~)
31
37
  if (Array.isArray(params.ids)) {
@@ -33,7 +39,7 @@ function searchTicketOffersByItemOffered(params) {
33
39
  }
34
40
  const { offers, sortedOfferIds } = yield repos.offer.searchByOfferCatalogIdWithSortIndex({
35
41
  // ids: params.ids,
36
- offerCatalog: { id: catalogId },
42
+ subOfferCatalog: { id: subOfferCatalogId },
37
43
  availableAtOrFrom: { id: (_d = params.store) === null || _d === void 0 ? void 0 : _d.id },
38
44
  unacceptedPaymentMethod: params.unacceptedPaymentMethod,
39
45
  excludeAppliesToMovieTicket: params.excludeAppliesToMovieTicket,
@@ -51,7 +57,7 @@ function searchTicketOffersByItemOffered(params) {
51
57
  }
52
58
  const { offers } = yield repos.offer.searchByIdsAndOfferCatalogId({
53
59
  ids: params.ids,
54
- offerCatalog: { id: catalogId },
60
+ subOfferCatalog: { id: subOfferCatalogId },
55
61
  availableAtOrFrom: { id: (_e = params.store) === null || _e === void 0 ? void 0 : _e.id },
56
62
  unacceptedPaymentMethod: params.unacceptedPaymentMethod,
57
63
  excludeAppliesToMovieTicket: params.excludeAppliesToMovieTicket,
@@ -1,5 +1,6 @@
1
1
  import * as factory from '../../../factory';
2
2
  import { MongoRepository as OfferRepo } from '../../../repo/offer';
3
+ import { MongoRepository as OfferCatalogRepo } from '../../../repo/offerCatalog';
3
4
  import { MongoRepository as ProductRepo } from '../../../repo/product';
4
5
  type ITicketOffer = factory.product.ITicketOffer & {
5
6
  parentOffer?: {
@@ -27,6 +28,7 @@ export declare function searchProductOffers(params: {
27
28
  page?: number;
28
29
  }): (repos: {
29
30
  offer: OfferRepo;
31
+ offerCatalog: OfferCatalogRepo;
30
32
  product: ProductRepo;
31
33
  }) => Promise<ITicketOffer[]>;
32
34
  export {};
@@ -15,6 +15,7 @@ const settings_1 = require("../../../settings");
15
15
  /**
16
16
  * プロダクトオファーを検索する
17
17
  */
18
+ // tslint:disable-next-line:max-func-body-length
18
19
  function searchProductOffers(params) {
19
20
  return (repos) => __awaiter(this, void 0, void 0, function* () {
20
21
  var _a;
@@ -24,6 +25,12 @@ function searchProductOffers(params) {
24
25
  if (typeof offerCatalogId !== 'string') {
25
26
  return [];
26
27
  }
28
+ // サブカタログIDを決定
29
+ let subOfferCatalogId = offerCatalogId;
30
+ const offerCatalogFirstElement = yield repos.offerCatalog.findFirstItemListElementById({ id: offerCatalogId });
31
+ if (offerCatalogFirstElement.typeOf === 'OfferCatalog') {
32
+ subOfferCatalogId = offerCatalogFirstElement.id;
33
+ }
27
34
  let offers;
28
35
  let sortedOfferIds;
29
36
  if (params.addSortIndex) {
@@ -33,7 +40,7 @@ function searchProductOffers(params) {
33
40
  }
34
41
  const searchByOfferCatalogIdResult = yield repos.offer.searchByOfferCatalogIdWithSortIndex({
35
42
  // ids: params.ids,
36
- offerCatalog: { id: offerCatalogId },
43
+ subOfferCatalog: { id: subOfferCatalogId },
37
44
  excludeAppliesToMovieTicket: false,
38
45
  limit: params.limit,
39
46
  page: params.page,
@@ -51,7 +58,7 @@ function searchProductOffers(params) {
51
58
  }
52
59
  const searchByOfferCatalogIdResult = yield repos.offer.searchByIdsAndOfferCatalogId({
53
60
  ids: params.ids,
54
- offerCatalog: { id: offerCatalogId },
61
+ subOfferCatalog: { id: subOfferCatalogId },
55
62
  excludeAppliesToMovieTicket: false,
56
63
  limit: params.limit,
57
64
  page: params.page,
@@ -58,6 +58,7 @@ export declare function search(params: {
58
58
  useIncludeInDataCatalog: boolean;
59
59
  }): (repos: {
60
60
  offer: OfferRepo;
61
+ offerCatalog: OfferCatalogRepo;
61
62
  product: ProductRepo;
62
63
  }) => Promise<{
63
64
  offers: factory.product.ITicketOffer[];
@@ -14,6 +14,7 @@ const factory = require("../../factory");
14
14
  const action_1 = require("../../repo/action");
15
15
  const event_1 = require("../../repo/event");
16
16
  const offer_1 = require("../../repo/offer");
17
+ const offerCatalog_1 = require("../../repo/offerCatalog");
17
18
  const place_1 = require("../../repo/place");
18
19
  const product_1 = require("../../repo/product");
19
20
  const AggregationService = require("../aggregation");
@@ -29,6 +30,7 @@ function call(data) {
29
30
  action: new action_1.MongoRepository(settings.connection),
30
31
  event: new event_1.MongoRepository(settings.connection),
31
32
  offer: new offer_1.MongoRepository(settings.connection),
33
+ offerCatalog: new offerCatalog_1.MongoRepository(settings.connection),
32
34
  place: new place_1.MongoRepository(settings.connection),
33
35
  product: new product_1.MongoRepository(settings.connection)
34
36
  });
package/package.json CHANGED
@@ -9,8 +9,8 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.329.0-alpha.15",
13
- "@cinerino/sdk": "3.167.0-alpha.6",
12
+ "@chevre/factory": "4.329.0",
13
+ "@cinerino/sdk": "3.167.0-alpha.9",
14
14
  "@motionpicture/coa-service": "9.2.0",
15
15
  "@motionpicture/gmo-service": "5.2.0",
16
16
  "@sendgrid/mail": "6.4.0",
@@ -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.8.0-alpha.67"
120
+ "version": "21.8.0-alpha.68"
121
121
  }
@@ -1,27 +0,0 @@
1
- // tslint:disable:no-console
2
- import * as mongoose from 'mongoose';
3
-
4
- import { chevre } from '../../../lib/index';
5
-
6
- // tslint:disable-next-line:max-func-body-length
7
- async function main() {
8
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
9
-
10
- const offerRepo = new chevre.repository.Offer(mongoose.connection);
11
-
12
- const result = await offerRepo.sync2aggregateOffer({
13
- id: {
14
- $in: ['1001']
15
- },
16
- project: {
17
- id: String(process.env.PROJECT_ID)
18
- },
19
- isDeleted: false,
20
- typeOf: chevre.factory.offerType.AggregateOffer
21
- });
22
- console.log(result);
23
- }
24
-
25
- main()
26
- .then(console.log)
27
- .catch(console.error);
@@ -1,25 +0,0 @@
1
- // tslint:disable:no-console
2
- // import * as redis from 'redis';
3
- import * as mongoose from 'mongoose';
4
-
5
- import { chevre } from '../../../lib/index';
6
-
7
- const project = { id: String(process.env.PROJECT_ID) };
8
-
9
- async function main() {
10
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
11
-
12
- const offerRepo = new chevre.repository.Offer(mongoose.connection);
13
-
14
- const result = await offerRepo.sync2aggregateOffer({
15
- project: { id: project.id },
16
- identifier: { $in: ['COA-120-15'] },
17
- isDeleted: false,
18
- typeOf: chevre.factory.offerType.Offer
19
- });
20
- console.log(result);
21
- }
22
-
23
- main()
24
- .then(console.log)
25
- .catch(console.error);