Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
shtukas committed Nov 28, 2024
1 parent 90249fc commit 6e16895
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,14 @@ object NotificationHandler extends CohortHandler {
item: CohortItem,
subscription: ZuoraSubscription
): ZIO[CohortTable with Zuora, Failure, Unit] = {
// Known keys for this mapping can be found in the BillingPeriod object
val mapping: Map[String, Int] = Map(
"Month" -> 1,
"Quarter" -> 4,
"Quarterly" -> 4,
"Semi_Annual" -> 6,
"Annual" -> 12
)
for {
cancellationDate <- ZIO
.fromOption(SupporterPlus2024Migration.cancellationSaveDiscountEffectiveDate(subscription))
.orElseFail(DataExtractionFailure(s"Could not extract cancellation date for item ${item}"))
billingPeriod <- ZIO
.fromOption(item.billingPeriod)
.orElseFail(DataExtractionFailure(s"Could not extract billing period for item ${item}"))
months <- ZIO
.fromOption(mapping.get(billingPeriod))
.orElseFail(DataExtractionFailure(s"Could not extract mapping value for billing period ${billingPeriod}"))
months <- ZIO.succeed(CohortItem.billingPeriodToInt(billingPeriod))
_ <- CohortTable
.update(
CohortItem(
Expand Down
13 changes: 13 additions & 0 deletions lambda/src/main/scala/pricemigrationengine/model/CohortItem.scala
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,17 @@ object CohortItem {
}
}
}

def billingPeriodToInt(period: String): Int = {
// This function is used to convert a CohortItem's billingPeriod in to the number of months
// that the billing period represents.
period match {
case "Month" => 1
case "Quarter" => 3
case "Quarterly" => 3
case "Semi_Annual" => 6
case "Annual" => 12
case _ => throw new Exception(s"could no recover month count for period: ${period}")
}
}
}

0 comments on commit 6e16895

Please sign in to comment.