Skip to content

Commit e8286ef

Browse files
authored
Merge pull request #7942 from espoon-voltti/present-in-group-fix
Korjataan mobiiliin "Muu syy" -tyyppisten työaikakirjausten muokkaus
2 parents 3577ca4 + f55a6cb commit e8286ef

File tree

8 files changed

+54
-28
lines changed

8 files changed

+54
-28
lines changed

frontend/src/employee-mobile-frontend/staff-attendance/StaffAttendanceEditPage.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import HelsinkiDateTime from 'lib-common/helsinki-date-time'
4040
import LocalDate from 'lib-common/local-date'
4141
import LocalTime from 'lib-common/local-time'
4242
import { useQueryResult } from 'lib-common/query'
43+
import { presentInGroup } from 'lib-common/staff-attendance'
4344
import { useIdRouteParam } from 'lib-common/useRouteParams'
4445
import UnderRowStatusIcon from 'lib-components/atoms/StatusIcon'
4546
import Title from 'lib-components/atoms/Title'
@@ -73,7 +74,9 @@ import { StaffMemberPageContainer } from './components/StaffMemberPageContainer'
7374
import { staffAttendanceMutation, staffAttendanceQuery } from './queries'
7475
import { toStaff } from './utils'
7576

76-
const typesWithoutGroup: StaffAttendanceType[] = ['TRAINING', 'OTHER_WORK']
77+
const typesWithoutGroup: StaffAttendanceType[] = staffAttendanceTypes.filter(
78+
(type) => !presentInGroup(type)
79+
)
7780
const emptyGroupIdDomValue = ''
7881

