Skip to content

Commit

Permalink
[Mission] fix update attached reportings query
Browse files Browse the repository at this point in the history
  • Loading branch information
claire2212 committed Oct 16, 2023
1 parent cfc8971 commit 8850c4f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class CreateOrUpdateReporting(

var attachedToMissionAtUtc: ZonedDateTime? = null
var detachedFromMissionAtUtc: ZonedDateTime? = null
if (reporting.missionId != null) {
// TO CHECK if the date is with or without UTC
if (reporting.missionId != null && reporting.attachedToMissionAtUtc == null) {
attachedToMissionAtUtc = ZonedDateTime.now()
detachedFromMissionAtUtc = null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ interface IDBReportingRepository : JpaRepository<ReportingModel, Int> {
"""
UPDATE reportings
SET
mission_id = :missionId,
attached_to_mission_at_utc = CASE WHEN mission_id is null AND id in (:reportingIds) THEN NOW() ELSE attached_to_mission_at_utc END,
detached_from_mission_at_utc = CASE WHEN id not in (:reportingIds) THEN NOW() ELSE CAST(null as timestamp ) END
WHERE id in (:reportingIds)
""",
mission_id = :missionId,
attached_to_mission_at_utc = CASE WHEN (mission_id IS NULL OR mission_id = (:missionId)) AND id IN (:reportingIds) THEN NOW() ELSE attached_to_mission_at_utc END,
detached_from_mission_at_utc = CASE WHEN id NOT IN (:reportingIds) THEN NOW() ELSE NULL END
WHERE id in (:reportingIds) OR (mission_id = :missionId AND detached_from_mission_at_utc IS NULL)
""",
nativeQuery = true,
)
fun attachReportingsToMission(reportingIds: List<Int>, missionId: Int)
Expand Down

0 comments on commit 8850c4f

Please sign in to comment.