@chevre/domain 21.6.0-alpha.8 → 21.6.0-alpha.9

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.
@@ -24,6 +24,7 @@ async function main() {
24
24
  let i = 0;
25
25
  let updateCount = 0;
26
26
  let datePublishedUndefinedCount = 0;
27
+ let datePublishedIsAfterNowCount = 0;
27
28
  await cursor.eachAsync(async (doc) => {
28
29
  i += 1;
29
30
  const movie: chevre.factory.creativeWork.movie.ICreativeWork = doc.toObject();
@@ -38,6 +39,14 @@ async function main() {
38
39
 
39
40
  if (alreadyMigrated) {
40
41
  console.log('already exist...', movie.project.id, movie.id, movie.identifier, availabilityStarts, availabilityEnds, i);
42
+
43
+ if (moment(movie.datePublished)
44
+ .isAfter(moment())) {
45
+ datePublishedIsAfterNowCount += 1;
46
+ // tslint:disable-next-line:max-line-length
47
+ // throw new Error(`movie.datePublished isAfter now ${movie.project.id} ${movie.id} ${movie.identifier} ${movie.datePublished}`);
48
+
49
+ }
41
50
  } else {
42
51
  if (movie.datePublished === undefined) {
43
52
  console.error('movie.datePublished undefined', movie.project.id, movie.id, movie.identifier, i);
@@ -63,6 +72,8 @@ async function main() {
63
72
  console.log(i, 'creativeWorks checked');
64
73
  console.log(updateCount, 'creativeWorks updated');
65
74
  console.log(datePublishedUndefinedCount, 'datePublishedUndefinedCount');
75
+ console.log(datePublishedIsAfterNowCount, 'datePublishedIsAfterNowCount');
76
+
66
77
  }
67
78
 
68
79
  main()
@@ -155,8 +155,8 @@ function fixOrders(params) {
155
155
  // 不要な属性は参照しない
156
156
  acceptedOffers: 0,
157
157
  customer: 0,
158
- orderedItem: 0,
159
- paymentMethods: 0
158
+ orderedItem: 0
159
+ // paymentMethods: 0 // 適用決済方法検証に必要
160
160
  });
161
161
  if (orders.length !== params.object.order.length) {
162
162
  throw new factory.errors.NotFound('Order');
@@ -268,104 +268,20 @@ function findApplicableReturnPolicy(params) {
268
268
  };
269
269
  }
270
270
  const returnPolicies = params.returnPolicies;
271
- const returningDate = moment(params.returningDate);
271
+ // const returningDate = moment(params.returningDate);
272
272
  let applicalbleReturnPolicies = [];
273
273
  if (params.reason === factory.transaction.returnOrder.Reason.Customer) {
274
274
  // 適用可能なポリシーにフィルター
275
275
  // tslint:disable-next-line:max-func-body-length
276
276
  applicalbleReturnPolicies = returnPolicies.filter((returnPolicy) => {
277
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
278
- let satisfyMerchantReturnDays = false;
279
- let offerItemCondition;
280
- const itemConditionId = (_a = returnPolicy.itemCondition) === null || _a === void 0 ? void 0 : _a.id;
281
- if (typeof itemConditionId === 'string') {
282
- offerItemCondition = params.offerItemConditions.find((o) => o.id === itemConditionId);
283
- if (offerItemCondition === undefined) {
284
- throw new factory.errors.NotFound('OfferItemCondition');
285
- }
286
- }
287
- const merchantReturnDays = returnPolicy.merchantReturnDays;
288
- if (typeof merchantReturnDays === 'number') {
289
- // 返品適用日数を確認する
290
- const everyOrderApplicable = params.orders.every((order) => {
291
- const mustBeReturnedUntil = moment(order.orderDate)
292
- .add(merchantReturnDays, 'days');
293
- return mustBeReturnedUntil.isSameOrAfter(returningDate);
294
- });
295
- // 全注文について日数の確認ができれば適用
296
- if (everyOrderApplicable) {
297
- satisfyMerchantReturnDays = true;
298
- }
299
- }
300
- else {
301
- // 日数制限なし
302
- satisfyMerchantReturnDays = true;
303
- }
304
- // イベント開始猶予を検証する(2023-05-22~)
305
- let satisfyItemCondition = true;
306
- if (offerItemCondition !== undefined) {
307
- let satisfyGracePeriodMaxValue = true;
308
- let satisfyGracePeriodMinValue = true;
309
- // 全イベントについて猶予の確認ができれば適用
310
- const gracePeriodMaxValue = (_c = (_b = offerItemCondition.itemOffered.serviceOutput) === null || _b === void 0 ? void 0 : _b.reservationFor.gracePeriodBeforeStart) === null || _c === void 0 ? void 0 : _c.maxValue;
311
- const gracePeriodMinValue = (_e = (_d = offerItemCondition.itemOffered.serviceOutput) === null || _d === void 0 ? void 0 : _d.reservationFor.gracePeriodBeforeStart) === null || _e === void 0 ? void 0 : _e.minValue;
312
- if (typeof gracePeriodMaxValue === 'number') {
313
- satisfyGracePeriodMaxValue = params.events.every((event) => {
314
- return moment(event.startDate)
315
- .isSameOrBefore(moment(params.returningDate)
316
- .add(gracePeriodMaxValue, 'seconds'));
317
- });
318
- }
319
- if (typeof gracePeriodMinValue === 'number') {
320
- satisfyGracePeriodMinValue = params.events.every((event) => {
321
- return moment(event.startDate)
322
- .isAfter(moment(params.returningDate)
323
- .add(gracePeriodMinValue, 'seconds'));
324
- });
325
- }
326
- let satisfyGracePeriodInDaysMax = true;
327
- let satisfyGracePeriodInDaysMin = true;
328
- const gracePeriodBeforeStartInDaysMax = (_g = (_f = offerItemCondition.itemOffered.serviceOutput) === null || _f === void 0 ? void 0 : _f.reservationFor.gracePeriodBeforeStartInDays) === null || _g === void 0 ? void 0 : _g.max;
329
- if (typeof (gracePeriodBeforeStartInDaysMax === null || gracePeriodBeforeStartInDaysMax === void 0 ? void 0 : gracePeriodBeforeStartInDaysMax.period.value) === 'number'
330
- && typeof gracePeriodBeforeStartInDaysMax.time === 'string') {
331
- satisfyGracePeriodInDaysMax = params.events.every((event) => {
332
- const maxDate = moment(event.startDate)
333
- .tz(gracePeriodBeforeStartInDaysMax.timezone)
334
- .startOf('days')
335
- .subtract(gracePeriodBeforeStartInDaysMax.period.value, 'days')
336
- .format('YYYY-MM-DD');
337
- const returnMinDate = moment.tz(`${maxDate}T${gracePeriodBeforeStartInDaysMax.time}`, gracePeriodBeforeStartInDaysMax.timezone);
338
- debug('returnMinDate:', returnMinDate, 'returningDate:', returningDate);
339
- return returnMinDate.isSameOrBefore(moment(returningDate));
340
- });
341
- }
342
- debug('gracePeriodBeforeStartInDaysMax:', gracePeriodBeforeStartInDaysMax);
343
- const gracePeriodBeforeStartInDaysMin = (_j = (_h = offerItemCondition.itemOffered.serviceOutput) === null || _h === void 0 ? void 0 : _h.reservationFor.gracePeriodBeforeStartInDays) === null || _j === void 0 ? void 0 : _j.min;
344
- if (typeof (gracePeriodBeforeStartInDaysMin === null || gracePeriodBeforeStartInDaysMin === void 0 ? void 0 : gracePeriodBeforeStartInDaysMin.period.value) === 'number'
345
- && typeof gracePeriodBeforeStartInDaysMin.time === 'string') {
346
- satisfyGracePeriodInDaysMin = params.events.every((event) => {
347
- const minDate = moment(event.startDate)
348
- .tz(gracePeriodBeforeStartInDaysMin.timezone)
349
- .startOf('days')
350
- .subtract(gracePeriodBeforeStartInDaysMin.period.value, 'days')
351
- .format('YYYY-MM-DD');
352
- const returnMaxDate = moment.tz(`${minDate}T${gracePeriodBeforeStartInDaysMin.time}`, gracePeriodBeforeStartInDaysMin.timezone);
353
- debug('returnMaxDate:', returnMaxDate, 'returningDate:', returningDate);
354
- return returnMaxDate.isAfter(moment(returningDate));
355
- });
356
- }
357
- debug('satisfyGracePeriodInDaysMin:', satisfyGracePeriodInDaysMin);
358
- let satisfyOnlyUnused = true;
359
- if (((_k = offerItemCondition.itemOffered.serviceOutput) === null || _k === void 0 ? void 0 : _k.onlyUnused) === true) {
360
- if (params.usedReservationExists) {
361
- satisfyOnlyUnused = false;
362
- }
363
- }
364
- debug('usedReservationExists:', params.usedReservationExists, 'satisfyOnlyUnused:', satisfyOnlyUnused);
365
- satisfyItemCondition = satisfyGracePeriodMaxValue && satisfyGracePeriodMinValue
366
- && satisfyGracePeriodInDaysMax && satisfyGracePeriodInDaysMin && satisfyOnlyUnused;
367
- }
368
- return satisfyMerchantReturnDays && satisfyItemCondition;
277
+ return isSellerReturnPolicyApplicable({
278
+ returnPolicy,
279
+ events: params.events,
280
+ offerItemConditions: params.offerItemConditions,
281
+ orders: params.orders,
282
+ returningDate: params.returningDate,
283
+ usedReservationExists: params.usedReservationExists
284
+ });
369
285
  });
370
286
  }
371
287
  // 販売者にポリシーが存在しなければ返品不可
@@ -403,6 +319,119 @@ function findApplicableReturnPolicy(params) {
403
319
  return Object.assign({ merchantReturnDays: appliedReturnPolicy.merchantReturnDays, restockingFee: appliedReturnPolicy.restockingFee, returnFees,
404
320
  returnFeesMovieTicket, typeOf: appliedReturnPolicy.typeOf }, (typeof (appliedItemCondition === null || appliedItemCondition === void 0 ? void 0 : appliedItemCondition.typeOf) === 'string') ? { itemCondition: appliedItemCondition } : undefined);
405
321
  }
322
+ // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
323
+ function isSellerReturnPolicyApplicable(params) {
324
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
325
+ const returnPolicy = params.returnPolicy;
326
+ const returningDate = moment(params.returningDate);
327
+ let satisfyMerchantReturnDays = false;
328
+ let satisfyApplicablePaymentMethod = false;
329
+ let offerItemCondition;
330
+ const itemConditionId = (_a = returnPolicy.itemCondition) === null || _a === void 0 ? void 0 : _a.id;
331
+ if (typeof itemConditionId === 'string') {
332
+ offerItemCondition = params.offerItemConditions.find((o) => o.id === itemConditionId);
333
+ if (offerItemCondition === undefined) {
334
+ throw new factory.errors.NotFound('OfferItemCondition');
335
+ }
336
+ }
337
+ const merchantReturnDays = returnPolicy.merchantReturnDays;
338
+ if (typeof merchantReturnDays === 'number') {
339
+ // 返品適用日数を確認する
340
+ const everyOrderApplicable = params.orders.every((order) => {
341
+ const mustBeReturnedUntil = moment(order.orderDate)
342
+ .add(merchantReturnDays, 'days');
343
+ return mustBeReturnedUntil.isSameOrAfter(returningDate);
344
+ });
345
+ // 全注文について日数の確認ができれば適用
346
+ if (everyOrderApplicable) {
347
+ satisfyMerchantReturnDays = true;
348
+ }
349
+ }
350
+ else {
351
+ // 日数制限なし
352
+ satisfyMerchantReturnDays = true;
353
+ }
354
+ // 適用決済方法検証(2023-08-08~)
355
+ const applicablePaymentMethod = returnPolicy.applicablePaymentMethod;
356
+ if (Array.isArray(applicablePaymentMethod)) {
357
+ const everyOrderApplicable = params.orders.every((order) => {
358
+ // 全決済方法区分がapplicablePaymentMethodに含まれれば適用
359
+ return order.paymentMethods.every((paymentMethod) => applicablePaymentMethod.includes(paymentMethod.typeOf));
360
+ });
361
+ // 全注文について確認ができれば適用
362
+ if (everyOrderApplicable) {
363
+ satisfyApplicablePaymentMethod = true;
364
+ }
365
+ }
366
+ else {
367
+ satisfyApplicablePaymentMethod = true;
368
+ }
369
+ // イベント開始猶予を検証する(2023-05-22~)
370
+ let satisfyItemCondition = true;
371
+ if (offerItemCondition !== undefined) {
372
+ let satisfyGracePeriodMaxValue = true;
373
+ let satisfyGracePeriodMinValue = true;
374
+ // 全イベントについて猶予の確認ができれば適用
375
+ const gracePeriodMaxValue = (_c = (_b = offerItemCondition.itemOffered.serviceOutput) === null || _b === void 0 ? void 0 : _b.reservationFor.gracePeriodBeforeStart) === null || _c === void 0 ? void 0 : _c.maxValue;
376
+ const gracePeriodMinValue = (_e = (_d = offerItemCondition.itemOffered.serviceOutput) === null || _d === void 0 ? void 0 : _d.reservationFor.gracePeriodBeforeStart) === null || _e === void 0 ? void 0 : _e.minValue;
377
+ if (typeof gracePeriodMaxValue === 'number') {
378
+ satisfyGracePeriodMaxValue = params.events.every((event) => {
379
+ return moment(event.startDate)
380
+ .isSameOrBefore(moment(params.returningDate)
381
+ .add(gracePeriodMaxValue, 'seconds'));
382
+ });
383
+ }
384
+ if (typeof gracePeriodMinValue === 'number') {
385
+ satisfyGracePeriodMinValue = params.events.every((event) => {
386
+ return moment(event.startDate)
387
+ .isAfter(moment(params.returningDate)
388
+ .add(gracePeriodMinValue, 'seconds'));
389
+ });
390
+ }
391
+ let satisfyGracePeriodInDaysMax = true;
392
+ let satisfyGracePeriodInDaysMin = true;
393
+ const gracePeriodBeforeStartInDaysMax = (_g = (_f = offerItemCondition.itemOffered.serviceOutput) === null || _f === void 0 ? void 0 : _f.reservationFor.gracePeriodBeforeStartInDays) === null || _g === void 0 ? void 0 : _g.max;
394
+ if (typeof (gracePeriodBeforeStartInDaysMax === null || gracePeriodBeforeStartInDaysMax === void 0 ? void 0 : gracePeriodBeforeStartInDaysMax.period.value) === 'number'
395
+ && typeof gracePeriodBeforeStartInDaysMax.time === 'string') {
396
+ satisfyGracePeriodInDaysMax = params.events.every((event) => {
397
+ const maxDate = moment(event.startDate)
398
+ .tz(gracePeriodBeforeStartInDaysMax.timezone)
399
+ .startOf('days')
400
+ .subtract(gracePeriodBeforeStartInDaysMax.period.value, 'days')
401
+ .format('YYYY-MM-DD');
402
+ const returnMinDate = moment.tz(`${maxDate}T${gracePeriodBeforeStartInDaysMax.time}`, gracePeriodBeforeStartInDaysMax.timezone);
403
+ debug('returnMinDate:', returnMinDate, 'returningDate:', returningDate);
404
+ return returnMinDate.isSameOrBefore(moment(returningDate));
405
+ });
406
+ }
407
+ debug('gracePeriodBeforeStartInDaysMax:', gracePeriodBeforeStartInDaysMax);
408
+ const gracePeriodBeforeStartInDaysMin = (_j = (_h = offerItemCondition.itemOffered.serviceOutput) === null || _h === void 0 ? void 0 : _h.reservationFor.gracePeriodBeforeStartInDays) === null || _j === void 0 ? void 0 : _j.min;
409
+ if (typeof (gracePeriodBeforeStartInDaysMin === null || gracePeriodBeforeStartInDaysMin === void 0 ? void 0 : gracePeriodBeforeStartInDaysMin.period.value) === 'number'
410
+ && typeof gracePeriodBeforeStartInDaysMin.time === 'string') {
411
+ satisfyGracePeriodInDaysMin = params.events.every((event) => {
412
+ const minDate = moment(event.startDate)
413
+ .tz(gracePeriodBeforeStartInDaysMin.timezone)
414
+ .startOf('days')
415
+ .subtract(gracePeriodBeforeStartInDaysMin.period.value, 'days')
416
+ .format('YYYY-MM-DD');
417
+ const returnMaxDate = moment.tz(`${minDate}T${gracePeriodBeforeStartInDaysMin.time}`, gracePeriodBeforeStartInDaysMin.timezone);
418
+ debug('returnMaxDate:', returnMaxDate, 'returningDate:', returningDate);
419
+ return returnMaxDate.isAfter(moment(returningDate));
420
+ });
421
+ }
422
+ debug('satisfyGracePeriodInDaysMin:', satisfyGracePeriodInDaysMin);
423
+ let satisfyOnlyUnused = true;
424
+ if (((_k = offerItemCondition.itemOffered.serviceOutput) === null || _k === void 0 ? void 0 : _k.onlyUnused) === true) {
425
+ if (params.usedReservationExists) {
426
+ satisfyOnlyUnused = false;
427
+ }
428
+ }
429
+ debug('usedReservationExists:', params.usedReservationExists, 'satisfyOnlyUnused:', satisfyOnlyUnused);
430
+ satisfyItemCondition = satisfyGracePeriodMaxValue && satisfyGracePeriodMinValue
431
+ && satisfyGracePeriodInDaysMax && satisfyGracePeriodInDaysMin && satisfyOnlyUnused;
432
+ }
433
+ return satisfyMerchantReturnDays && satisfyApplicablePaymentMethod && satisfyItemCondition;
434
+ }
406
435
  /**
407
436
  * 注文中のオファーの返品ポリシーを検証
408
437
  */
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.324.0-alpha.4",
12
+ "@chevre/factory": "4.324.0-alpha.5",
13
13
  "@cinerino/sdk": "3.162.3",
14
14
  "@motionpicture/coa-service": "9.2.0",
15
15
  "@motionpicture/gmo-service": "5.2.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.6.0-alpha.8"
120
+ "version": "21.6.0-alpha.9"
121
121
  }