Skip to content

Commit c4572fd

Browse files
committed
fix: add changes per requests
1 parent a85d2b1 commit c4572fd

File tree

4 files changed

+32
-15
lines changed

4 files changed

+32
-15
lines changed

backend/src/database/dashboard.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func (db *DB) GetFacilityAttendanceConcerns(ctx *models.QueryContext, facilityID
166166
JOIN program_class_enrollments e ON e.class_id = c.id
167167
WHERE c.status = ?
168168
AND c.archived_at IS NULL
169-
AND e.enrollment_status = ?`
169+
AND e.enrollment_status = ? `
170170
args := []any{models.Active, models.Enrolled}
171171
if facilityID != nil {
172172
attendanceSQL += "AND c.facility_id = ? "

backend/src/handlers/dashboard.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -264,18 +264,10 @@ func (srv *Server) handleFacilityHealthSummary(w http.ResponseWriter, r *http.Re
264264
claims := r.Context().Value(ClaimsKey).(*Claims)
265265
facility := r.URL.Query().Get("facility")
266266
var facilityID *uint
267-
switch facility {
268-
case "all":
267+
if facility == "all" && claims.canSwitchFacility() {
269268
facilityID = nil
270-
case "":
271-
facilityID = &claims.FacilityID
272-
default:
273-
facilityIDInt, err := strconv.Atoi(facility)
274-
if err != nil {
275-
return newInvalidIdServiceError(err, "facility")
276-
}
277-
ref := uint(facilityIDInt)
278-
facilityID = &ref
269+
} else {
270+
facilityID = &args.FacilityID
279271
}
280272

281273
days := 3

frontend-v2/src/lib/formatters.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,33 @@ export function getClassSchedule(cls: Class): ClassScheduleInfo {
130130

131131
export function isClassToday(cls: Class): boolean {
132132
const schedule = getClassSchedule(cls);
133-
const today = new Date().toLocaleDateString('en-US', { weekday: 'long' });
134-
return schedule.days.includes(today);
133+
const now = new Date();
134+
const todayName = now.toLocaleDateString('en-US', { weekday: 'long' });
135+
if (!schedule.days.includes(todayName)) {
136+
return false;
137+
}
138+
139+
const startOfToday = new Date(
140+
now.getFullYear(),
141+
now.getMonth(),
142+
now.getDate()
143+
);
144+
const endOfToday = new Date(
145+
now.getFullYear(),
146+
now.getMonth(),
147+
now.getDate(),
148+
23,
149+
59,
150+
59,
151+
999
152+
);
153+
const start = cls.start_dt ? new Date(cls.start_dt) : null;
154+
const end = cls.end_dt ? new Date(cls.end_dt) : null;
155+
const startOk =
156+
!start || Number.isNaN(start.getTime()) || start <= endOfToday;
157+
const endOk = !end || Number.isNaN(end.getTime()) || end >= startOfToday;
158+
159+
return startOk && endOk;
135160
}
136161

137162
export function getStatusColor(status: string): string {

frontend-v2/src/pages/Dashboard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default function Dashboard() {
5050
: '/api/program-classes/missing-attendance?days=3&all=true'
5151
);
5252
const { data: facilityHealthResp } = useSWR<
53-
ServerResponseOne<FacilityHealthSummary[]>
53+
ServerResponseMany<FacilityHealthSummary>
5454
>(
5555
deptAdmin
5656
? '/api/dashboard/facility-health?facility=all&days=3'

0 commit comments

Comments
 (0)