@chevre/domain 21.8.0-alpha.66 → 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()
@@ -11,11 +11,44 @@ async function main() {
11
11
 
12
12
  const offerCatalogRepo = new chevre.repository.OfferCatalog(mongoose.connection);
13
13
 
14
- await offerCatalogRepo.optimizeAll();
14
+ const cursor = offerCatalogRepo.getCursor(
15
+ {
16
+ // 'project.id': { $eq: project.id }
17
+ },
18
+ {
19
+ __v: 0,
20
+ createdAt: 0,
21
+ updatedAt: 0
22
+ }
23
+ );
24
+ console.log('catalogs found');
25
+
26
+ let i = 0;
27
+ let updateCount = 0;
28
+ await cursor.eachAsync(async (doc) => {
29
+ i += 1;
30
+ const { _id, ...offerCatalog } = <chevre.factory.offerCatalog.IOfferCatalog & { _id: string }>doc.toObject();
31
+
32
+ let itemListElementTypeOfEqOffer = false;
33
+ itemListElementTypeOfEqOffer = offerCatalog.itemListElement.every((element) => element.typeOf === chevre.factory.offerType.Offer);
34
+ if (!itemListElementTypeOfEqOffer) {
35
+ throw new Error(`itemListElementTypeOfEqOffer: false. ${offerCatalog.project.id} ${offerCatalog.id}`);
36
+ }
37
+
38
+ const itemOfferedKeys = Object.keys(offerCatalog.itemOffered);
39
+ console.log(itemOfferedKeys);
40
+ if (itemOfferedKeys.length > 1) {
41
+ console.log(itemOfferedKeys, offerCatalog.project.id, offerCatalog.id);
42
+ updateCount += 1;
43
+ }
44
+ });
15
45
 
46
+ console.log(i, 'catalogs checked');
47
+ console.log(updateCount, 'catalogs synced');
48
+
49
+ await offerCatalogRepo.optimizeAll();
16
50
  console.log('optmized');
17
51
  }
18
-
19
52
  main()
20
53
  .then()
21
54
  .catch(console.error);
@@ -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
@@ -4,9 +4,12 @@ import * as mongoose from 'mongoose';
4
4
  import { chevre } from '../../../lib/index';
5
5
 
6
6
  const PROJECT_ID = process.env.PROJECT_ID;
7
+ mongoose.Model.on('index', (...args) => {
8
+ console.error('******** index event emitted. ********\n', args);
9
+ });
7
10
 
8
11
  async function main() {
9
- await mongoose.connect(<string>process.env.MONGOLAB_URI);
12
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: true });
10
13
 
11
14
  const catalogRepo = new chevre.repository.OfferCatalog(mongoose.connection);
12
15
 
@@ -17,10 +20,11 @@ async function main() {
17
20
  identifier: { $eq: '0001' },
18
21
  sort: { identifier: chevre.factory.sortType.Descending },
19
22
  limit: 2,
20
- page: 1
23
+ page: 1,
24
+ itemListElement: { typeOf: { $eq: 'Offer' } }
21
25
  }
22
26
  );
23
- console.log('catalogs found', catalogs.map((catalog) => `${catalog.identifier} ${catalog.numberOfItems}`));
27
+ console.log('catalogs found', catalogs.map((catalog) => `${catalog.identifier} ${catalog.numberOfItems} ${catalog.itemListElementTypeOf}`));
24
28
  console.log(catalogs.length);
25
29
  }
26
30
 
@@ -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);
@@ -4,6 +4,9 @@ import * as mongoose from 'mongoose';
4
4
  import { chevre } from '../../../lib/index';
5
5
 
6
6
  // const project = { id: String(process.env.PROJECT_ID) };
7
+ mongoose.Model.on('index', (...args) => {
8
+ console.error('******** index event emitted. ********\n', args);
9
+ });
7
10
 
8
11
  // tslint:disable-next-line:max-func-body-length
