Skip to content

Commit

Permalink
resolved merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Bahugunajii committed Jan 8, 2024
2 parents b038c05 + 85c8d17 commit 7d52b2f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
20 changes: 20 additions & 0 deletions api/afdb/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,23 @@ export const getSessions = async (sessionId: number) => {
}
};

export const getGroupTypes = async (groupTypeId: number) => {
try {
const queryParams = new URLSearchParams({
id: groupTypeId.toString(),
type: "batch"
});
const urlWithParams = `${url}/group-type?${queryParams.toString()}`;
const response = await fetch(urlWithParams, getFetchConfig(bearerToken));

if (!response.ok) {
throw new Error(`Error in fetching Group Type Details: ${response.statusText}`);
}

const data = await response.json();
return data;
} catch (error) {
console.error("Error in fetching Group Type Details:", error);
throw error;
}
};
15 changes: 12 additions & 3 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { useAuth } from "@/services/AuthContext";
import TopBar from "@/components/TopBar";
import BottomNavigationBar from "@/components/BottomNavigationBar";
import { getSessions, getGroupUser, getGroupSessions } from "@/api/afdb/session";
import { getSessions, getGroupUser, getGroupSessions, getGroupTypes } from "@/api/afdb/session";
import { useState, useEffect } from "react";
import { GroupUser, GroupSession, Session } from "./types";
import Link from "next/link";
Expand All @@ -26,8 +26,17 @@ export default function Home() {
const groupUserData = await getGroupUser(userDbId!);

const groupSessions = await Promise.all(groupUserData.map(async (userData: GroupUser) => {
const groupSessionData = await getGroupSessions(userData.group_type_id);
return groupSessionData;
const groupType = await getGroupTypes(userData.group_type_id);

const groupTypeIds = groupType.map((type: any) => type.id);

const groupSessionData = await Promise.all(groupTypeIds.map(async (groupId: number) => {
return await getGroupSessions(groupId);
}));

const flattenedGroupSessions = groupSessionData.flat();

return flattenedGroupSessions;
}));

const flattenedGroupSessions = groupSessions.flat();
Expand Down

0 comments on commit 7d52b2f

Please sign in to comment.