Merge branch 'master' into tonitch/front/pagesAPI
This commit is contained in:
@ -3,28 +3,34 @@
|
||||
*
|
||||
* TODO: On time of writing, the backend doesn't support these endpoints so it could be modified in the future.
|
||||
*/
|
||||
import { restGet } from './restConsumer.js'
|
||||
import { restGet, restPost } from './restConsumer.js'
|
||||
|
||||
/**
|
||||
* create a new register requests that can be recovered by the registering service
|
||||
* TODO: add info in the Object (I don't know what will be needed)
|
||||
*/
|
||||
export async function createRegister(){
|
||||
return restPost("/requests/register"});
|
||||
return restPost("/requests/register");
|
||||
}
|
||||
|
||||
/**
|
||||
* list all register request in a list of Objects
|
||||
*/
|
||||
export async function getRegisters(){
|
||||
return restGet("/requests/register")
|
||||
}
|
||||
|
||||
/**
|
||||
* Get info on a particular registering request
|
||||
* Shall return a list of
|
||||
* - id
|
||||
* - type
|
||||
* - lastName
|
||||
* - firstName
|
||||
* - address
|
||||
* - country
|
||||
* - birthdate
|
||||
* - email
|
||||
* - cursus
|
||||
* - degree
|
||||
*/
|
||||
export async function getRegisters(id){
|
||||
return restGet("/requests/register/" + id);
|
||||
if(id != null)
|
||||
return restGet("/requests/register/" + id);
|
||||
return restGet("/requests/register")
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,11 +1,60 @@
|
||||
import { restGet, restPost } from './restConsumer.js'
|
||||
|
||||
export async function login(user, pass, exp){
|
||||
return restPost("/login", {login: user, password: pass, expiration: exp});
|
||||
return restPost("/login", {identifier: user, password: pass, expirationDate: exp});
|
||||
}
|
||||
|
||||
export async function register(user, pass, mail){
|
||||
return restPost("/user", {name: user, password: pass, mail: mail});
|
||||
/**
|
||||
* Register a user (tokenless)
|
||||
*
|
||||
* @param firstname
|
||||
* @param lastname
|
||||
* @param birthdate
|
||||
* @param password
|
||||
* @param mail
|
||||
* @param address
|
||||
* @param country
|
||||
* @param cursus
|
||||
* @param imageId id of the image in database returned when uploaded
|
||||
*/
|
||||
export async function register(firstname, lastname, birthDate, password, email, address, country, cursus, imageId){
|
||||
return restPost("/register", {
|
||||
firstname: firstname,
|
||||
lastname: lastname,
|
||||
birthDate: birthDate,
|
||||
password: password,
|
||||
email: email,
|
||||
address: address,
|
||||
country: country,
|
||||
cursus: cursus
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 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,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -18,6 +67,25 @@ export async function getUser(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
|
||||
*/
|
||||
@ -25,3 +93,27 @@ export async function getAllUsers(){
|
||||
return restGet("/users");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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(data){
|
||||
return restPatch("/user", data);
|
||||
}
|
||||
|
@ -8,15 +8,20 @@ export async function restGet(endPoint) {
|
||||
}
|
||||
|
||||
export async function restPost(endPoint, data) {
|
||||
return await _rest(endPoint, {method: "POST", body: data});
|
||||
return await _rest(endPoint, {method: "POST", credentials: 'include', body: JSON.stringify(data)});
|
||||
}
|
||||
|
||||
export async function restPostFile(endPoint, file){
|
||||
let headers = new Headers();
|
||||
return await _rest(endPoint, {method: "POST", credentials: 'include', body: file, headers: headers });
|
||||
}
|
||||
|
||||
export async function restDelete(endPoint, data) {
|
||||
return await _rest(endPoint, {method: "DELETE", body: data});
|
||||
return await _rest(endPoint, {method: "DELETE", credentials: 'include', body: JSON.stringify(data)});
|
||||
}
|
||||
|
||||
export async function restPatch(endPoint, data) {
|
||||
return await _rest(endPoint, {method: "PATCH", body: data});
|
||||
return await _rest(endPoint, {method: "PATCH", credentials: 'include', body: JSON.stringify(data)});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -31,14 +36,18 @@ export async function restPatch(endPoint, data) {
|
||||
async function _rest(endPoint, config){
|
||||
endPoint.at(0) != "/" ? console.error("Carefull, you certainly should put a / at the begenning of your endPoint ") : true;
|
||||
let session_token = getCookie("session_token");
|
||||
let headers = new Headers({'Authorization': session_token});
|
||||
config['headers'] = headers;
|
||||
let headers = new Headers({
|
||||
'Authorization': session_token,
|
||||
'Content-Type': 'application/json',
|
||||
});
|
||||
config['headers'] = config['headers'] == null ? headers : config['headers'];
|
||||
return toast.promise(fetch(restURL + endPoint, config),
|
||||
{
|
||||
pending: config['pending'] != null ? config['pending'] : 'pending',
|
||||
error: config['error'] != null ? config['error'] : 'Network Failure...',
|
||||
success: config['success'] != null ? config['success'] : {render(res){
|
||||
return res.ok ? "Success" : "error";
|
||||
console.log(res);
|
||||
return res.data.ok ? "Success" : "error";
|
||||
}},
|
||||
})
|
||||
.then( e => e.json()).catch( e => e );
|
||||
|
11
frontend/src/rest/uploads.js
Normal file
11
frontend/src/rest/uploads.js
Normal file
@ -0,0 +1,11 @@
|
||||
import { restPostFile } from '@/rest/restConsumer.js'
|
||||
|
||||
|
||||
/**
|
||||
* Upload a file to the server and return the url of this image
|
||||
*/
|
||||
export async function uploadProfilePicture(file){
|
||||
const formData = new FormData();
|
||||
formData.append("file", file[0]);
|
||||
return restPostFile("/upload/ProfilePicture", formData)
|
||||
}
|
Reference in New Issue
Block a user