From ce2bc8f01be504f52eb2b70bb1682ca50266f2ef Mon Sep 17 00:00:00 2001 From: Oliwier Popielarczyk <71080644+olipop210@users.noreply.github.com> Date: Mon, 4 May 2026 23:11:58 +0200 Subject: [PATCH 1/3] feat: get registration rounds action add server action for fetching rounds for given registration --- src/actions/v2/get-registration-rounds.ts | 40 +++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/actions/v2/get-registration-rounds.ts diff --git a/src/actions/v2/get-registration-rounds.ts b/src/actions/v2/get-registration-rounds.ts new file mode 100644 index 0000000..e3d3743 --- /dev/null +++ b/src/actions/v2/get-registration-rounds.ts @@ -0,0 +1,40 @@ +import redis from "@/lib/redis"; +import { getOrSetRedis } from "@/lib/redis/get-set"; +import { fetchUsosApi } from "@/lib/usos"; + +interface UsosRegistrationRound { + id: string; + name: { + pl: string; + en: string; + }; + status: "active" | "preparing" | "closed"; + registration_mode: + | "double_for_courses" + | "double_for_group_with_ask" + | "double_group_manual" + | "direct_for__courses_and_groups"; + start_date: Date; + end_date: Date; +} + +export async function getRegistrationRoundsAction( + registrationId: string, +): Promise { + return getOrSetRedis({ + redis, + key: `usos:registration_rounds:${registrationId}`, + ttlSeconds: 60, + fetcher: async () => { + const data = await fetchUsosApi( + `registrations/course_registration_rounds`, + { + registration_id: registrationId, + fields: "fields=id|name|status|registration_mode|start_date|end_date", + }, + ); + + return data; + }, + }); +} From 867a182ac433805de6e0637726aa7e07e23dcf9c Mon Sep 17 00:00:00 2001 From: Oliwier Popielarczyk <71080644+olipop210@users.noreply.github.com> Date: Mon, 4 May 2026 23:16:31 +0200 Subject: [PATCH 2/3] feat: registration rounds action add sorting function --- src/actions/v2/get-registration-rounds.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/actions/v2/get-registration-rounds.ts b/src/actions/v2/get-registration-rounds.ts index e3d3743..e7c94c9 100644 --- a/src/actions/v2/get-registration-rounds.ts +++ b/src/actions/v2/get-registration-rounds.ts @@ -18,6 +18,13 @@ interface UsosRegistrationRound { end_date: Date; } +function sortByStartDateFn( + a: UsosRegistrationRound, + b: UsosRegistrationRound, +): number { + return new Date(a.start_date).getTime() - new Date(b.start_date).getTime(); +} + export async function getRegistrationRoundsAction( registrationId: string, ): Promise { @@ -34,7 +41,7 @@ export async function getRegistrationRoundsAction( }, ); - return data; + return data.sort(sortByStartDateFn); }, }); } From 7b2729f8f3c5f68017cda8c493fb5b33bea4a4ea Mon Sep 17 00:00:00 2001 From: Oliwier Popielarczyk <71080644+olipop210@users.noreply.github.com> Date: Mon, 4 May 2026 23:28:05 +0200 Subject: [PATCH 3/3] refactor: lint sort function naming --- src/actions/v2/get-registration-rounds.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/actions/v2/get-registration-rounds.ts b/src/actions/v2/get-registration-rounds.ts index e7c94c9..dada6be 100644 --- a/src/actions/v2/get-registration-rounds.ts +++ b/src/actions/v2/get-registration-rounds.ts @@ -18,7 +18,7 @@ interface UsosRegistrationRound { end_date: Date; } -function sortByStartDateFn( +function sortByStartDateFunction( a: UsosRegistrationRound, b: UsosRegistrationRound, ): number { @@ -41,7 +41,7 @@ export async function getRegistrationRoundsAction( }, ); - return data.sort(sortByStartDateFn); + return data.toSorted(sortByStartDateFunction); }, }); }