|
| 1 | +import type { ClassCreate, ClassFilters, ClassUpdate } from "../types/Class"; |
1 | 2 | import type { PlannedClass, PlanningFilters } from "../types/Planning"; |
| 3 | +import type { TeacherCreate, TeacherFilters, TeacherUpdate } from "../types/Teacher"; |
2 | 4 | import type { LoginCredentials } from "../types/User"; |
| 5 | +import { classApi } from "./endpoints/class"; |
3 | 6 | import { lessonApi } from "./endpoints/lesson"; |
4 | 7 | import { planningApi } from "./endpoints/planning"; |
| 8 | +import { reportApi } from "./endpoints/report"; |
5 | 9 | import { roomApi } from "./endpoints/room"; |
6 | 10 | import { sensorApi } from "./endpoints/sensor"; |
| 11 | +import { teacherApi } from "./endpoints/teacher"; |
7 | 12 | import { userApi } from "./endpoints/user"; |
8 | 13 | import { weatherApi } from "./endpoints/weather"; |
9 | 14 |
|
@@ -77,6 +82,12 @@ export const roomQueryOptions = { |
77 | 82 | staleTime: 60 * 60 * 1000, |
78 | 83 | }), |
79 | 84 |
|
| 85 | + roomNameOptions: () => ({ |
| 86 | + queryKey: ["room", "nameOptions"], |
| 87 | + queryFn: () => roomApi.getRoomNameOptions(), |
| 88 | + staleTime: 60 * 60 * 1000, |
| 89 | + }), |
| 90 | + |
80 | 91 | floorOptions: (building: string) => ({ |
81 | 92 | queryKey: ["room", "floorOptions", building], |
82 | 93 | queryFn: () => roomApi.getFloorOptions(building), |
@@ -170,6 +181,116 @@ export const roomQueryOptions = { |
170 | 181 | }), |
171 | 182 | }; |
172 | 183 |
|
| 184 | +export const reportQueryOptions = { |
| 185 | + reportCount: (filters = {}) => ({ |
| 186 | + queryKey: ["report", "count", filters], |
| 187 | + queryFn: () => reportApi.getReportsCount(filters), |
| 188 | + staleTime: 60 * 60 * 1000, |
| 189 | + }), |
| 190 | + |
| 191 | + createReport: () => ({ |
| 192 | + mutationKey: ["report", "createReport"], |
| 193 | + mutationFn: (data: { |
| 194 | + equipmentId: string; |
| 195 | + description: string; |
| 196 | + }) => reportApi.createReport(data), |
| 197 | + }), |
| 198 | + |
| 199 | + getReports: (filters = {}) => ({ |
| 200 | + queryKey: ["report", "allReports", filters], |
| 201 | + queryFn: () => reportApi.getReports(filters), |
| 202 | + staleTime: 60 * 60 * 1000, |
| 203 | + }), |
| 204 | + |
| 205 | + deleteReport: () => ({ |
| 206 | + mutationKey: ["report", "deleteReport"], |
| 207 | + mutationFn: (reportId: string) => reportApi.deleteReport(reportId), |
| 208 | + }), |
| 209 | + |
| 210 | + updateReport: () => ({ |
| 211 | + mutationKey: ["report", "updateReport"], |
| 212 | + mutationFn: ({ |
| 213 | + reportId, |
| 214 | + data, |
| 215 | + }: { |
| 216 | + reportId: string; |
| 217 | + data: { |
| 218 | + status: string; |
| 219 | + }; |
| 220 | + }) => reportApi.updateReport(reportId, data), |
| 221 | + }), |
| 222 | +} |
| 223 | + |
| 224 | +export const classQueryOptions = { |
| 225 | + classCount: (filters: ClassFilters = {}) => ({ |
| 226 | + queryKey: ["class", "count", filters], |
| 227 | + queryFn: () => classApi.getClassesCount(filters), |
| 228 | + staleTime: 60 * 60 * 1000, |
| 229 | + }), |
| 230 | + |
| 231 | + getClasses: (filters: ClassFilters = {}) => ({ |
| 232 | + queryKey: ["class", "allClasses", filters], |
| 233 | + queryFn: () => classApi.getClasses(filters), |
| 234 | + staleTime: 60 * 60 * 1000, |
| 235 | + }), |
| 236 | + |
| 237 | + createClass: () => ({ |
| 238 | + mutationKey: ["class", "createClass"], |
| 239 | + mutationFn: (data: ClassCreate) => classApi.createClass(data), |
| 240 | + }), |
| 241 | + |
| 242 | + updateClass: () => ({ |
| 243 | + mutationKey: ["class", "updateClass"], |
| 244 | + mutationFn: ({ |
| 245 | + classId, |
| 246 | + data, |
| 247 | + }: { |
| 248 | + classId: string; |
| 249 | + data: ClassUpdate; |
| 250 | + }) => classApi.updateClass(classId, data), |
| 251 | + }), |
| 252 | + |
| 253 | + deleteClass: () => ({ |
| 254 | + mutationKey: ["class", "deleteClass"], |
| 255 | + mutationFn: (classId: string) => classApi.deleteClass(classId), |
| 256 | + }), |
| 257 | +}; |
| 258 | + |
| 259 | +export const teacherQueryOptions = { |
| 260 | + teacherCount: (filters: TeacherFilters = {}) => ({ |
| 261 | + queryKey: ["teacher", "count", filters], |
| 262 | + queryFn: () => teacherApi.getTeachersCount(filters), |
| 263 | + staleTime: 60 * 60 * 1000, |
| 264 | + }), |
| 265 | + |
| 266 | + getTeachers: (filters: TeacherFilters = {}) => ({ |
| 267 | + queryKey: ["teacher", "allTeachers", filters], |
| 268 | + queryFn: () => teacherApi.getTeachers(filters), |
| 269 | + staleTime: 60 * 60 * 1000, |
| 270 | + }), |
| 271 | + |
| 272 | + createTeacher: () => ({ |
| 273 | + mutationKey: ["teacher", "createTeacher"], |
| 274 | + mutationFn: (data: TeacherCreate) => teacherApi.createTeacher(data), |
| 275 | + }), |
| 276 | + |
| 277 | + updateTeacher: () => ({ |
| 278 | + mutationKey: ["teacher", "updateTeacher"], |
| 279 | + mutationFn: ({ |
| 280 | + teacherId, |
| 281 | + data, |
| 282 | + }: { |
| 283 | + teacherId: string; |
| 284 | + data: TeacherUpdate; |
| 285 | + }) => teacherApi.updateTeacher(teacherId, data), |
| 286 | + }), |
| 287 | + |
| 288 | + deleteTeacher: () => ({ |
| 289 | + mutationKey: ["teacher", "deleteTeacher"], |
| 290 | + mutationFn: (teacherId: string) => teacherApi.deleteTeacher(teacherId), |
| 291 | + }), |
| 292 | +}; |
| 293 | + |
173 | 294 | export const lessonQueryOptions = { |
174 | 295 | deleteLesson: () => ({ |
175 | 296 | mutationFn: (lessonId: string) => lessonApi.deleteLesson(lessonId), |
|
0 commit comments