LeoMoulin
4199663d64
- Rework the inscription requests system so that it considers the equivalence systems and the impact of the teacher in the inscription procedure.
156 lines
3.3 KiB
JavaScript
156 lines
3.3 KiB
JavaScript
import { restGet, restPost, restPatch, restDelete} from './restConsumer.js'
|
|
import { getCookie, setCookie } from '@/utils.js'
|
|
|
|
export async function login(user, pass, exp){
|
|
return restPost("/login", {identifier: user, password: pass, expirationDate: exp});
|
|
}
|
|
|
|
export function isLogged(){
|
|
return getCookie("session_token") != ""
|
|
}
|
|
|
|
export function disconnect(){
|
|
setCookie("session_token", ";expires= Thu, 01 Jan 1970 00:00:01 GMT")
|
|
}
|
|
|
|
/**
|
|
* Register a user (tokenless)
|
|
*
|
|
* @param firstname
|
|
* @param lastname
|
|
* @param birthdate
|
|
* @param password
|
|
* @param mail
|
|
* @param address
|
|
* @param country
|
|
* @param curriculum
|
|
* @param imageId id of the image in database returned when uploaded
|
|
*/
|
|
export async function register(firstname, lastname, birthDate, password, email, address, country, curriculumId, imageId, identityCardId, submissionDate, equivalence){
|
|
return restPost("/register", {
|
|
firstName: firstname,
|
|
lastName: lastname,
|
|
birthDate: birthDate,
|
|
password: password,
|
|
email: email,
|
|
address: address,
|
|
country: country,
|
|
curriculumId: curriculumId,
|
|
profilePicture: imageId,
|
|
identityCard : identityCardId,
|
|
submissionDate : submissionDate,
|
|
equivalenceState : equivalence
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Register a user (by secretary)
|
|
*
|
|
* @param firstname
|
|
* @param lastname
|
|
* @param birthdate
|
|
* @param password
|
|
* @param mail
|
|
* @param address
|
|
* @param country
|
|
* @param imageId id of the image in database returned when uploaded
|
|
*
|
|
* PS: the password is not required as it is generated by the backend and sent to the user
|
|
* by mail. it's up to the user to change it if he cares about security
|
|
*/
|
|
export async function createUser(firstname, lastname, birthDate, email, address, country, role, imageId){
|
|
return restPost("/user", {
|
|
firstname: firstname,
|
|
lastname: lastname,
|
|
birthDate: birthDate,
|
|
password: password,
|
|
email: email,
|
|
address: address,
|
|
country: country,
|
|
});
|
|
}
|
|
|
|
/**
|
|
* get informations on a specific user.
|
|
* Leaving the id empty will return the user's value based on his token
|
|
* if the user is not authenticated. then an empty array should be returned
|
|
*/
|
|
export async function getUser(id){
|
|
const endpoint = "/user/" + id;
|
|
return restGet(endpoint);
|
|
}
|
|
|
|
/**
|
|
* Alterable datas of user.
|
|
* usage by secretary
|
|
*
|
|
* @param id regno of the user
|
|
* @param data data to change
|
|
*
|
|
* - lastName
|
|
* - firstName
|
|
* - birthDate
|
|
* - role
|
|
* - email
|
|
* - photo
|
|
* - Adress
|
|
*/
|
|
export async function alterUser(id, data){
|
|
return restPatch("/user/" + id, data);
|
|
}
|
|
|
|
/**
|
|
* Reserved for secretary roles. Allow to list all user on the plateform
|
|
*/
|
|
export async function getAllUsers(){
|
|
return restGet("/users");
|
|
}
|
|
|
|
/**
|
|
* Return the list of teachers
|
|
*
|
|
* @return a list of teachers
|
|
* each elements is of the form
|
|
* - id
|
|
* - name
|
|
* - role
|
|
*/
|
|
export async function getTeachers(){
|
|
return restGet("/teachers")
|
|
}
|
|
|
|
|
|
export async function getStudents(){
|
|
return restGet("/students")
|
|
}
|
|
/**
|
|
* Get informations about yourself
|
|
* - RegNo
|
|
* - FirstName / LastName
|
|
* - email
|
|
* - adressId (?)
|
|
* - birthDate
|
|
* - role
|
|
*/
|
|
export async function getSelf(){
|
|
return restGet("/user");
|
|
}
|
|
|
|
/**
|
|
* Alterable datas are
|
|
* - email
|
|
* - photo
|
|
* - Adress
|
|
* - Password
|
|
*/
|
|
export async function alterSelf(id,data){
|
|
console.log(data)
|
|
return restPatch("/user/"+id, data);
|
|
}
|
|
|
|
|
|
|
|
export async function deleteUser(id){
|
|
return restDelete("/user/" + id)
|
|
}
|