Skip to content

Commit

Permalink
Merge pull request #127 from hmrc/MIBM-258
Browse files Browse the repository at this point in the history
[MIBM-258][JR] Overwrite DeclarationType
  • Loading branch information
sureshhmrc authored Nov 26, 2020
2 parents 114adc2 + 468c82a commit 3a06c13
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ trait StartController extends DeclarationJourneyController {
}
}

def overwriteDeclarationType(sessionId: SessionId) = {
val declarationJourney = DeclarationJourney(sessionId = sessionId, declarationType)

repo.upsert(declarationJourney).map { _ =>
next(sessionId)
}
}

request.session.get(SessionKeys.sessionId) match {
case None =>
DeclarationJourneyLogger.info(
Expand All @@ -54,6 +62,10 @@ trait StartController extends DeclarationJourneyController {
val sessionId = SessionId(id)

repo.findBySessionId(sessionId).flatMap{
case Some(journey) if journey.declarationType != declarationType =>
DeclarationJourneyLogger.info(
s"StartController. Persisted journey found with different declarationType, overwriting with ${declarationType.entryName}")
overwriteDeclarationType(sessionId)
case Some(_) =>
DeclarationJourneyLogger.info(s"StartController. Persisted journey found")
Future successful next(sessionId)
Expand Down

0 comments on commit 3a06c13

Please sign in to comment.