@chevre/domain 21.2.0-alpha.68 → 21.2.0-alpha.69

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.
@@ -23,7 +23,9 @@ export declare class MongoRepository {
23
23
  /**
24
24
  * 予約検索
25
25
  */
26
- search<T extends factory.reservationType>(params: factory.reservation.ISearchConditions<T>, projection?: any): Promise<factory.reservation.IReservation<factory.reservationType.EventReservation>[]>;
26
+ search<T extends factory.reservationType>(params: factory.reservation.ISearchConditions<T>, projection?: {
27
+ [key: string]: 0 | 1;
28
+ }): Promise<factory.reservation.IReservation<factory.reservationType.EventReservation>[]>;
27
29
  findById<T extends factory.reservationType>(params: {
28
30
  id: string;
29
31
  inclusion?: string[];
@@ -64,6 +64,7 @@ function start(params) {
64
64
  });
65
65
  }
66
66
  const policiesByOffer = yield searchPoliciesByOffer({ offers })(repos);
67
+ const { usedReservationExists } = yield checkUsedReservationExists({ orders })(repos);
67
68
  const appliedReturnPolicy = findApplicableReturnPolicy({
68
69
  acceptedOffers,
69
70
  events,
@@ -73,7 +74,8 @@ function start(params) {
73
74
  reason: params.object.reason,
74
75
  returnPolicies,
75
76
  offers,
76
- policiesByOffer
77
+ policiesByOffer,
78
+ usedReservationExists
77
79
  });
78
80
  validateAppliedReturnPolicy({ merchantReturnPolicy: appliedReturnPolicy });
79
81
  // アイテム検証
@@ -174,12 +176,9 @@ function validateOrder(params) {
174
176
  }
175
177
  });
176
178
  }
177
- function validateItems(params) {
179
+ function checkUsedReservationExists(params) {
178
180
  return (repos) => __awaiter(this, void 0, void 0, function* () {
179
- if (params.reason === factory.transaction.returnOrder.Reason.Seller) {
180
- // 販売者都合の場合、特に検証しない
181
- return;
182
- }
181
+ let usedReservationExists = false;
183
182
  // 注文に含まれる予約の状態検証
184
183
  const reservationNumbers = yield repos.order.searchReservationNumbersByOrderNumbers({
185
184
  orderNumber: { $in: params.orders.map((order) => order.orderNumber) }
@@ -192,11 +191,38 @@ function validateItems(params) {
192
191
  typeOf: factory.reservationType.EventReservation,
193
192
  reservationNumber: { $in: reservationNumbers },
194
193
  attended: true
195
- });
194
+ }, { _id: 1 });
196
195
  if (existingUsedReservations.length > 0) {
197
- throw new factory.errors.Argument('orderNumber', 'some reservations already used');
196
+ usedReservationExists = true;
198
197
  }
199
198
  }
199
+ return { usedReservationExists };
200
+ });
201
+ }
202
+ function validateItems(params) {
203
+ return (__) => __awaiter(this, void 0, void 0, function* () {
204
+ if (params.reason === factory.transaction.returnOrder.Reason.Seller) {
205
+ // 販売者都合の場合、特に検証しない
206
+ return;
207
+ }
208
+ // アイテムコンディション検証へ移行
209
+ // 注文に含まれる予約の状態検証
210
+ // const reservationNumbers = await repos.order.searchReservationNumbersByOrderNumbers({
211
+ // orderNumber: { $in: params.orders.map((order) => order.orderNumber) }
212
+ // });
213
+ // if (reservationNumbers.length > 0) {
214
+ // // 使用済の予約がひとつでもあれば不可
215
+ // const existingUsedReservations = await repos.reservation.search({
216
+ // limit: 1,
217
+ // page: 1,
218
+ // typeOf: factory.reservationType.EventReservation,
219
+ // reservationNumber: { $in: reservationNumbers },
220
+ // attended: true
221
+ // });
222
+ // if (existingUsedReservations.length > 0) {
223
+ // throw new factory.errors.Argument('orderNumber', 'some reservations already used');
224
+ // }
225
+ // }
200
226
  });
201
227
  }
202
228
  function searchPoliciesByOffer(params) {
@@ -225,6 +251,7 @@ function searchPoliciesByOffer(params) {
225
251
  */
226
252
  // tslint:disable-next-line:max-func-body-length
227
253
  function findApplicableReturnPolicy(params) {
254
+ var _a;
228
255
  if (params.reason === factory.transaction.returnOrder.Reason.Seller) {
229
256
  // 販売者都合の場合、手数料なしの返金返品ポリシーを適用
230
257
  return {
@@ -239,7 +266,7 @@ function findApplicableReturnPolicy(params) {
239
266
  // 適用可能なポリシーにフィルター
240
267
  // tslint:disable-next-line:max-func-body-length
241
268
  applicalbleReturnPolicies = returnPolicies.filter((returnPolicy) => {
242
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
269
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
243
270
  let satisfyMerchantReturnDays = false;
244
271
  let offerItemCondition;
245
272
  const itemConditionId = (_a = returnPolicy.itemCondition) === null || _a === void 0 ? void 0 : _a.id;
@@ -271,8 +298,6 @@ function findApplicableReturnPolicy(params) {
271
298
  if (offerItemCondition !== undefined) {
272
299
  let satisfyGracePeriodMaxValue = true;
273
300
  let satisfyGracePeriodMinValue = true;
274
- let satisfyGracePeriodInDaysMax = true;
275
- let satisfyGracePeriodInDaysMin = true;
276
301
  // 全イベントについて猶予の確認ができれば適用
277
302
  const gracePeriodMaxValue = (_c = (_b = offerItemCondition.itemOffered.serviceOutput) === null || _b === void 0 ? void 0 : _b.reservationFor.gracePeriodBeforeStart) === null || _c === void 0 ? void 0 : _c.maxValue;
278
303
  const gracePeriodMinValue = (_e = (_d = offerItemCondition.itemOffered.serviceOutput) === null || _d === void 0 ? void 0 : _d.reservationFor.gracePeriodBeforeStart) === null || _e === void 0 ? void 0 : _e.minValue;
@@ -290,6 +315,8 @@ function findApplicableReturnPolicy(params) {
290
315
  .add(gracePeriodMinValue, 'seconds'));
291
316
  });
292
317
  }
318
+ let satisfyGracePeriodInDaysMax = true;
319
+ let satisfyGracePeriodInDaysMin = true;
293
320
  const gracePeriodBeforeStartInDaysMax = (_g = (_f = offerItemCondition.itemOffered.serviceOutput) === null || _f === void 0 ? void 0 : _f.reservationFor.gracePeriodBeforeStartInDays) === null || _g === void 0 ? void 0 : _g.max;
294
321
  if (typeof (gracePeriodBeforeStartInDaysMax === null || gracePeriodBeforeStartInDaysMax === void 0 ? void 0 : gracePeriodBeforeStartInDaysMax.period.value) === 'number'
295
322
  && typeof gracePeriodBeforeStartInDaysMax.time === 'string') {
@@ -320,29 +347,18 @@ function findApplicableReturnPolicy(params) {
320
347
  });
321
348
  }
322
349
  debug('satisfyGracePeriodInDaysMin:', satisfyGracePeriodInDaysMin);
350
+ let satisfyOnlyUnused = true;
351
+ if (((_k = offerItemCondition.itemOffered.serviceOutput) === null || _k === void 0 ? void 0 : _k.onlyUnused) === true) {
352
+ if (params.usedReservationExists) {
353
+ satisfyOnlyUnused = false;
354
+ }
355
+ }
356
+ debug('usedReservationExists:', params.usedReservationExists, 'satisfyOnlyUnused:', satisfyOnlyUnused);
323
357
  satisfyItemCondition = satisfyGracePeriodMaxValue && satisfyGracePeriodMinValue
324
- && satisfyGracePeriodInDaysMax && satisfyGracePeriodInDaysMin;
358
+ && satisfyGracePeriodInDaysMax && satisfyGracePeriodInDaysMin && satisfyOnlyUnused;
325
359
  }
326
360
  return satisfyMerchantReturnDays && satisfyItemCondition;
327
361
  });
328
- // returnPolicies.forEach((returnPolicy) => {
329
- // const merchantReturnDays = returnPolicy.merchantReturnDays;
330
- // if (typeof merchantReturnDays === 'number') {
331
- // // 返品適用日数を確認する
332
- // const everyOrderApplicable = params.orders.every((order) => {
333
- // const mustBeReturnedUntil = moment(order.orderDate)
334
- // .add(merchantReturnDays, 'days');
335
- // return mustBeReturnedUntil.isSameOrAfter(returningDate);
336
- // });
337
- // // 全注文について日数の確認ができれば適用
338
- // if (everyOrderApplicable) {
339
- // applicalbleReturnPolicies.push(returnPolicy);
340
- // }
341
- // } else {
342
- // // 日数制限なし
343
- // applicalbleReturnPolicies.push(returnPolicy);
344
- // }
345
- // });
346
362
  }
347
363
  // 販売者にポリシーが存在しなければ返品不可
348
364
  if (applicalbleReturnPolicies.length === 0) {
@@ -368,13 +384,16 @@ function findApplicableReturnPolicy(params) {
368
384
  appliedReturnPolicy = returnPolicy;
369
385
  }
370
386
  });
371
- return {
372
- merchantReturnDays: appliedReturnPolicy.merchantReturnDays,
373
- restockingFee: appliedReturnPolicy.restockingFee,
374
- returnFees,
375
- returnFeesMovieTicket,
376
- typeOf: 'MerchantReturnPolicy'
377
- };
387
+ let appliedItemCondition;
388
+ const appliedItemConditionId = (_a = appliedReturnPolicy.itemCondition) === null || _a === void 0 ? void 0 : _a.id;
389
+ if (typeof appliedItemConditionId === 'string') {
390
+ appliedItemCondition = params.offerItemConditions.find((o) => o.id === appliedItemConditionId);
391
+ if (appliedItemCondition === undefined) {
392
+ throw new factory.errors.NotFound('OfferItemCondition');
393
+ }
394
+ }
395
+ return Object.assign({ merchantReturnDays: appliedReturnPolicy.merchantReturnDays, restockingFee: appliedReturnPolicy.restockingFee, returnFees,
396
+ returnFeesMovieTicket, typeOf: appliedReturnPolicy.typeOf }, (typeof (appliedItemCondition === null || appliedItemCondition === void 0 ? void 0 : appliedItemCondition.typeOf) === 'string') ? { itemCondition: appliedItemCondition } : undefined);
378
397
  }
379
398
  /**
380
399
  * 注文中のオファーの返品ポリシーを検証
package/package.json CHANGED
@@ -9,8 +9,8 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.313.0-alpha.10",
13
- "@cinerino/sdk": "3.157.0-alpha.0",
12
+ "@chevre/factory": "4.313.0-alpha.11",
13
+ "@cinerino/sdk": "3.157.0-alpha.1",
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.2.0-alpha.68"
120
+ "version": "21.2.0-alpha.69"
121
121
  }