2024-03-07 22:29:07 +01:00
|
|
|
/**
|
|
|
|
* Courses API
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { restGet, restPost, restDelete, restPatch } from './restConsumer.js'
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new course
|
|
|
|
*/
|
2024-03-18 14:51:27 +01:00
|
|
|
export async function createCourse(name, credits, owner){
|
|
|
|
console.log(owner);
|
|
|
|
|
|
|
|
return restPost("/course", {title: name, credits: credits, owner} )
|
2024-03-07 22:29:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete the specified course
|
|
|
|
*/
|
|
|
|
export async function deleteCourse(id){
|
|
|
|
return restDelete("/course/" + id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get informations on a particular course
|
|
|
|
*
|
|
|
|
* @param id identification of the course
|
|
|
|
*
|
|
|
|
* @return all atribute of the specified course
|
|
|
|
* - name
|
|
|
|
* - credits
|
|
|
|
* - faculty
|
|
|
|
* - teacher
|
|
|
|
* - assistants : list
|
|
|
|
*/
|
|
|
|
export async function getCourse(id){
|
|
|
|
return restGet("/course/" + id);
|
|
|
|
}
|
|
|
|
|
2024-03-13 18:22:28 +01:00
|
|
|
/**
|
|
|
|
* Get the list of courses to display on secretary's option
|
|
|
|
*
|
|
|
|
* @return list of courses of the form
|
|
|
|
* - id
|
|
|
|
* - name
|
|
|
|
* - credits
|
|
|
|
* - facutly
|
|
|
|
* - teacher
|
|
|
|
* - Assistants
|
|
|
|
*/
|
2024-03-17 21:38:10 +01:00
|
|
|
export async function getCourses(role){
|
|
|
|
if(role==="Teacher"){
|
|
|
|
return restGet("/courses/owned")
|
|
|
|
}
|
|
|
|
return restGet("/courses")
|
2024-03-13 18:22:28 +01:00
|
|
|
}
|
|
|
|
|
2024-03-17 21:38:10 +01:00
|
|
|
|
2024-03-07 22:29:07 +01:00
|
|
|
/**
|
|
|
|
* Change the options of a course
|
|
|
|
*
|
|
|
|
* @param id the id of the course
|
|
|
|
* @param changes Object with value to changes
|
|
|
|
*
|
|
|
|
* The changes object can contain:
|
|
|
|
* - name
|
|
|
|
* - credits
|
|
|
|
* - faculty
|
|
|
|
* - teacher
|
|
|
|
* - assistants: should be a list and will replace all assistants
|
|
|
|
*/
|
|
|
|
export async function alterCourse(id, changes){
|
|
|
|
return restPatch("/course/" + id, changes);
|
|
|
|
}
|