9
12
  async function main() {
@@ -61,6 +61,12 @@ schema.index({ identifier: 1 }, {
61
61
  schema.index({ 'project.id': 1, identifier: 1 }, {
62
62
  name: 'searchByProjectId-v20220721'
63
63
  });
64
+ schema.index({ 'itemListElement.typeOf': 1, identifier: 1 }, {
65
+ name: 'searchByItemListElementTypeOf',
66
+ partialFilterExpression: {
67
+ 'itemListElement.typeOf': { $exists: true }
68
+ }
69
+ });
64
70
  schema.index({ 'itemListElement.id': 1, identifier: 1 }, {
65
71
  name: 'searchByItemListElementId',
66
72
  partialFilterExpression: {
@@ -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?: {
@@ -32,10 +32,6 @@ const OFFERS_ARRAY_INDEX_NAME = 'offerIndex';
32
32
  class MongoRepository {
33
33
  constructor(connection) {
34
34
  this.aggregateOfferModel = connection.model(aggregateOffer_1.modelName, aggregateOffer_1.schema);
35
- // .on('index', (error: any) => {
36
- // // tslint:disable-next-line:no-console
37
- // console.error('index event emitted.', error);
38
- // });
39
35
  this.offerCatalogModel = connection.model(offerCatalog_1.modelName, offerCatalog_1.schema);
40
36
  }
41
37
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
@@ -445,7 +441,7 @@ class MongoRepository {
445
441
  */
446
442
  searchAllByOfferCatalogId(params) {
447
443
  return __awaiter(this, void 0, void 0, function* () {
448
- const matchStages = [{ $match: { _id: { $eq: params.offerCatalog.id } } }];
444
+ const matchStages = [{ $match: { _id: { $eq: params.subOfferCatalog.id } } }];
449
445
  const itemListElements = yield this.offerCatalogModel.aggregate([
450
446
  { $unwind: '$itemListElement' },
451
447
  ...matchStages,
@@ -487,7 +483,7 @@ class MongoRepository {
487
483
  aggregateOfferIds = searchDistinctAggregateOfferIdsResult;
488
484
  }
489
485
  // aggregateで再実装(2023-01-26~)
490
- const matchStages = [{ $match: { _id: { $eq: params.offerCatalog.id } } }];
486
+ const matchStages = [{ $match: { _id: { $eq: params.subOfferCatalog.id } } }];
491
487
  if (Array.isArray(aggregateOfferIds)) {
492
488
  matchStages.push({ $match: { 'itemListElement.id': { $exists: true, $in: aggregateOfferIds } } });
493
489
  }
@@ -552,7 +548,7 @@ class MongoRepository {
552
548
  // aggregateOfferIds = searchDistinctAggregateOfferIdsResult;
553
549
  // }
554
550
  // aggregateで再実装(2023-01-26~)
555
- const matchStages = [{ $match: { _id: { $eq: params.offerCatalog.id } } }];
551
+ const matchStages = [{ $match: { _id: { $eq: params.subOfferCatalog.id } } }];
556
552
  // if (Array.isArray(aggregateOfferIds)) {
557
553
  // matchStages.push({ $match: { 'itemListElement.id': { $exists: true, $in: aggregateOfferIds } } });
558
554
  // }
@@ -573,7 +569,7 @@ class MongoRepository {
573
569
  let offers = [];
574
570
  if (sortedOfferIds.length > 0) {
575
571
  const searchOffersConditions = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (params.useIncludeInDataCatalog)
576
- ? { includedInDataCatalog: { id: { $in: [params.offerCatalog.id] } } }
572
+ ? { includedInDataCatalog: { id: { $in: [params.subOfferCatalog.id] } } }
577
573
  : { parentOffer: { id: { $in: sortedOfferIds } } }), (typeof ((_a = params.availableAtOrFrom) === null || _a === void 0 ? void 0 : _a.id) === 'string')
578
574
  ? { availableAtOrFrom: { id: { $eq: params.availableAtOrFrom.id } } }
579
575
  : undefined), { priceSpecification: {
@@ -24,6 +24,10 @@
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
25
  import { Connection } from 'mongoose';
26
26
  import * as factory from '../factory';
27
+ export type IAggregatedOfferCatalog = Pick<factory.offerCatalog.IOfferCatalog, 'id' | 'name' | 'description' | 'project' | 'typeOf' | 'identifier' | 'itemOffered' | 'additionalProperty'> & {
28
+ numberOfItems?: number;
29
+ itemListElementTypeOf: factory.offerType.Offer | 'OfferCatalog';
30
+ };
27
31
  /**
28
32
  * オファーカタログリポジトリ
29
33
  */
@@ -77,15 +81,23 @@ export declare class MongoRepository {
77
81
  };
78
82
  };
79
83
  }): Promise<import("mongodb").UpdateResult | undefined>;
80
- search(params: factory.offerCatalog.ISearchConditions): Promise<(Omit<factory.offerCatalog.IOfferCatalog, 'itemListElement'> & {
81
- numberOfItems?: number;
82
- })[]>;
84
+ search(params: factory.offerCatalog.ISearchConditions): Promise<IAggregatedOfferCatalog[]>;
85
+ /**
86
+ * 強制的に親カタログのみ検索する
87
+ */
88
+ searchParentCatalogsForcibly(params: factory.offerCatalog.ISearchConditions): Promise<IAggregatedOfferCatalog[]>;
83
89
  findItemListElementById(params: {
84
90
  id: string;
85
91
  project: {
86
92
  id: string;
87
93
  };
88
94
  }): Promise<Pick<factory.offerCatalog.IOfferCatalog, 'itemListElement'>>;
95
+ /**
96
+ * 一つ目のitemListElementを取得する
97
+ */
98
+ findFirstItemListElementById(params: {
99
+ id: string;
100
+ }): Promise<factory.offerCatalog.IItemListElement>;
89
101
  deleteById(params: {
90
102
  id: string;
91
103
  }): Promise<void>;
@@ -33,7 +33,7 @@ class MongoRepository {
33
33
  }
34
34
  // tslint:disable-next-line:max-func-body-length
35
35
  static CREATE_MONGO_CONDITIONS(params) {
36
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
36
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
37
37
  // MongoDB検索条件
38
38
  const andConditions = [];
39
39
  const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
@@ -70,7 +70,11 @@ class MongoRepository {
70
70
  ]
71
71
  });
72
72
  }
73
- const itemListElementIdIn = (_h = (_g = params.itemListElement) === null || _g === void 0 ? void 0 : _g.id) === null || _h === void 0 ? void 0 : _h.$in;
73
+ const itemListElementTypeOfEq = (_h = (_g = params.itemListElement) === null || _g === void 0 ? void 0 : _g.typeOf) === null || _h === void 0 ? void 0 : _h.$eq;
74
+ if (typeof itemListElementTypeOfEq === 'string') {
75
+ andConditions.push({ 'itemListElement.typeOf': { $exists: true, $eq: itemListElementTypeOfEq } });
76
+ }
77
+ const itemListElementIdIn = (_k = (_j = params.itemListElement) === null || _j === void 0 ? void 0 : _j.id) === null || _k === void 0 ? void 0 : _k.$in;
74
78
  if (Array.isArray(itemListElementIdIn)) {
75
79
  andConditions.push({
76
80
  'itemListElement.id': {
@@ -79,7 +83,7 @@ class MongoRepository {
79
83
  }
80
84
  });
81
85
  }
82
- const itemListElementIdNin = (_k = (_j = params.itemListElement) === null || _j === void 0 ? void 0 : _j.id) === null || _k === void 0 ? void 0 : _k.$nin;
86
+ const itemListElementIdNin = (_m = (_l = params.itemListElement) === null || _l === void 0 ? void 0 : _l.id) === null || _m === void 0 ? void 0 : _m.$nin;
83
87
  if (Array.isArray(itemListElementIdNin)) {
84
88
  andConditions.push({
85
89
  'itemListElement.id': {
@@ -87,7 +91,7 @@ class MongoRepository {
87
91
  }
88
92
  });
89
93
  }
90
- const itemListElementIdAll = (_m = (_l = params.itemListElement) === null || _l === void 0 ? void 0 : _l.id) === null || _m === void 0 ? void 0 : _m.$all;
94
+ const itemListElementIdAll = (_p = (_o = params.itemListElement) === null || _o === void 0 ? void 0 : _o.id) === null || _p === void 0 ? void 0 : _p.$all;
91
95
  if (Array.isArray(itemListElementIdAll)) {
92
96
  andConditions.push({
93
97
  'itemListElement.id': {
@@ -96,7 +100,7 @@ class MongoRepository {
96
100
  }
97
101
  });
98
102
  }
99
- const itemOfferedTypeOfEq = (_p = (_o = params.itemOffered) === null || _o === void 0 ? void 0 : _o.typeOf) === null || _p === void 0 ? void 0 : _p.$eq;
103
+ const itemOfferedTypeOfEq = (_r = (_q = params.itemOffered) === null || _q === void 0 ? void 0 : _q.typeOf) === null || _r === void 0 ? void 0 : _r.$eq;
100
104
  if (typeof itemOfferedTypeOfEq === 'string') {
101
105
  andConditions.push({
102
106
  'itemOffered.typeOf': {
@@ -105,7 +109,7 @@ class MongoRepository {
105
109
  }
106
110
  });
107
111
  }
108
- const itemOfferedServiceTypeCodeValueEq = (_s = (_r = (_q = params.itemOffered) === null || _q === void 0 ? void 0 : _q.serviceType) === null || _r === void 0 ? void 0 : _r.codeValue) === null || _s === void 0 ? void 0 : _s.$eq;
112
+ const itemOfferedServiceTypeCodeValueEq = (_u = (_t = (_s = params.itemOffered) === null || _s === void 0 ? void 0 : _s.serviceType) === null || _t === void 0 ? void 0 : _t.codeValue) === null || _u === void 0 ? void 0 : _u.$eq;
109
113
  if (typeof itemOfferedServiceTypeCodeValueEq === 'string') {
110
114
  andConditions.push({
111
115
  'itemOffered.serviceType.codeValue': {
@@ -114,7 +118,7 @@ class MongoRepository {
114
118
  }
115
119
  });
116
120
  }
117
- const additionalPropertyElemMatch = (_t = params.additionalProperty) === null || _t === void 0 ? void 0 : _t.$elemMatch;
121
+ const additionalPropertyElemMatch = (_v = params.additionalProperty) === null || _v === void 0 ? void 0 : _v.$elemMatch;
118
122
  if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
119
123
  andConditions.push({
120
124
  additionalProperty: {
@@ -174,6 +178,12 @@ class MongoRepository {
174
178
  .exec();
175
179
  // tslint:disable-next-line:no-console
176
180
  console.log(result);
181
+ result = yield this.offerCatalogModel.updateMany({ 'itemOffered.serviceType': { $exists: true } }, {
182
+ $unset: { 'itemOffered.serviceType': 1 }
183
+ })
184
+ .exec();
185
+ // tslint:disable-next-line:no-console
186
+ console.log(result);
177
187
  });
178
188
  }
179
189
  updateManyById(params) {
@@ -238,7 +248,6 @@ class MongoRepository {
238
248
  const matchStages = conditions.map((condition) => {
239
249
  return { $match: condition };
240
250
  });
241
- // numberOfItems集計(2023-02-28~)
242
251
  const aggregate = this.offerCatalogModel.aggregate([
243
252
  ...(((_a = params.sort) === null || _a === void 0 ? void 0 : _a.identifier) !== undefined) ? [{ $sort: { identifier: params.sort.identifier } }] : [],
244
253
  ...matchStages,
@@ -251,7 +260,6 @@ class MongoRepository {
251
260
  typeOf: '$typeOf',
252
261
  id: '$_id',
253
262
  identifier: '$identifier',
254
- // itemListElement: '$itemListElement',
255
263
  itemOffered: '$itemOffered',
256
264
  additionalProperty: '$additionalProperty',
257
265
  numberOfItems: {
@@ -260,7 +268,9 @@ class MongoRepository {
260
268
  then: { $size: '$itemListElement' },
261
269
  else: 0
262
270
  }
263
- }
271
+ },
272
+ // itemListElement.typeOfを追加(2023-09-14~)
273
+ itemListElementTypeOf: { $first: '$itemListElement.typeOf' }
264
274
  }
265
275
  }
266
276
  ]);
@@ -272,6 +282,14 @@ class MongoRepository {
272
282
  return aggregate.exec();
273
283
  });
274
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
+ }
275
293
  findItemListElementById(params) {
276
294
  return __awaiter(this, void 0, void 0, function* () {
277
295
  const doc = yield this.offerCatalogModel.findOne({
@@ -285,6 +303,30 @@ class MongoRepository {
285
303
  return doc.toObject();
286
304
  });
287
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
+ }
288
330
  deleteById(params) {
289
331
  return __awaiter(this, void 0, void 0, function* () {
290
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
  });
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.syncOfferCatalog = void 0;
13
+ const factory = require("../../../factory");
13
14
  /**
14
15
  * カタログのitemListElementを集計オファーへ同期する
15
16
  */
@@ -18,41 +19,58 @@ function syncOfferCatalog(params) {
18
19
  // if (params.ids.length !== 1) {
19
20
  // throw new factory.errors.Argument('id', 'id.length must be 1');
20
21
  // }
22
+ var _a, _b;
21
23
  if (params.isDeleted) {
22
24
  for (const offerCatalogId of params.ids) {
23
- // カタログを含む全集計オファーからカタログを除外
24
- yield repos.aggregateOffer.pullIncludedInDataCatalog({
25
- project: { id: params.project.id },
26
- $pull: {
27
- includedInDataCatalog: { $elemMatch: { id: { $eq: offerCatalogId } } }
28
- }
29
- });
25
+ const offerCatalogs = yield repos.offerCatalog.search({ id: { $in: [offerCatalogId] } });
26
+ const itemListElementTypeOf = (_a = offerCatalogs.shift()) === null || _a === void 0 ? void 0 : _a.itemListElementTypeOf;
27
+ switch (itemListElementTypeOf) {
28
+ case factory.offerType.Offer:
29
+ // カタログを含む全集計オファーからカタログを除外
30
+ yield repos.aggregateOffer.pullIncludedInDataCatalog({
31
+ project: { id: params.project.id },
32
+ $pull: {
33
+ includedInDataCatalog: { $elemMatch: { id: { $eq: offerCatalogId } } }
34
+ }
35
+ });
36
+ break;
37
+ default:
38
+ // no op
39
+ }
30
40
  }
31
41
  }
32
42
  else {
33
43
  for (const offerCatalogId of params.ids) {
34
- // 集計オファーIDリストを検索
35
- const { itemListElement } = yield repos.offerCatalog.findItemListElementById({
36
- id: offerCatalogId,
37
- project: { id: params.project.id }
38
- });
39
- const aggregateOfferIds = itemListElement.map((element) => element.id);
40
- // カタログを含み、かつ、新しいカタログに含まれない集計オファーからカタログを除外
41
- yield repos.aggregateOffer.pullIncludedInDataCatalog(Object.assign({ project: { id: params.project.id }, $pull: {
42
- includedInDataCatalog: { $elemMatch: { id: { $eq: offerCatalogId } } }
43
- } }, (aggregateOfferIds.length > 0) ? { id: { $nin: aggregateOfferIds } } : undefined));
44
- if (aggregateOfferIds.length > 0) {
45
- // 新しいカタログに含まれる全集計オファーにカタログを追加
46
- yield repos.aggregateOffer.pushIncludedInDataCatalog({
47
- project: { id: params.project.id },
48
- id: { $in: aggregateOfferIds },
49
- $push: {
50
- includedInDataCatalog: { $each: [{ id: offerCatalogId }] }
44
+ const offerCatalogs = yield repos.offerCatalog.search({ id: { $in: [offerCatalogId] } });
45
+ const itemListElementTypeOf = (_b = offerCatalogs.shift()) === null || _b === void 0 ? void 0 : _b.itemListElementTypeOf;
46
+ switch (itemListElementTypeOf) {
47
+ case factory.offerType.Offer:
48
+ // 集計オファーIDリストを検索
49
+ const { itemListElement } = yield repos.offerCatalog.findItemListElementById({
50
+ id: offerCatalogId,
51
+ project: { id: params.project.id }
52
+ });
53
+ const aggregateOfferIds = itemListElement.map((element) => element.id);
54
+ // カタログを含み、かつ、新しいカタログに含まれない集計オファーからカタログを除外
55
+ yield repos.aggregateOffer.pullIncludedInDataCatalog(Object.assign({ project: { id: params.project.id }, $pull: {
56
+ includedInDataCatalog: { $elemMatch: { id: { $eq: offerCatalogId } } }
57
+ } }, (aggregateOfferIds.length > 0) ? { id: { $nin: aggregateOfferIds } } : undefined));
58
+ if (aggregateOfferIds.length > 0) {
59
+ // 新しいカタログに含まれる全集計オファーにカタログを追加
60
+ yield repos.aggregateOffer.pushIncludedInDataCatalog({
61
+ project: { id: params.project.id },
62
+ id: { $in: aggregateOfferIds },
63
+ $push: {
64
+ includedInDataCatalog: { $each: [{ id: offerCatalogId }] }
65
+ }
66
+ });
51
67
  }
52
- });
68
+ // 同期済記録を補完
69
+ yield repos.offerCatalog.updateDateSynced({ id: offerCatalogId, dateSynced: new Date() });
70
+ break;
71
+ default:
72
+ // no op
53
73
  }
54
- // 同期済記録を補完
55
- yield repos.offerCatalog.updateDateSynced({ id: offerCatalogId, dateSynced: new Date() });
56
74
  }
57
75
  }
58
76
  });
package/package.json CHANGED
@@ -9,8 +9,8 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.329.0-alpha.14",
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.66"
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);