Skip to content

Commit

Permalink
Refactor for clearer logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ha Pham committed Mar 13, 2024
1 parent ba203da commit f8e8ad2
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ fun main() {
.map { constraint ->
when (constraint.itemType) {
ChargebeeItemConstraint.ItemType.PLAN -> {
if (constraint.targetType == ChargebeeItemConstraint.TargetType.NONE) return@map constraint
appliedToPlan = true
val checkResult = checkPlanConstraint(constraint, discount)
if (checkResult.manualCheckNeeded) manualCheckNeeded = true
return@map checkResult.constraint
}

ChargebeeItemConstraint.ItemType.ADDON -> {
if (constraint.targetType == ChargebeeItemConstraint.TargetType.NONE) return@map constraint
appliedToAddon = true
val checkResult = checkAddonConstraint(
constraint,
Expand All @@ -61,8 +63,10 @@ fun main() {
}

ChargebeeItemConstraint.ItemType.CHARGE -> {
println("Coupon ${discount.id} is applied to CHARGES. Manual check needed.")
manualCheckNeeded = true
if (constraint.targetType != ChargebeeItemConstraint.TargetType.NONE) {
println("Coupon ${discount.id} is applied to CHARGES. Manual check needed.")
manualCheckNeeded = true
}
return@map constraint
}
}
Expand All @@ -73,10 +77,10 @@ fun main() {
println("Coupon ${discount.id} is applied to both PLANS and ADDONS. Manual check needed")
}

if (updatedConstraints.any { !discount.itemConstraints.contains(it) }) {
if (manualCheckNeeded) {
println("Skip coupon ${discount.id} for manual check")
} else if (!DRY_RUN ) {
if (manualCheckNeeded) {
println("Skip coupon ${discount.id} for manual check")
} else if (updatedConstraints.any { !discount.itemConstraints.contains(it) }) {
if (DRY_RUN) {
println("Skip updating coupon ${discount.id} in DRY RUN mode")
} else {
println("Updating coupon ${discount.id}...")
Expand Down

0 comments on commit f8e8ad2

Please sign in to comment.