Skip to content
This repository was archived by the owner on Aug 2, 2025. It is now read-only.

Commit 6f27264

Browse files
committed
fix: move zod validation out of queries
fixes TIM-40: Remove non-fetch operations from queryFn to only exponentially backoff network requests
1 parent 079649c commit 6f27264

File tree

5 files changed

+23
-29
lines changed

5 files changed

+23
-29
lines changed

apps/client/src/consumers/sbhsApi/useDailyNotices.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import { noticesSchema, sbhsKey } from "./schemas";
44
import { useQuery } from "@tanstack/react-query";
55

66
const queryFn = async (authActions: OAuth2Actions) => {
7-
return noticesSchema.parse(
8-
await authActions.fetchAuthenticated("dailynews/list.json")
9-
);
7+
return await authActions.fetchAuthenticated("dailynews/list.json");
108
};
119

1210
const getQueryKey = sbhsKey("dailynews/list.json");
@@ -17,6 +15,7 @@ export const useDailyNotices = () => {
1715
return useQuery({
1816
queryKey: getQueryKey(),
1917
queryFn: () => queryFn(authActions),
18+
select: (data) => noticesSchema.parse(data),
2019
});
2120
};
2221

apps/client/src/consumers/sbhsApi/useDay.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@ const queryFn = async (
88
from?: string,
99
to?: string
1010
) => {
11-
return daySchema.parse(
12-
await authActions.fetchAuthenticated(
13-
"calendar/days.json",
14-
from && to
15-
? {
16-
from,
17-
to,
18-
}
19-
: undefined
20-
)
11+
return await authActions.fetchAuthenticated(
12+
"calendar/days.json",
13+
from && to
14+
? {
15+
from,
16+
to,
17+
}
18+
: undefined
2119
);
2220
};
2321

@@ -36,7 +34,7 @@ export const useDay = (from?: string, to?: string) => {
3634
: undefined
3735
),
3836
queryFn: () => queryFn(authActions, from, to),
39-
enabled: !!from && !!to,
37+
select: (data) => daySchema.parse(data),
4038
});
4139
};
4240

apps/client/src/consumers/sbhsApi/useDtt.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ import { dttSchema, sbhsKey } from "./schemas";
44
import { useQuery } from "@tanstack/react-query";
55

66
const queryFn = async (authActions: OAuth2Actions, date?: string) => {
7-
return dttSchema.parse(
8-
await authActions.fetchAuthenticated(
9-
"timetable/daytimetable.json",
10-
date
11-
? {
12-
date,
13-
}
14-
: undefined
15-
)
7+
return await authActions.fetchAuthenticated(
8+
"timetable/daytimetable.json",
9+
date
10+
? {
11+
date,
12+
}
13+
: undefined
1614
);
1715
};
1816

@@ -30,6 +28,7 @@ export const useDtt = (date?: string) => {
3028
: undefined
3129
),
3230
queryFn: () => queryFn(authActions, date),
31+
select: (data) => dttSchema.parse(data),
3332
});
3433
};
3534

apps/client/src/consumers/sbhsApi/useProfile.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import { profileSchema, sbhsKey } from "./schemas";
44
import { useQuery } from "@tanstack/react-query";
55

66
const queryFn = async (authActions: OAuth2Actions) =>
7-
profileSchema.parse(
8-
await authActions.fetchAuthenticated("details/userinfo.json")
9-
);
7+
await authActions.fetchAuthenticated("details/userinfo.json");
108

119
const getQueryKey = sbhsKey("details/userinfo.json");
1210

@@ -16,6 +14,7 @@ export const useProfile = () => {
1614
return useQuery({
1715
queryKey: getQueryKey(),
1816
queryFn: () => queryFn(authActions),
17+
select: (data) => profileSchema.parse(data),
1918
});
2019
};
2120

apps/client/src/consumers/sbhsApi/useTimetable.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import { timetableSchema, sbhsKey } from "./schemas";
44
import { useQuery } from "@tanstack/react-query";
55

66
const queryFn = async (authActions: OAuth2Actions) => {
7-
return timetableSchema.parse(
8-
await authActions.fetchAuthenticated("timetable/timetable.json")
9-
);
7+
return await authActions.fetchAuthenticated("timetable/timetable.json");
108
};
119

1210
const getQueryKey = sbhsKey("timetable/timetable.json");
@@ -17,6 +15,7 @@ export const useTimetable = () => {
1715
return useQuery({
1816
queryKey: getQueryKey(),
1917
queryFn: () => queryFn(authActions),
18+
select: (data) => timetableSchema.parse(data),
2019
});
2120
};
2221

0 commit comments

Comments
 (0)