@chevre/domain 20.4.0-alpha.30 → 20.4.0-alpha.32

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.
@@ -8,9 +8,11 @@ import { chevre } from '../../../lib/index';
8
8
  async function main() {
9
9
  await mongoose.connect(<string>process.env.MONGOLAB_URI);
10
10
 
11
- const reservationRepo = new chevre.repository.Reservation(mongoose.connection);
11
+ const taskRepo = new chevre.repository.Task(mongoose.connection);
12
12
 
13
- const result = await reservationRepo.deleteReservedTicketUnderName();
13
+ const result = await taskRepo.deleteByName({
14
+ name: <any>'DeleteAuthorization'
15
+ });
14
16
 
15
17
  console.log('deleted', result);
16
18
  }
@@ -24,7 +24,6 @@ async function main() {
24
24
  const { ticketOffers } = await chevre.service.offer.event.searchEventTicketOffers({
25
25
  event: { id: 'ale6qiedi' },
26
26
  onlyValid: true,
27
- sort: false,
28
27
  validateOfferRateLimit: true,
29
28
  addSortIndex: true,
30
29
  limit: 100,
@@ -55,6 +55,14 @@ export declare class MongoRepository {
55
55
  id: string;
56
56
  };
57
57
  }): Promise<void>;
58
+ deleteByName(params: {
59
+ name: factory.taskName;
60
+ }): Promise<{
61
+ ok?: number | undefined;
62
+ n?: number | undefined;
63
+ } & {
64
+ deletedCount?: number | undefined;
65
+ }>;
58
66
  aggregateTask(params: {
59
67
  project?: {
60
68
  id?: {
@@ -310,6 +310,14 @@ class MongoRepository {
310
310
  .exec();
311
311
  });
312
312
  }
313
+ deleteByName(params) {
314
+ return __awaiter(this, void 0, void 0, function* () {
315
+ return this.taskModel.deleteMany({
316
+ name: { $eq: params.name }
317
+ })
318
+ .exec();
319
+ });
320
+ }
313
321
  aggregateTask(params) {
314
322
  return __awaiter(this, void 0, void 0, function* () {
315
323
  const statuses = yield Promise.all([
@@ -94,8 +94,10 @@ function createTransactionObject(params) {
94
94
  return (repos) => __awaiter(this, void 0, void 0, function* () {
95
95
  // オファー検索
96
96
  const offers = yield (0, searchProductOffers_1.searchProductOffers)({
97
+ ids: params.acceptedOffers.map((o) => o.id),
97
98
  itemOffered: { id: String(params.product.id) },
98
- sort: false // ソート不要(2023-01-27~)
99
+ onlyValid: true,
100
+ addSortIndex: false
99
101
  })(repos);
100
102
  const transactionObject = [];
101
103
  for (const acceptedOffer of params.acceptedOffers) {
@@ -5,10 +5,20 @@ import { MongoRepository as ProductRepo } from '../../../repo/product';
5
5
  * プロダクトオファーを検索する
6
6
  */
7
7
  export declare function searchProductOffers(params: {
8
+ /**
9
+ * 指定したIDのオファーだけ取得する場合
10
+ */
11
+ ids?: string[];
8
12
  itemOffered: {
9
13
  id: string;
10
14
  };
11
- sort: boolean;
15
+ availableAt?: {
16
+ id: string;
17
+ };
18
+ onlyValid: boolean;
19
+ addSortIndex: boolean;
20
+ limit?: number;
21
+ page?: number;
12
22
  }): (repos: {
13
23
  offer: OfferRepo;
14
24
  product: ProductRepo;
@@ -23,16 +23,23 @@ function searchProductOffers(params) {
23
23
  if (typeof offerCatalogId !== 'string') {
24
24
  return [];
25
25
  }
26
- const { offers } = yield repos.offer.findOffersByOfferCatalogId({
26
+ const { offers, sortedOfferIds } = yield repos.offer.findOffersByOfferCatalogId({
27
+ ids: params.ids,
27
28
  offerCatalog: { id: offerCatalogId },
28
29
  excludeAppliesToMovieTicket: false,
29
- sort: params.sort
30
+ limit: params.limit,
31
+ page: params.page,
32
+ sort: false,
33
+ onlyValid: params.onlyValid === true,
34
+ availableAtOrFrom: params.availableAt
30
35
  });
31
36
  return offers.map((o) => {
37
+ let sortIndex;
38
+ if (params.addSortIndex) {
39
+ sortIndex = sortedOfferIds.indexOf(String(o.id));
40
+ }
32
41
  const unitSpec = o.priceSpecification;
33
42
  const compoundPriceSpecification = {
34
- // 不要な属性を除外(2022-11-02~)
35
- // project: productWithOffers.project,
36
43
  typeOf: factory.priceSpecificationType.CompoundPriceSpecification,
37
44
  priceCurrency: factory.priceCurrency.JPY,
38
45
  valueAddedTaxIncluded: true,
@@ -40,10 +47,7 @@ function searchProductOffers(params) {
40
47
  ...(unitSpec !== undefined) ? [unitSpec] : []
41
48
  ]
42
49
  };
43
- return Object.assign(Object.assign({ additionalProperty: (Array.isArray(o.additionalProperty)) ? o.additionalProperty : [], alternateName: o.alternateName, availability: o.availability, availableAtOrFrom: o.availableAtOrFrom, color: o.color, description: o.description, id: o.id, identifier: o.identifier, itemOffered: o.itemOffered, name: o.name, priceCurrency: o.priceCurrency,
44
- // 不要な属性を除外(2022-11-07~)
45
- // project: o.project,
46
- typeOf: o.typeOf, priceSpecification: compoundPriceSpecification }, (o.validFrom instanceof Date) ? { validFrom: o.validFrom } : undefined), (o.validThrough instanceof Date) ? { validThrough: o.validThrough } : undefined);
50
+ return Object.assign(Object.assign(Object.assign({ additionalProperty: (Array.isArray(o.additionalProperty)) ? o.additionalProperty : [], alternateName: o.alternateName, availability: o.availability, availableAtOrFrom: o.availableAtOrFrom, color: o.color, description: o.description, id: o.id, identifier: o.identifier, itemOffered: o.itemOffered, name: o.name, priceCurrency: o.priceCurrency, typeOf: o.typeOf, priceSpecification: compoundPriceSpecification }, (o.validFrom instanceof Date) ? { validFrom: o.validFrom } : undefined), (o.validThrough instanceof Date) ? { validThrough: o.validThrough } : undefined), (typeof sortIndex === 'number') ? { sortIndex } : undefined);
47
51
  });
48
52
  });
49
53
  }
@@ -37,6 +37,10 @@ export { searchProductOffers };
37
37
  * プロダクトオファーを検索する
38
38
  */
39
39
  export declare function search(params: {
40
+ /**
41
+ * 指定したIDのオファーだけ取得する場合
42
+ */
43
+ ids?: string[];
40
44
  project: {
41
45
  id: string;
42
46
  };
@@ -50,7 +54,9 @@ export declare function search(params: {
50
54
  id: string;
51
55
  };
52
56
  onlyValid: boolean;
53
- sort: boolean;
57
+ limit?: number;
58
+ page?: number;
59
+ addSortIndex: boolean;
54
60
  }): (repos: {
55
61
  offer: OfferRepo;
56
62
  product: ProductRepo;
@@ -25,9 +25,8 @@ exports.ERROR_MESSAGE_ALREADY_REGISTERED = 'Already registered';
25
25
  */
26
26
  function search(params) {
27
27
  return (repos) => __awaiter(this, void 0, void 0, function* () {
28
- var _a, _b;
28
+ var _a;
29
29
  const now = moment();
30
- let offers = [];
31
30
  const searchProductsResult = yield repos.product.search({
32
31
  limit: 1,
33
32
  page: 1,
@@ -39,54 +38,63 @@ function search(params) {
39
38
  throw new factory.errors.NotFound('Product');
40
39
  }
41
40
  // 販売者指定の場合、検証
42
- if (typeof ((_a = params.seller) === null || _a === void 0 ? void 0 : _a.id) === 'string') {
43
- const productOffers = product.offers;
44
- if (!Array.isArray(productOffers)) {
45
- return offers;
46
- }
47
- const hasValidOffer = productOffers.some((o) => {
48
- var _a, _b;
49
- return ((_a = o.seller) === null || _a === void 0 ? void 0 : _a.id) === ((_b = params.seller) === null || _b === void 0 ? void 0 : _b.id)
50
- && o.validFrom !== undefined
51
- && moment(o.validFrom)
52
- .isSameOrBefore(now)
53
- && o.validThrough !== undefined
54
- && moment(o.validThrough)
55
- .isSameOrAfter(now);
56
- });
57
- if (!hasValidOffer) {
58
- return offers;
41
+ if (product.typeOf === factory.product.ProductType.MembershipService
42
+ || product.typeOf === factory.product.ProductType.PaymentCard) {
43
+ if (typeof ((_a = params.seller) === null || _a === void 0 ? void 0 : _a.id) === 'string') {
44
+ const productOffers = product.offers;
45
+ if (!Array.isArray(productOffers)) {
46
+ return [];
47
+ }
48
+ const hasValidOffer = productOffers.some((o) => {
49
+ var _a, _b;
50
+ return ((_a = o.seller) === null || _a === void 0 ? void 0 : _a.id) === ((_b = params.seller) === null || _b === void 0 ? void 0 : _b.id)
51
+ && o.validFrom !== undefined
52
+ && moment(o.validFrom)
53
+ .isSameOrBefore(now)
54
+ && o.validThrough !== undefined
55
+ && moment(o.validThrough)
56
+ .isSameOrAfter(now);
57
+ });
58
+ if (!hasValidOffer) {
59
+ return [];
60
+ }
59
61
  }
60
62
  }
61
- offers = yield (0, searchProductOffers_1.searchProductOffers)({
63
+ // let offers: factory.product.ITicketOffer[] = [];
64
+ return (0, searchProductOffers_1.searchProductOffers)({
65
+ ids: params.ids,
62
66
  itemOffered: { id: params.itemOffered.id },
63
- sort: params.sort
67
+ availableAt: params.availableAt,
68
+ onlyValid: params.onlyValid,
69
+ addSortIndex: params.addSortIndex
64
70
  })(repos);
71
+ // Mongoへ移行(2023-03-01~)
65
72
  // 店舗条件によって対象を絞る
66
- const storeId = (_b = params.availableAt) === null || _b === void 0 ? void 0 : _b.id;
67
- if (typeof storeId === 'string') {
68
- // アプリケーションが利用可能なオファーに絞る
69
- offers = offers.filter((o) => {
70
- return Array.isArray(o.availableAtOrFrom)
71
- && o.availableAtOrFrom.some((availableApplication) => availableApplication.id === storeId);
72
- });
73
- }
73
+ // const storeId = params.availableAt?.id;
74
+ // if (typeof storeId === 'string') {
75
+ // // アプリケーションが利用可能なオファーに絞る
76
+ // offers = offers.filter((o) => {
77
+ // return Array.isArray(o.availableAtOrFrom)
78
+ // && o.availableAtOrFrom.some((availableApplication) => availableApplication.id === storeId);
79
+ // });
80
+ // }
81
+ // Mongoへ移行(2023-03-01~)
74
82
  // 有効期間を適用
75
- if (params.onlyValid === true) {
76
- offers = offers.filter((o) => {
77
- let isValid = true;
78
- if (o.validFrom !== undefined && moment(o.validFrom)
79
- .isAfter(now)) {
80
- isValid = false;
81
- }
82
- if (o.validThrough !== undefined && moment(o.validThrough)
83
- .isBefore(now)) {
84
- isValid = false;
85
- }
86
- return isValid;
87
- });
88
- }
89
- return offers;
83
+ // if (params.onlyValid === true) {
84
+ // offers = offers.filter((o) => {
85
+ // let isValid = true;
86
+ // if (o.validFrom !== undefined && moment(o.validFrom)
87
+ // .isAfter(now)) {
88
+ // isValid = false;
89
+ // }
90
+ // if (o.validThrough !== undefined && moment(o.validThrough)
91
+ // .isBefore(now)) {
92
+ // isValid = false;
93
+ // }
94
+ // return isValid;
95
+ // });
96
+ // }
97
+ // return offers;
90
98
  });
91
99
  }
92
100
  exports.search = search;
@@ -202,8 +210,7 @@ function fixProductAndOffers(params) {
202
210
  if (product === undefined) {
203
211
  throw new factory.errors.NotFound('Product');
204
212
  }
205
- const availableOffers = yield search(Object.assign(Object.assign({ project: { id: params.project.id }, itemOffered: { id: String(product.id) }, onlyValid: true }, (typeof ((_c = params.location) === null || _c === void 0 ? void 0 : _c.id) === 'string') ? { availableAt: { id: params.location.id } } : undefined), { sort: false // ソート不要(2023-01-27~)
206
- }))(repos);
213
+ const availableOffers = yield search(Object.assign({ ids: params.object.map((o) => String(o.id)), project: { id: params.project.id }, itemOffered: { id: String(product.id) }, onlyValid: true, addSortIndex: false }, (typeof ((_c = params.location) === null || _c === void 0 ? void 0 : _c.id) === 'string') ? { availableAt: { id: params.location.id } } : undefined))(repos);
207
214
  return { product, availableOffers };
208
215
  });
209
216
  }
@@ -218,7 +218,7 @@ function processAuthorizeProductOffer(params) {
218
218
  itemOffered: { id: params.product.id },
219
219
  seller: { id: String(seller.id) },
220
220
  onlyValid: true,
221
- sort: false // ソート不要(2023-01-27~)
221
+ addSortIndex: false
222
222
  })(repos);
223
223
  const acceptedProductOffer = offers.find((o) => o.identifier === acceptedOffer.identifier);
224
224
  if (acceptedProductOffer === undefined) {
package/package.json CHANGED
@@ -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.30"
123
+ "version": "20.4.0-alpha.32"
124
124
  }