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

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,154 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../../lib/index';
5
+
6
+ const project = { id: String(process.env.PROJECT_ID) };
7
+ const NUM_CREATE_OFFERS = 300;
8
+ const NUM_CREATE_SUB_CATALOGS = 10;
9
+
10
+ // tslint:disable-next-line:max-func-body-length
11
+ async function main() {
12
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
13
+
14
+ const aggregateOfferRepo = await chevre.repository.AggregateOffer.createInstance(mongoose.connection);
15
+ const offerCatalogRepo = await chevre.repository.OfferCatalog.createInstance(mongoose.connection);
16
+ const productRepo = await chevre.repository.Product.createInstance(mongoose.connection);
17
+ const offerCatalogItemRepo = await chevre.repository.OfferCatalogItem.createInstance(mongoose.connection);
18
+
19
+ const savingOffers: Omit<chevre.factory.unitPriceOffer.IUnitPriceOffer, 'id'>[] =
20
+ // tslint:disable-next-line:prefer-array-literal
21
+ [...Array(NUM_CREATE_OFFERS)].map<Omit<chevre.factory.unitPriceOffer.IUnitPriceOffer, 'id'>>((__, i) => {
22
+ const identifier = `sampleFreeOffer${i}`;
23
+ const priceSpecification: chevre.factory.unitPriceOffer.IUnitPriceOfferPriceSpecification = {
24
+ typeOf: chevre.factory.priceSpecificationType.UnitPriceSpecification,
25
+ priceCurrency: chevre.factory.priceCurrency.JPY,
26
+ valueAddedTaxIncluded: true,
27
+ price: 0,
28
+ referenceQuantity: {
29
+ value: 1,
30
+ typeOf: 'QuantitativeValue',
31
+ unitCode: chevre.factory.unitCode.C62
32
+ },
33
+ accounting: {
34
+ typeOf: 'Accounting',
35
+ accountsReceivable: 0
36
+ }
37
+ };
38
+
39
+ return {
40
+ project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
41
+ typeOf: chevre.factory.offerType.Offer,
42
+ identifier,
43
+ description: { en: identifier, ja: identifier },
44
+ alternateName: { ja: identifier },
45
+ name: { en: identifier, ja: identifier },
46
+ availability: chevre.factory.itemAvailability.InStock,
47
+ availableAtOrFrom: [
48
+ { id: '51qbjcfr72h62m06vtv5kkhgje' }
49
+ ],
50
+ itemOffered: { typeOf: chevre.factory.product.ProductType.EventService },
51
+ priceCurrency: chevre.factory.priceCurrency.JPY,
52
+ priceSpecification
53
+ };
54
+ });
55
+ const saveOfferResult = await aggregateOfferRepo.upsertByIdentifier(savingOffers);
56
+ console.log('saveOfferResult:', saveOfferResult);
57
+
58
+ const offerIds: string[] = (Array.isArray(saveOfferResult?.modifiedOffers)) ? saveOfferResult.modifiedOffers.map(({ id }) => id) : [];
59
+ const catalogIdentifier = 'sampleFreeOffersCatalog';
60
+ const savingOfferCatalog: chevre.factory.offerCatalog.IOfferCatalog = {
61
+ project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
62
+ typeOf: 'OfferCatalog',
63
+ identifier: catalogIdentifier,
64
+ description: { en: catalogIdentifier, ja: catalogIdentifier },
65
+ name: { en: catalogIdentifier, ja: catalogIdentifier },
66
+ itemListElement: offerIds.map((id) => ({ id, typeOf: chevre.factory.offerType.Offer })),
67
+ itemOffered: { typeOf: chevre.factory.product.ProductType.EventService }
68
+ };
69
+ const saveCatalogResult = await offerCatalogRepo.saveByIdentifier(savingOfferCatalog);
70
+ console.log('saveCatalogResult:', saveCatalogResult);
71
+
72
+ const productId = 'sampleFreeEventService';
73
+ const savingProduct: chevre.factory.product.IProduct & {
74
+ offers?: never;
75
+ } = {
76
+ project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
77
+ typeOf: chevre.factory.product.ProductType.EventService,
78
+ name: { en: productId, ja: productId },
79
+ productID: productId,
80
+ hasOfferCatalog: {
81
+ typeOf: 'OfferCatalog',
82
+ itemListElement: [{ id: saveCatalogResult.id }]
83
+ }
84
+ };
85
+ const saveProductResult = await productRepo.upsertManyByProductId([{
86
+ $set: savingProduct
87
+ }]);
88
+ console.log('saveProductResult:', saveProductResult);
89
+
90
+ // 以下サブカタログ
91
+ const offerIds4subCatalog: string[] = (Array.isArray(saveOfferResult?.modifiedOffers))
92
+ // tslint:disable-next-line:no-magic-numbers
93
+ ? saveOfferResult.modifiedOffers.slice(0, 100)
94
+ .map(({ id }) => id) :
95
+ [];
96
+ const savingSubOfferCatalogs: chevre.factory.offerCatalog.IOfferCatalog[] =
97
+ // tslint:disable-next-line:prefer-array-literal
98
+ [...Array(NUM_CREATE_SUB_CATALOGS)].map<chevre.factory.offerCatalog.IOfferCatalog>((__, i) => {
99
+ const subCatalogIdentifier = `sampleFreeOffersSubCatalog${i}`;
100
+
101
+ return {
102
+ project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
103
+ typeOf: 'OfferCatalog',
104
+ identifier: subCatalogIdentifier,
105
+ description: { en: subCatalogIdentifier, ja: subCatalogIdentifier },
106
+ name: { en: subCatalogIdentifier, ja: subCatalogIdentifier },
107
+ itemListElement: offerIds4subCatalog.map((id) => ({ id, typeOf: chevre.factory.offerType.Offer })),
108
+ itemOffered: { typeOf: chevre.factory.product.ProductType.EventService }
109
+ };
110
+ });
111
+ const saveSubCatalogResult = await offerCatalogItemRepo.upsertManyByIdentifier(savingSubOfferCatalogs.map((savingSubOfferCatalog) => {
112
+ return {
113
+ $set: savingSubOfferCatalog
114
+ };
115
+ }));
116
+ console.log('saveSubCatalogResult:', saveSubCatalogResult);
117
+
118
+ const subCatalogIds: string[] =
119
+ (Array.isArray(saveSubCatalogResult?.modifiedCatalogs)) ? saveSubCatalogResult.modifiedCatalogs.map(({ id }) => id) : [];
120
+ const catalogBySubCatalogIdentifier = 'sampleFreeOffersCatalogBySub';
121
+ const savingOfferCatalogBySubCatalog: chevre.factory.offerCatalog.IOfferCatalog = {
122
+ project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
123
+ typeOf: 'OfferCatalog',
124
+ identifier: catalogBySubCatalogIdentifier,
125
+ description: { en: catalogBySubCatalogIdentifier, ja: catalogBySubCatalogIdentifier },
126
+ name: { en: catalogBySubCatalogIdentifier, ja: catalogBySubCatalogIdentifier },
127
+ itemListElement: subCatalogIds.map((id) => ({ id, typeOf: 'OfferCatalog' })),
128
+ itemOffered: { typeOf: chevre.factory.product.ProductType.EventService }
129
+ };
130
+ const saveCatalogBySubResult = await offerCatalogRepo.saveByIdentifier(savingOfferCatalogBySubCatalog);
131
+ console.log('saveCatalogBySubResult:', saveCatalogBySubResult);
132
+
133
+ const productIdBySubCatalog = 'sampleFreeEventServiceBySub';
134
+ const savingProductBySubCatalog: chevre.factory.product.IProduct & {
135
+ offers?: never;
136
+ } = {
137
+ project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
138
+ typeOf: chevre.factory.product.ProductType.EventService,
139
+ name: { en: productIdBySubCatalog, ja: productIdBySubCatalog },
140
+ productID: productIdBySubCatalog,
141
+ hasOfferCatalog: {
142
+ typeOf: 'OfferCatalog',
143
+ itemListElement: [{ id: saveCatalogBySubResult.id }]
144
+ }
145
+ };
146
+ const saveProductBySubCatalogResult = await productRepo.upsertManyByProductId([{
147
+ $set: savingProductBySubCatalog
148
+ }]);
149
+ console.log('saveProductBySubCatalogResult:', saveProductBySubCatalogResult);
150
+ }
151
+
152
+ main()
153
+ .then()
154
+ .catch(console.error);
@@ -1,7 +1,9 @@
1
1
  // tslint:disable:no-console
2
2
  import * as mongoose from 'mongoose';
3
3
 
4
- import { chevre } from '../../../lib/index';
4
+ import { chevre } from '../../../../lib/index';
5
+
6
+ const formatter = new Intl.NumberFormat('ja-JP');
5
7
 
6
8
  // const PROJECT_ID = process.env.PROJECT_ID;
7
9
  mongoose.Model.on('index', (...args) => {
@@ -9,29 +11,39 @@ mongoose.Model.on('index', (...args) => {
9
11
  });
10
12
 
11
13
  async function main() {
14
+ let startTime: [number, number] = process.hrtime();
15
+ let diff: [number, number] = process.hrtime(startTime);
16
+ let result: any;
17
+
12
18
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
13
19
 
14
20
  const eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
21
+ const eventSeriesRepo = await chevre.repository.EventSeries.createInstance(mongoose.connection);
15
22
  const offerRepo = await chevre.repository.Offer.createInstance(mongoose.connection);
16
23
  const offerCatalogRepo = await chevre.repository.OfferCatalog.createInstance(mongoose.connection);
17
24
  const productRepo = await chevre.repository.Product.createInstance(mongoose.connection);
18
25
 
19
- const result = await (await chevre.service.offer.createService()).event.searchOfferCatalogItemAvailability({
26
+ startTime = process.hrtime();
27
+ result = await (await chevre.service.offer.createService()).event.searchOfferAppliesToMovieTicket({
20
28
  event: {
21
- id: 'bm0f0cadh'
29
+ id: 'cm8dwc74k'
22
30
  },
23
31
  limit: 10,
24
32
  page: 1,
25
- availableAtOrFrom: { id: '3eo6okferrsdpfd9j2ce1iv9k7' },
26
- options: { considerUnacceptedPaymentMethod: true }
33
+ store: { id: '51qbjcfr72h62m06vtv5kkhgje' },
34
+ onlyValid: true,
35
+ options: { useIncludeInDataCatalog: false }
27
36
  })({
28
37
  event: eventRepo,
38
+ eventSeries: eventSeriesRepo,
29
39
  offer: offerRepo,
30
40
  offerCatalog: offerCatalogRepo,
31
41
  product: productRepo
32
42
  });
43
+ diff = process.hrtime(startTime);
33
44
  console.log(result);
34
45
  console.log(result.length);
46
+ console.log('diff:', [diff[0], formatter.format(diff[1])]);
35
47
  }
36
48
 
37
49
  main()
@@ -0,0 +1,68 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../../lib/index';
5
+
6
+ const formatter = new Intl.NumberFormat('ja-JP');
7
+
8
+ // const PROJECT_ID = process.env.PROJECT_ID;
9
+ mongoose.Model.on('index', (...args) => {
10
+ console.error('******** index event emitted. ********\n', args);
11
+ });
12
+
13
+ async function main() {
14
+ let startTime: [number, number] = process.hrtime();
15
+ let diff: [number, number] = process.hrtime(startTime);
16
+ let result: any;
17
+
18
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
19
+
20
+ const eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
21
+ const offerRepo = await chevre.repository.Offer.createInstance(mongoose.connection);
22
+ const offerCatalogRepo = await chevre.repository.OfferCatalog.createInstance(mongoose.connection);
23
+ const productRepo = await chevre.repository.Product.createInstance(mongoose.connection);
24
+
25
+ // startTime = process.hrtime();
26
+ // result = await (await chevre.service.offer.createService()).event.searchOfferCatalogItemAvailability({
27
+ // event: {
28
+ // id: 'cm8dwc74j'
29
+ // },
30
+ // limit: 10,
31
+ // page: 1,
32
+ // availableAtOrFrom: { id: '51qbjcfr72h62m06vtv5kkhgje' },
33
+ // options: { considerUnacceptedPaymentMethod: true, useIncludeInDataCatalog: true }
34
+ // })({
35
+ // event: eventRepo,
36
+ // offer: offerRepo,
37
+ // offerCatalog: offerCatalogRepo,
38
+ // product: productRepo
39
+ // });
40
+ // diff = process.hrtime(startTime);
41
+ // console.log(result);
42
+ // console.log(result.length);
43
+ // console.log('diff:', [diff[0], formatter.format(diff[1])]);
44
+
45
+ startTime = process.hrtime();
46
+ result = await (await chevre.service.offer.createService()).event.searchOfferCatalogItemAvailability({
47
+ event: {
48
+ id: 'cm8dwc74j'
49
+ },
50
+ limit: 10,
51
+ page: 1,
52
+ availableAtOrFrom: { id: '51qbjcfr72h62m06vtv5kkhgje' },
53
+ options: { considerUnacceptedPaymentMethod: true, useIncludeInDataCatalog: false }
54
+ })({
55
+ event: eventRepo,
56
+ offer: offerRepo,
57
+ offerCatalog: offerCatalogRepo,
58
+ product: productRepo
59
+ });
60
+ diff = process.hrtime(startTime);
61
+ console.log(result);
62
+ console.log(result.length);
63
+ console.log('diff:', [diff[0], formatter.format(diff[1])]);
64
+ }
65
+
66
+ main()
67
+ .then(console.log)
68
+ .catch(console.error);
@@ -84,27 +84,27 @@ const indexes = [
84
84
  [
85
85
  { identifier: 1, dateCreated: -1 },
86
86
  { name: 'identifier' }
87
- ],
88
- // tslint:disable-next-line:no-suspicious-comment
89
- [
90
- { identifier: 1 },
91
- { name: 'searchByIdentifier' }
92
- ],
93
- // tslint:disable-next-line:no-suspicious-comment
94
- [
95
- { 'project.id': 1, identifier: 1 },
96
- { name: 'searchByProjectId' }
97
- ],
98
- // tslint:disable-next-line:no-suspicious-comment
99
- [
100
- { 'provider.id': 1, identifier: 1 },
101
- { name: 'searchByProviderId' }
102
- ],
103
- // tslint:disable-next-line:no-suspicious-comment
104
- [
105
- { 'about.id': 1, identifier: 1 },
106
- { name: 'searchByAboutId' }
107
87
  ]
88
+ // discontinue(2025-05-08~)
89
+ // [
90
+ // { identifier: 1 },
91
+ // { name: 'searchByIdentifier' }
92
+ // ],
93
+ // discontinue(2025-05-08~)
94
+ // [
95
+ // { 'project.id': 1, identifier: 1 },
96
+ // { name: 'searchByProjectId' }
97
+ // ],
98
+ // discontinue(2025-05-08~)
99
+ // [
100
+ // { 'provider.id': 1, identifier: 1 },
101
+ // { name: 'searchByProviderId' }
102
+ // ],
103
+ // discontinue(2025-05-08~)
104
+ // [
105
+ // { 'about.id': 1, identifier: 1 },
106
+ // { name: 'searchByAboutId' }
107
+ // ]
108
108
  ];
109
109
  exports.indexes = indexes;
110
110
  /**
@@ -92,9 +92,10 @@ export declare class OfferRepo implements OfferInCatalogReadOnlyRepo {
92
92
  searchAvaialbleAppliesToMovieTicketByOfferCatalogId(params: {
93
93
  subOfferCatalog: {
94
94
  /**
95
- * サブカタログID
95
+ * カタログID or サブカタログID
96
96
  */
97
97
  id: string;
98
+ isOfferCatalogItem: boolean;
98
99
  };
99
100
  availableAtOrFrom?: {
100
101
  id?: string;
@@ -104,6 +105,7 @@ export declare class OfferRepo implements OfferInCatalogReadOnlyRepo {
104
105
  onlyValid?: boolean;
105
106
  limit?: number;
106
107
  page?: number;
108
+ useIncludeInDataCatalog: boolean;
107
109
  }): Promise<Pick<factory.priceSpecification.unitPrice.IAppliesToMovieTicket, 'serviceOutput'>[]>;
108
110
  /**
109
111
  * クライアントの利用可能カタログを検索する
@@ -122,6 +124,21 @@ export declare class OfferRepo implements OfferInCatalogReadOnlyRepo {
122
124
  }): Promise<{
123
125
  id: string;
124
126
  }[]>;
127
+ /**
128
+ * サブカタログがクライアントで利用可能かどうか
129
+ */
130
+ isCatalogAvailable(params: {
131
+ includedInDataCatalog: {
132
+ /**
133
+ * サブカタログID
134
+ */
135
+ id: string;
136
+ };
137
+ availableAtOrFrom: {
138
+ id: string;
139
+ };
140
+ unacceptedPaymentMethod: string[];
141
+ }): Promise<boolean>;
125
142
  count(params: Omit<factory.unitPriceOffer.ISearchConditions, 'limit' | 'page' | 'sort'>): Promise<number>;
126
143
  search(params: factory.unitPriceOffer.ISearchConditions, projection?: IProjection): Promise<IOfferInCatalog[]>;
127
144
  /**
@@ -226,20 +226,31 @@ class OfferRepo {
226
226
  */
227
227
  searchAvaialbleAppliesToMovieTicketByOfferCatalogId(params) {
228
228
  return __awaiter(this, void 0, void 0, function* () {
229
- // let sortedOfferIds: string[] = [];
230
- // if (!params.useIncludeInDataCatalog) {
231
- // // useIncludeInDataCatalogでない場合のみ集計オファーIDリストを検索する
232
- // sortedOfferIds = await this.searchAggregateOfferIdsBySubOfferCatalog({
233
- // id: params.subOfferCatalog.id,
234
- // isOfferCatalogItem: params.subOfferCatalog.isOfferCatalogItem
235
- // });
236
- // }
237
229
  var _a;
238
- const searchOffersConditions = Object.assign(Object.assign({
239
- // ...(params.useIncludeInDataCatalog)
240
- // ? { includedInDataCatalog: { id: { $in: [params.subOfferCatalog.id] } } }
241
- // : { parentOffer: { id: { $in: sortedOfferIds } } },
242
- includedInDataCatalog: { id: { $in: [params.subOfferCatalog.id] } } }, (typeof ((_a = params.availableAtOrFrom) === null || _a === void 0 ? void 0 : _a.id) === 'string')
230
+ const { useIncludeInDataCatalog } = params;
231
+ // カタログのみ対応でよい?
232
+ let offerIds;
233
+ if (!useIncludeInDataCatalog) {
234
+ if (params.subOfferCatalog.isOfferCatalogItem) {
235
+ const offerCatalog = yield this.offerCatalogItemModel.findOne({ _id: { $eq: params.subOfferCatalog.id } }, { _id: 0, itemListElement: 1 })
236
+ .lean()
237
+ .exec();
238
+ offerIds = offerCatalog === null || offerCatalog === void 0 ? void 0 : offerCatalog.itemListElement.map(({ id }) => id);
239
+ }
240
+ else {
241
+ const offerCatalog = yield this.offerCatalogModel.findOne({ _id: { $eq: params.subOfferCatalog.id } }, { _id: 0, itemListElement: 1 })
242
+ .lean()
243
+ .exec();
244
+ offerIds = offerCatalog === null || offerCatalog === void 0 ? void 0 : offerCatalog.itemListElement.map(({ id }) => id);
245
+ }
246
+ if (!Array.isArray(offerIds) || offerIds.length === 0) {
247
+ return [];
248
+ }
249
+ }
250
+ // support useIncludeInDataCatalog(2025-05-08~)
251
+ const searchOffersConditions = Object.assign(Object.assign(Object.assign({}, (Array.isArray(offerIds))
252
+ ? { parentOffer: { id: { $in: offerIds } } }
253
+ : { includedInDataCatalog: { id: { $in: [params.subOfferCatalog.id] } } }), (typeof ((_a = params.availableAtOrFrom) === null || _a === void 0 ? void 0 : _a.id) === 'string')
243
254
  ? { availableAtOrFrom: { id: { $eq: params.availableAtOrFrom.id } } }
244
255
  : undefined), { priceSpecification: {
245
256
  appliesToMovieTicket: Object.assign({
@@ -308,6 +319,36 @@ class OfferRepo {
308
319
  return aggregate.exec();
309
320
  });
310
321
  }
322
+ /**
323
+ * サブカタログがクライアントで利用可能かどうか
324
+ */
325
+ isCatalogAvailable(params) {
326
+ return __awaiter(this, void 0, void 0, function* () {
327
+ const { unacceptedPaymentMethod } = params;
328
+ // サブカタログのみ対応でよい
329
+ const offerCatalogItem = yield this.offerCatalogItemModel.findOne({ _id: { $eq: params.includedInDataCatalog.id } }, { _id: 0, itemListElement: 1 })
330
+ .lean()
331
+ .exec();
332
+ const offerIds = offerCatalogItem === null || offerCatalogItem === void 0 ? void 0 : offerCatalogItem.itemListElement.map(({ id }) => id);
333
+ if (!Array.isArray(offerIds) || offerIds.length === 0) {
334
+ return false;
335
+ }
336
+ const doc = yield this.aggregateOfferModel.findOne(Object.assign({
337
+ // 'project.id': { $eq: params.project.id },
338
+ _id: { $in: offerIds }, 'offers.availableAtOrFrom.id': { $exists: true, $eq: params.availableAtOrFrom.id } }, (Array.isArray(unacceptedPaymentMethod) && unacceptedPaymentMethod.length > 0)
339
+ ? {
340
+ 'offers.priceSpecification.appliesToMovieTicket.serviceOutput.typeOf': {
341
+ $nin: unacceptedPaymentMethod
342
+ }
343
+ }
344
+ : undefined), {
345
+ _id: 1
346
+ })
347
+ .lean()
348
+ .exec();
349
+ return doc !== null;
350
+ });
351
+ }
311
352
  count(params) {
312
353
  return __awaiter(this, void 0, void 0, function* () {
313
354
  const matchStages = aggregateOffer_1.AggregateOfferRepo.CREATE_MATCH_STAGE(params);
@@ -86,6 +86,15 @@ export declare class PendingReservationRepo implements AbstractStockHolderRepo {
86
86
  $eq: string;
87
87
  };
88
88
  }): Promise<IProjectSubReservationResult[]>;
89
+ /**
90
+ * expiresを最新の情報に同期する
91
+ */
92
+ syncEvent2expires(params: {
93
+ expires: Date;
94
+ reservationFor: {
95
+ id: string;
96
+ };
97
+ }): Promise<import("mongoose").UpdateWriteOpResult>;
89
98
  private aggregateNumSeats;
90
99
  private createReservationPackageIfPossible;
91
100
  private deleteReservationPackage;
@@ -468,6 +468,24 @@ class PendingReservationRepo {
468
468
  .exec();
469
469
  });
470
470
  }
471
+ /**
472
+ * expiresを最新の情報に同期する
473
+ */
474
+ syncEvent2expires(params) {
475
+ return __awaiter(this, void 0, void 0, function* () {
476
+ const { expires, reservationFor } = params;
477
+ if (!(expires instanceof Date)) {
478
+ throw new factory.errors.Argument('expires', 'must be Date');
479
+ }
480
+ return this.pendingReservationModel.updateMany({
481
+ 'reservationFor.id': { $eq: reservationFor.id },
482
+ numSeats: { $gte: 1 } // numSeats:0についてはもはや不要なドキュメントなので除外
483
+ }, {
484
+ $set: { expires }
485
+ })
486
+ .exec();
487
+ });
488
+ }
471
489
  aggregateNumSeats(params) {
472
490
  return __awaiter(this, void 0, void 0, function* () {
473
491
  const { bookingTime, dateCreated, reservationFor, limit } = params;
@@ -859,9 +859,7 @@ function createScreeningRoomFromCOA(project, seller, screenFromCOA) {
859
859
  };
860
860
  }
861
861
  function updateEvent4ttts(params) {
862
- return (repos
863
- // settings: Settings
864
- ) => __awaiter(this, void 0, void 0, function* () {
862
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
865
863
  const actionAttributes = Object.assign({ project: { typeOf: factory.organizationType.Project, id: params.project.id }, typeOf: factory.actionType.UpdateAction, agent: params.agent, object: {
866
864
  id: params.oldEventId,
867
865
  typeOf: factory.eventType.ScreeningEvent
@@ -899,7 +897,7 @@ function updateEvent4ttts(params) {
899
897
  isNew: false,
900
898
  useInform: true
901
899
  })(repos
902
- // settings
900
+ // スケジュールによるイベント作成ではendDateに変更がないのでpendingReservationsへの同期はひとまず必要なし
903
901
  );
904
902
  });
905
903
  }
@@ -28,6 +28,9 @@ declare function searchOfferAppliesToMovieTicket(params: {
28
28
  * 有効なオファーのみ対象とするか
29
29
  */
30
30
  onlyValid?: boolean;
31
+ options: {
32
+ useIncludeInDataCatalog: boolean;
33
+ };
31
34
  }): (repos: {
32
35
  event: EventRepo;
33
36
  eventSeries: EventSeriesRepo;
@@ -75,22 +75,21 @@ function searchOfferAppliesToMovieTicket(params) {
75
75
  }
76
76
  // サブカタログIDを決定
77
77
  let subOfferCatalogId = catalogId;
78
- // let isOfferCatalogItem: boolean = false;
78
+ let isOfferCatalogItem = false;
79
79
  const offerCatalogFirstElement = yield repos.offerCatalog.findFirstItemListElementById({ id: catalogId });
80
80
  if (offerCatalogFirstElement.typeOf === 'OfferCatalog') {
81
81
  subOfferCatalogId = offerCatalogFirstElement.id;
82
- // isOfferCatalogItem = true;
82
+ isOfferCatalogItem = true;
83
83
  }
84
84
  return repos.offer.searchAvaialbleAppliesToMovieTicketByOfferCatalogId({
85
- // subOfferCatalog: { id: subOfferCatalogId, isOfferCatalogItem },
86
- subOfferCatalog: { id: subOfferCatalogId },
85
+ subOfferCatalog: { id: subOfferCatalogId, isOfferCatalogItem },
87
86
  availableAtOrFrom: { id: (_d = params.store) === null || _d === void 0 ? void 0 : _d.id },
88
87
  unacceptedPaymentMethod: unacceptedPaymentMethod,
89
88
  excludeAppliesToMovieTicket: excludeAppliesToMovieTicket,
90
89
  onlyValid: params.onlyValid === true,
91
- // useIncludeInDataCatalog: params.useIncludeInDataCatalog,
92
90
  limit: params.limit,
93
- page: params.page
91
+ page: params.page,
92
+ useIncludeInDataCatalog: params.options.useIncludeInDataCatalog
94
93
  });
95
94
  });
96
95
  }
@@ -38,6 +38,7 @@ declare function searchOfferCatalogItemAvailability(params: {
38
38
  */
39
39
  id: string;
40
40
  };
41
+ useIncludeInDataCatalog: boolean;
41
42
  };
42
43
  }): (repos: {
43
44
  event: EventRepo;
@@ -21,20 +21,26 @@ function getUnacceptedPaymentMethodByEvent(params) {
21
21
  }
22
22
  return unacceptedPaymentMethod;
23
23
  }
24
+ const MAX_LIMIT_SEARCH_OFFER_CATALOG_ITEMS = 10;
24
25
  /**
25
26
  * サブカタログ利用可能性検索
26
27
  */
27
28
  // tslint:disable-next-line:max-func-body-length
28
29
  function searchOfferCatalogItemAvailability(params) {
30
+ // tslint:disable-next-line:max-func-body-length
29
31
  return (repos) => __awaiter(this, void 0, void 0, function* () {
30
32
  var _a, _b, _c, _d;
31
- const { considerUnacceptedPaymentMethod } = params.options;
33
+ const { considerUnacceptedPaymentMethod, useIncludeInDataCatalog } = params.options;
32
34
  if (typeof params.limit !== 'number') {
33
35
  throw new factory.errors.Argument('limit', 'must be number');
34
36
  }
35
37
  if (typeof params.page !== 'number') {
36
38
  throw new factory.errors.Argument('page', 'must be number');
37
39
  }
40
+ // オファー検索時の_id条件がitemListElementCount * MAX_LIMIT_SEARCH_OFFER_CATALOG_ITEMS以下になるように制限
41
+ if (params.limit > MAX_LIMIT_SEARCH_OFFER_CATALOG_ITEMS) {
42
+ throw new factory.errors.Argument('limit', `must be <=${MAX_LIMIT_SEARCH_OFFER_CATALOG_ITEMS}`);
43
+ }
38
44
  let availabilities = [];
39
45
  // optimize(2024-07-18~)
40
46
  const event = yield repos.event.projectEventFieldsById({ id: params.event.id }, ['project', 'offers.itemOffered.id', 'offers.unacceptedPaymentMethod']);
@@ -85,19 +91,34 @@ function searchOfferCatalogItemAvailability(params) {
85
91
  });
86
92
  const unacceptedPaymentMethod = getUnacceptedPaymentMethodByEvent({ event });
87
93
  if (catalogItemListElements.length > 0) {
88
- // 単価オファーから利用可能なサブカタログを検索
89
- const availableCatalogs = yield repos.offer.searchAvailableCatalogs({
90
- project: { id: event.project.id },
91
- includedInDataCatalog: { id: catalogItemListElements.map((element) => element.id) },
92
- availableAtOrFrom: { id: params.availableAtOrFrom.id },
93
- unacceptedPaymentMethod: (considerUnacceptedPaymentMethod) ? unacceptedPaymentMethod : []
94
- });
95
- availabilities = catalogItemListElements.map((element) => {
96
- return {
97
- id: element.id,
98
- isAvailable: availableCatalogs.some((item) => item.id === element.id)
99
- };
100
- });
94
+ if (useIncludeInDataCatalog) {
95
+ // 単価オファーから利用可能なサブカタログを検索
96
+ const availableCatalogs = yield repos.offer.searchAvailableCatalogs({
97
+ project: { id: event.project.id },
98
+ includedInDataCatalog: { id: catalogItemListElements.map((element) => element.id) },
99
+ availableAtOrFrom: { id: params.availableAtOrFrom.id },
100
+ unacceptedPaymentMethod: (considerUnacceptedPaymentMethod) ? unacceptedPaymentMethod : []
101
+ });
102
+ availabilities = catalogItemListElements.map((element) => {
103
+ return {
104
+ id: element.id,
105
+ isAvailable: availableCatalogs.some((item) => item.id === element.id)
106
+ };
107
+ });
108
+ }
109
+ else {
110
+ // support no dependency on includedInDataCatalog(2025-05-07~)
111
+ for (const element of catalogItemListElements) {
112
+ availabilities.push({
113
+ id: element.id,
114
+ isAvailable: yield repos.offer.isCatalogAvailable({
115
+ includedInDataCatalog: { id: element.id },
116
+ availableAtOrFrom: { id: params.availableAtOrFrom.id },
117
+ unacceptedPaymentMethod: (considerUnacceptedPaymentMethod) ? unacceptedPaymentMethod : []
118
+ })
119
+ });
120
+ }
121
+ }
101
122
  }
102
123
  }
103
124
  else {
@@ -1,5 +1,6 @@
1
1
  import type { EventRepo } from '../../repo/event';
2
2
  import type { EventSeriesRepo } from '../../repo/eventSeries';
3
+ import type { PendingReservationRepo } from '../../repo/pendingReservation';
3
4
  import type { ProjectRepo } from '../../repo/project';
4
5
  import type { SettingRepo } from '../../repo/setting';
5
6
  import type { TaskRepo } from '../../repo/task';
@@ -10,6 +11,7 @@ import * as factory from '../../factory';
10
11
  declare function onEventChanged(params: factory.task.onEventChanged.IData): (repos: {
11
12
  event: EventRepo;
12
13
  eventSeries: EventSeriesRepo;
14
+ pendingReservation?: PendingReservationRepo;
13
15
  project: ProjectRepo;
14
16
  setting: SettingRepo;
15
17
  task: TaskRepo;
@@ -10,7 +10,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.onEventChanged = onEventChanged;
13
+ const createDebug = require("debug");
14
+ const moment = require("moment");
13
15
  const factory = require("../../factory");
16
+ const debug = createDebug('chevre-domain:service:offer:onEventChanged');
14
17
  /**
15
18
  * イベント変更時処理
16
19
  */
@@ -49,6 +52,19 @@ function onEventChanged(params) {
49
52
  // no op
50
53
  }
51
54
  }
55
+ if (params.typeOf === factory.eventType.Event || params.typeOf === factory.eventType.ScreeningEvent) {
56
+ if (repos.pendingReservation !== undefined) {
57
+ // sync pendingReservations.expires(2025-05-08~)
58
+ yield syncEventEndDate2pendingReservations({
59
+ ids: params.id,
60
+ typeOf: params.typeOf
61
+ })({
62
+ event: repos.event,
63
+ pendingReservation: repos.pendingReservation,
64
+ setting: repos.setting
65
+ });
66
+ }
67
+ }
52
68
  }
53
69
  });
54
70
  }
@@ -263,3 +279,33 @@ function createInform2aggTasks(params, setting) {
263
279
  }
264
280
  });
265
281
  }
282
+ function syncEventEndDate2pendingReservations(params) {
283
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
284
+ var _a, _b;
285
+ const setting = yield repos.setting.findOne({ project: { id: { $eq: '*' } } }, ['storage']);
286
+ const stockHoldAfterEventEndInDays = (_a = setting === null || setting === void 0 ? void 0 : setting.storage) === null || _a === void 0 ? void 0 : _a.stockHoldAfterEventEndInDays;
287
+ if (typeof stockHoldAfterEventEndInDays !== 'number') {
288
+ throw new factory.errors.NotFound('setting.storage.stockHoldAfterEventEndInDays');
289
+ }
290
+ for (const eventId of params.ids) {
291
+ const events = yield repos.event.projectEventFields({
292
+ limit: 1,
293
+ page: 1,
294
+ id: { $eq: eventId },
295
+ typeOf: params.typeOf
296
+ }, ['endDate']);
297
+ const endDate = (_b = events.shift()) === null || _b === void 0 ? void 0 : _b.endDate;
298
+ if (endDate instanceof Date) {
299
+ const expires = moment(endDate)
300
+ .add(stockHoldAfterEventEndInDays, 'days')
301
+ .toDate();
302
+ debug('syncEvent2expires processing...', eventId, endDate, expires);
303
+ const syncResult = yield repos.pendingReservation.syncEvent2expires({
304
+ expires,
305
+ reservationFor: { id: eventId }
306
+ });
307
+ debug('syncEvent2expires processed.', syncResult);
308
+ }
309
+ }
310
+ });
311
+ }
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.call = call;
13
13
  const event_1 = require("../../repo/event");
14
14
  const eventSeries_1 = require("../../repo/eventSeries");
15
+ const pendingReservation_1 = require("../../repo/pendingReservation");
15
16
  const project_1 = require("../../repo/project");
16
17
  const setting_1 = require("../../repo/setting");
17
18
  const task_1 = require("../../repo/task");
@@ -24,11 +25,10 @@ function call(data) {
24
25
  yield (0, onEventChanged_1.onEventChanged)(data)({
25
26
  event: new event_1.EventRepo(connection),
26
27
  eventSeries: new eventSeries_1.EventSeriesRepo(connection),
28
+ pendingReservation: new pendingReservation_1.PendingReservationRepo(connection),
27
29
  project: new project_1.ProjectRepo(connection),
28
30
  setting: new setting_1.SettingRepo(connection),
29
31
  task: new task_1.TaskRepo(connection)
30
- }
31
- // settings
32
- );
32
+ });
33
33
  });
34
34
  }
package/package.json CHANGED
@@ -113,5 +113,5 @@
113
113
  "postversion": "git push origin --tags",
114
114
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
115
115
  },
116
- "version": "22.9.0-alpha.116"
116
+ "version": "22.9.0-alpha.118"
117
117
  }