unset RelayRound.startedAt upon reset if startsAt is in the future

master
Thibault Duplessis 2021-11-06 16:42:01 +01:00
parent ded25fffa0
commit 6014461860
2 changed files with 10 additions and 4 deletions

View File

@ -217,10 +217,15 @@ final class RelayApi(
}
}
def reset(relay: RelayRound, by: User): Funit =
studyApi.deleteAllChapters(relay.studyId, by) >>-
multiboard.invalidate(relay.studyId) >>
requestPlay(relay.id, v = true)
def reset(old: RelayRound, by: User): Funit =
WithRelay(old.id) { relay =>
studyApi.deleteAllChapters(relay.studyId, by) >> {
old.hasStartedEarly ?? roundRepo.coll.update
.one($id(relay.id), $set("finished" -> false) ++ $unset("startedAt"))
.void
} >>-
multiboard.invalidate(relay.studyId)
} >> requestPlay(old.id, v = true)
def deleteRound(roundId: RelayRound.Id): Fu[Option[RelayTour]] =
byIdWithTour(roundId) flatMap {

View File

@ -47,6 +47,7 @@ case class RelayRound(
)
def hasStarted = startedAt.isDefined
def hasStartedEarly = hasStarted && startsAt.exists(_ isAfter DateTime.now)
def shouldHaveStarted = hasStarted || startsAt.exists(_ isBefore DateTime.now)
def shouldGiveUp =