mirror of
https://github.com/lemeow125/StudE-Frontend.git
synced 2025-08-02 17:43:19 +08:00
Allow editing of user info
This commit is contained in:
parent
f24b84139b
commit
8de8e67070
3 changed files with 80 additions and 32 deletions
|
@ -4,7 +4,9 @@ import {
|
|||
ActivationParams,
|
||||
LoginParams,
|
||||
OnboardingParams,
|
||||
PatchStudentData,
|
||||
RegistrationParams,
|
||||
StudentData,
|
||||
} from "../../interfaces/Interfaces";
|
||||
|
||||
let debug = true;
|
||||
|
@ -43,6 +45,16 @@ export async function setRefreshToken(refresh: string) {
|
|||
return true;
|
||||
}
|
||||
|
||||
// Header Config Template for REST
|
||||
export async function GetConfig() {
|
||||
const accessToken = await getAccessToken();
|
||||
return {
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// User APIs
|
||||
export function UserRegister(register: RegistrationParams) {
|
||||
console.log(JSON.stringify(register));
|
||||
|
@ -105,13 +117,9 @@ export async function TokenRefresh() {
|
|||
});
|
||||
}
|
||||
export async function UserInfo() {
|
||||
const accessToken = await getAccessToken();
|
||||
const config = await GetConfig();
|
||||
return instance
|
||||
.get("/api/v1/accounts/users/me/", {
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
},
|
||||
})
|
||||
.get("/api/v1/accounts/users/me/", config)
|
||||
.then((response) => {
|
||||
// console.log(JSON.stringify(response.data));
|
||||
return [true, response.data];
|
||||
|
@ -124,6 +132,23 @@ export async function UserInfo() {
|
|||
});
|
||||
}
|
||||
|
||||
export async function PatchUserInfo(info: PatchStudentData) {
|
||||
const config = await GetConfig();
|
||||
return instance
|
||||
.patch("/api/v1/accounts/users/me/", info, config)
|
||||
.then((response) => {
|
||||
console.log(JSON.stringify(response.data));
|
||||
return [true, response.data];
|
||||
})
|
||||
.catch((error) => {
|
||||
let error_message = "";
|
||||
if (error.response) error_message = error.response.data;
|
||||
else error_message = "Unable to reach servers";
|
||||
console.log(error_message);
|
||||
return [false, error_message];
|
||||
});
|
||||
}
|
||||
|
||||
export function UserActivate(activation: ActivationParams) {
|
||||
return instance
|
||||
.post("/api/v1/accounts/users/activation/", activation)
|
||||
|
@ -178,13 +203,9 @@ export async function GetSemesters() {
|
|||
}
|
||||
|
||||
export async function GetYearLevels() {
|
||||
const accessToken = await getAccessToken();
|
||||
const config = await GetConfig();
|
||||
return instance
|
||||
.get("/api/v1/year_levels/", {
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
},
|
||||
})
|
||||
.get("/api/v1/year_levels/", config)
|
||||
.then((response) => {
|
||||
// console.log(JSON.stringify(response.data));
|
||||
return [true, response.data];
|
||||
|
@ -198,12 +219,9 @@ export async function GetYearLevels() {
|
|||
}
|
||||
|
||||
export async function OnboardingUpdateStudentInfo(info: OnboardingParams) {
|
||||
const accessToken = await getAccessToken();
|
||||
const headers = {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
};
|
||||
const config = await GetConfig();
|
||||
return instance
|
||||
.patch("/api/v1/accounts/users/me/", info, { headers })
|
||||
.patch("/api/v1/accounts/users/me/", info, config)
|
||||
.then((response) => {
|
||||
console.log(JSON.stringify(response.data));
|
||||
return [true, response.data];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue