@revolugo/common 7.3.0-rc.0 → 7.3.0-rc.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revolugo/common",
3
- "version": "7.3.0-rc.0",
3
+ "version": "7.3.0-rc.2",
4
4
  "private": false,
5
5
  "description": "Revolugo common",
6
6
  "author": "Revolugo",
@@ -401,9 +401,10 @@ export function getCurrentPenaltyPercentage({
401
401
  })
402
402
  }
403
403
 
404
- export function isBetterCancellationPolicies(
404
+ function checkCancellationPolicies(
405
405
  newVal: ICancellationPolicy[],
406
406
  oldVal: ICancellationPolicy[],
407
+ orEqual: boolean,
407
408
  ): boolean {
408
409
  if (isEmpty(newVal)) {
409
410
  return true
@@ -413,27 +414,8 @@ export function isBetterCancellationPolicies(
413
414
  return false
414
415
  }
415
416
 
416
- if (!newVal[0]?.dateTo) {
417
- return oldVal.every(oldCancellationPolicy => {
418
- const relatedNewCancellationPolicy = newVal.find(newCancellationPolicy =>
419
- dayjs(oldCancellationPolicy.dateTo).isBetween(
420
- newCancellationPolicy.dateFrom,
421
- newCancellationPolicy.dateTo,
422
- null,
423
- '[]',
424
- ),
425
- )
426
-
427
- if (!relatedNewCancellationPolicy) {
428
- return true
429
- }
430
-
431
- return (
432
- oldCancellationPolicy.penaltyPercentage >=
433
- relatedNewCancellationPolicy.penaltyPercentage
434
- )
435
- })
436
- }
417
+ const isBetter = (oldPenalty: number, newPenalty: number) =>
418
+ orEqual ? oldPenalty >= newPenalty : oldPenalty > newPenalty
437
419
 
438
420
  return oldVal.every(oldCancellationPolicy => {
439
421
  const relatedNewCancellationPolicy = newVal.find(newCancellationPolicy =>
@@ -449,13 +431,27 @@ export function isBetterCancellationPolicies(
449
431
  return true
450
432
  }
451
433
 
452
- return (
453
- oldCancellationPolicy.penaltyPercentage >=
454
- relatedNewCancellationPolicy.penaltyPercentage
434
+ return isBetter(
435
+ oldCancellationPolicy.penaltyPercentage,
436
+ relatedNewCancellationPolicy.penaltyPercentage,
455
437
  )
456
438
  })
457
439
  }
458
440
 
441
+ export function isBetterCancellationPolicies(
442
+ newVal: ICancellationPolicy[],
443
+ oldVal: ICancellationPolicy[],
444
+ ): boolean {
445
+ return checkCancellationPolicies(newVal, oldVal, false)
446
+ }
447
+
448
+ export function isSameOrBetterCancellationPolicies(
449
+ newVal: ICancellationPolicy[],
450
+ oldVal: ICancellationPolicy[],
451
+ ): boolean {
452
+ return checkCancellationPolicies(newVal, oldVal, true)
453
+ }
454
+
459
455
  export function parseCancellationPolicies(
460
456
  cancellationPolicies: {
461
457
  dateFrom: string