7982
const getDeparted = (
@@ -126,7 +129,7 @@ const staffAttendanceForm = mapped(
126129
output.arrivedTime,
127130
output.departedTime
128131
),
129-
hasStaffOccupancyEffect: ['TRAINING', 'OTHER_WORK'].includes(output.type)
132+
hasStaffOccupancyEffect: typesWithoutGroup.includes(output.type)
130133
? false
131134
: output.occupancyEffect
132135
})
@@ -680,7 +683,7 @@ const StaffAttendanceEditor = ({
680683
</FixedSpaceRow>
681684
<Gap size="s" />
682685
{featureFlags.staffAttendanceTypes &&
683-
['TRAINING', 'OTHER_WORK'].includes(type.value()) ? null : (
686+
typesWithoutGroup.includes(type.value()) ? null : (
684687
<CheckboxF
685688
bind={occupancyEffect}
686689
label={i18n.staff.staffOccupancyEffect}

frontend/src/lib-common/staff-attendance.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44

55
import type { StaffAttendanceType } from './generated/api-types/attendance'
66

7-
export function presentInGroup(type: StaffAttendanceType) {
8-
return !(
9-
type === 'TRAINING' ||
10-
type === 'OTHER_WORK' ||
11-
type === 'SICKNESS' ||
12-
type === 'CHILD_SICKNESS'
13-
)
7+
const presentInGroupByType: Record<StaffAttendanceType, boolean> = {
8+
PRESENT: true,
9+
OTHER_WORK: false,
10+
TRAINING: false,
11+
OVERTIME: true,
12+
JUSTIFIED_CHANGE: true,
13+
SICKNESS: false,
14+
CHILD_SICKNESS: false
1415
}
16+
17+
export const presentInGroup = (type: StaffAttendanceType): boolean =>
18+
presentInGroupByType[type]

service/src/integrationTest/kotlin/fi/espoo/evaka/attendance/RealtimeStaffAttendanceControllerIntegrationTest.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import kotlin.test.assertEquals
3030
import org.junit.jupiter.api.BeforeEach
3131
import org.junit.jupiter.api.Test
3232
import org.junit.jupiter.api.assertThrows
33+
import org.junit.jupiter.params.ParameterizedTest
34+
import org.junit.jupiter.params.provider.EnumSource
3335
import org.springframework.beans.factory.annotation.Autowired
3436

3537
class RealtimeStaffAttendanceControllerIntegrationTest :
@@ -269,6 +271,32 @@ class RealtimeStaffAttendanceControllerIntegrationTest :
269271
}
270272
}
271273

274+
@ParameterizedTest
275+
@EnumSource(StaffAttendanceType::class)
276+
fun `Staff attendance type upsert works`(type: StaffAttendanceType) {
277+
realtimeStaffAttendanceController.upsertDailyStaffRealtimeAttendances(
278+
dbInstance(),
279+
unitSupervisor,
280+
MockEvakaClock(now),
281+
RealtimeStaffAttendanceController.StaffAttendanceBody(
282+
unitId = testDaycare.id,
283+
date = now.toLocalDate(),
284+
employeeId = testDecisionMaker_2.id,
285+
entries =
286+
listOf(
287+
RealtimeStaffAttendanceController.StaffAttendanceUpsert(
288+
id = null,
289+
groupId = groupId1.takeIf { type.presentInGroup() },
290+
arrived = now.minusHours(3),
291+
departed = now.minusHours(2),
292+
type = type,
293+
hasStaffOccupancyEffect = false,
294+
)
295+
),
296+
),
297+
)
298+
}
299+
272300
private fun getAttendances(unitId: DaycareId): StaffAttendanceResponse {
273301
return realtimeStaffAttendanceController.getRealtimeStaffAttendances(
274302
dbInstance(),

service/src/integrationTest/kotlin/fi/espoo/evaka/occupancy/OccupancyTest.kt

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -626,18 +626,7 @@ class OccupancyTest : PureJdbiTest(resetDbBeforeEach = true) {
626626
}
627627

628628
@ParameterizedTest(name = "Realized occupancy with realtime staff attendance type {0}")
629-
@EnumSource(
630-
names =
631-
[
632-
"PRESENT",
633-
"OVERTIME",
634-
"JUSTIFIED_CHANGE",
635-
"TRAINING",
636-
"OTHER_WORK",
637-
"SICKNESS",
638-
"CHILD_SICKNESS",
639-
]
640-
)
629+
@EnumSource(StaffAttendanceType::class)
641630
fun `calculateDailyGroupOccupancyValues with different realtime staff attendance types`(
642631
type: StaffAttendanceType
643632
) {

service/src/main/kotlin/fi/espoo/evaka/attendance/MobileUnitController.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ fun Database.Read.fetchUnitInfo(unitId: DaycareId, date: LocalDate): UnitInfo {
198198
WHERE sa.departed IS NULL AND dc.id = ${bind(unitId)}
199199
AND daterange(dg.start_date, dg.end_date, '[]') @> ${bind(date)}
200200
AND 'REALTIME_STAFF_ATTENDANCE' = ANY(dc.enabled_pilot_features)
201-
AND sa.type NOT IN ('OTHER_WORK', 'TRAINING')
201+
AND sa.type = ANY (${bind(StaffAttendanceType.PRESENT_IN_GROUP_TYPES)})
202202
203203
UNION ALL
204204

service/src/main/kotlin/fi/espoo/evaka/attendance/StaffAttendance.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ enum class StaffAttendanceType : DatabaseEnum {
4141
CHILD_SICKNESS -> false
4242
else -> true
4343
}
44+
45+
companion object {
46+
val PRESENT_IN_GROUP_TYPES = entries.filter { it.presentInGroup() }
47+
}
4448
}
4549

4650
data class CurrentDayStaffAttendanceResponse(

service/src/main/kotlin/fi/espoo/evaka/occupancy/Occupancy.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package fi.espoo.evaka.occupancy
66

77
import fi.espoo.evaka.absence.AbsenceCategory
88
import fi.espoo.evaka.application.fetchApplicationDetails
9+
import fi.espoo.evaka.attendance.StaffAttendanceType
910
import fi.espoo.evaka.attendance.occupancyCoefficientSeven
1011
import fi.espoo.evaka.daycare.CareType
1112
import fi.espoo.evaka.daycare.domain.ProviderType
@@ -299,7 +300,7 @@ FROM staff_attendance_realtime
299300
WHERE departed IS NOT NULL
300301
AND group_id = ANY(${bind(groups)})
301302
AND tstzrange(arrived, departed) && ${bind(range)}
302-
AND type = ANY($presentStaffAttendanceTypes)
303+
AND type = ANY(${bind(StaffAttendanceType.PRESENT_IN_GROUP_TYPES)})
303304
304305
UNION ALL
305306

service/src/main/kotlin/fi/espoo/evaka/occupancy/RealtimeOccupancy.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,6 @@ WHERE
175175
.toList<ChildOccupancyAttendance>()
176176
}
177177

178-
val presentStaffAttendanceTypes =
179-
"'{${StaffAttendanceType.entries.filter { it.presentInGroup() }.joinToString()}}'::staff_attendance_type[]"
180-
181178
fun Database.Read.getStaffOccupancyAttendances(
182179
unitId: DaycareId,
183180
timeRange: HelsinkiDateTimeRange,
@@ -194,7 +191,7 @@ FROM staff_attendance_realtime sa
194191
JOIN daycare_group dg ON dg.id = sa.group_id
195192
WHERE
196193
dg.daycare_id = ${bind(unitId)} AND tstzrange(sa.arrived, sa.departed) && ${bind(timeRange)} AND
197-
type = ANY($presentStaffAttendanceTypes) AND
194+
type = ANY(${bind(StaffAttendanceType.PRESENT_IN_GROUP_TYPES)}) AND
198195
${predicate(groupFilter.forTable("sa"))}
199196
200197
UNION ALL

0 commit comments

Comments
 (0)