Skip to content
Snippets Groups Projects
Commit 3a139939 authored by michael.minelli's avatar michael.minelli
Browse files

DojoBackendManager => Fix get user by type functions

parent a5606133
Branches
No related tags found
No related merge requests found
......@@ -17,6 +17,8 @@ import ClientsSharedConfig from '../sharedByClients/config/ClientsSharedConfig
import inquirer from 'inquirer';
import SharedConfig from '../shared/config/SharedConfig';
import ConfigFiles from '../config/ConfigFiles';
import SessionManager from './SessionManager';
import UserRole from '../sharedByClients/models/UserRole';
class DojoBackendManager {
......@@ -478,7 +480,7 @@ class DojoBackendManager {
public async getUserExercises(): Promise<Array<Exercise> | undefined> {
try {
const response = await axios.get<DojoBackendResponse<Array<Exercise>>>(DojoBackendHelper.getApiUrl(ApiRoute.EXERCISE_LIST));
const response = await axios.get<DojoBackendResponse<Array<Exercise>>>(DojoBackendHelper.getApiUrl(ApiRoute.USER_EXERCISES_LIST, { userId: SessionManager.profile?.id }));
return response.data.data;
} catch ( error ) {
console.error('Error fetching user exercises:', error);
......@@ -486,13 +488,13 @@ class DojoBackendManager {
}
}
public async getExerciseDetails(exerciseIdOrUrl: string): Promise<Exercise | undefined> {
public async getExercise(exerciseIdOrUrl: string): Promise<Exercise | undefined> {
try {
const response = await axios.get<Exercise>(DojoBackendHelper.getApiUrl(ApiRoute.EXERCISE_DETAILS_GET, {
const response = await axios.get<DojoBackendResponse<Exercise>>(DojoBackendHelper.getApiUrl(ApiRoute.EXERCISE_GET_DELETE, {
exerciseIdOrUrl: exerciseIdOrUrl
}));
return response.data;
return response.data.data;
} catch ( error ) {
console.error('Error fetching exercise details:', error);
return undefined;
......@@ -540,30 +542,19 @@ class DojoBackendManager {
}
}
public async getUsers(roleFilter?: string): Promise<Array<User> | undefined> {
public async getUsers(role?: string): Promise<Array<User> | undefined> {
try {
const response = await axios.get<DojoBackendResponse<Array<User>>>(DojoBackendHelper.getApiUrl(ApiRoute.USER_LIST), { params: roleFilter ? { roleFilter: roleFilter } : {} });
const response = await axios.get<DojoBackendResponse<Array<User>>>(DojoBackendHelper.getApiUrl(ApiRoute.USER_LIST), { params: role ? { role: role } : {} });
return response.data.data;
} catch ( error ) {
console.error('Error fetching professors:', error);
console.error('Error fetching users:', error);
return undefined;
}
}
public async getTeachers(): Promise<Array<User> | undefined> {
return this.getUsers('teacher');
}
public async getExerciseDetail(exerciseId: string): Promise<Exercise | undefined> {
try {
const response = await axios.get<Exercise>(DojoBackendHelper.getApiUrl(ApiRoute.EXERCISE_DETAIL).replace('{{exerciseId}}', String(exerciseId)));
return response.data;
} catch ( error ) {
console.error('Error fetching exercise details:', error);
return undefined;
}
return this.getUsers(UserRole.TEACHING_STAFF);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment