Skip to content
Merged

Dev #63

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions src/api/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ClassPaginationParams } from "@/types/data";
* @returns {Promise<{ data?: { id: string }; error?: string }>} - The response from the server
*/
export const createClass = async (
newClass: ClassInfo
newClass: ClassInfo,
): Promise<{ id?: string; error?: string }> => {
try {
const response = await fetch(`${CLASS_ENDPOINT}/`, {
Expand Down Expand Up @@ -44,7 +44,7 @@ export const createClass = async (

export const updateClass = async (
classId: string,
updates: Partial<ClassInfo>
updates: Partial<ClassInfo>,
): Promise<{ id?: string; error?: string }> => {
try {
const response = await fetch(`${CLASS_ENDPOINT}/${classId}`, {
Expand Down Expand Up @@ -77,7 +77,7 @@ export const updateClass = async (
};

export const deleteClass = async (
classId: string
classId: string,
): Promise<{ success?: boolean; error?: string }> => {
try {
const response = await fetch(`${CLASS_ENDPOINT}/${classId}`, {
Expand Down Expand Up @@ -116,7 +116,7 @@ export const deleteClass = async (
*/
export const getClassesByInstructor = async (
instructorId: string,
includeStudents: boolean = false
includeStudents: boolean = false,
): Promise<{ data?: ClassData[]; error?: string }> => {
try {
const url = new URL(`${CLASS_ENDPOINT}/instructor/${instructorId}`);
Expand Down Expand Up @@ -188,7 +188,7 @@ export async function getClassesbyStudent(studentId: string): Promise<{
*/
export const registerUserClass = async (
userId: string,
classId: string
classId: string,
): Promise<{ success: boolean; error?: string }> => {
try {
const response = await fetch(`${CLASS_ENDPOINT}/register`, {
Expand Down Expand Up @@ -219,7 +219,7 @@ export const registerUserClass = async (

export const unregisterUserClass = async (
userId: string,
classId: string
classId: string,
): Promise<{ success: boolean; error?: string }> => {
try {
const response = await fetch(`${CLASS_ENDPOINT}/unregister`, {
Expand Down Expand Up @@ -252,7 +252,7 @@ export const unregisterUserClass = async (
* @returns {Promise<{ data?: UserActivityLogItem[]; error?: string }>} - The response from the server or an error message.
*/
export async function getClassActivityByInstructorId(
instructorId: string
instructorId: string,
): Promise<{ data: ActivityLogResponse; error?: string }> {
console.log("Fetching class activity for instructor:", instructorId);

Expand All @@ -279,6 +279,8 @@ export async function getClassActivityByInstructorId(
return { data: [] };
}

console.log("Log data", JSON.stringify(logs, null, 2));

return { data: logs };
} catch (err) {
return {
Expand All @@ -298,7 +300,7 @@ export async function getClassActivityByInstructorId(
export const updateStudentEnrollmentStatus = async (
classId: string,
studentId: string,
newStatus: EnrollmentStatus
newStatus: EnrollmentStatus,
): Promise<{ success: boolean; error?: string }> => {
try {
const response = await fetch(`${CLASS_ENDPOINT}/enrollment-status`, {
Expand Down Expand Up @@ -342,7 +344,7 @@ interface PaginatedClassResponse {
}

export async function getAllClasses(
params: ClassPaginationParams = {}
params: ClassPaginationParams = {},
): Promise<{
data?: PaginatedClassResponse;
error?: string;
Expand Down Expand Up @@ -392,7 +394,7 @@ export async function getAllClasses(
export async function updateClassStudentsSettings(
classId: string,
studentIds: string[],
settings: UserSettings
settings: UserSettings,
): Promise<{ data?: boolean; error?: string }> {
try {
const response = await fetch(
Expand All @@ -404,7 +406,7 @@ export async function updateClassStudentsSettings(
studentIds,
settings,
}),
}
},
);

const data = await response.json();
Expand All @@ -429,7 +431,7 @@ export async function getClassById(
includeStudents?: boolean;
userId?: string;
includeAllStatuses?: boolean;
}
},
): Promise<{
data?: ClassData;
error?: string;
Expand All @@ -440,7 +442,7 @@ export async function getClassById(
if (options?.includeStudents) {
searchParams.append(
"includeStudents",
options.includeStudents.toString()
options.includeStudents.toString(),
);
}

Expand All @@ -451,7 +453,7 @@ export async function getClassById(
if (options?.includeAllStatuses) {
searchParams.append(
"includeAllStatuses",
options.includeAllStatuses.toString()
options.includeAllStatuses.toString(),
);
}

Expand Down
Loading