frontend_adaptive_learning/src/roles/user/setting/services/SettingService.jsx

56 lines
1.2 KiB
React
Raw Normal View History

2024-10-31 02:32:14 +00:00
import axios from 'axios';
import { API_URL } from '../../../../utils/Constant';
const config = {
headers: {
Authorization: localStorage.getItem('token')
}
};
const fetchProfile = async () => {
try {
const response = await axios.get(`${API_URL}/getMe`, config);
return response.data;
} catch (error) {
throw error;
}
};
const updateProfile = async (id, formData) => {
const cfg = {
headers: {
'Content-Type': 'multipart/form-data',
Authorization: localStorage.getItem('token')
},
};
try {
const response = await axios.put(`${API_URL}/user/update/${id}`, formData, cfg);
return response.data;
} catch (error) {
throw error;
}
};
const updatePassword = async (userId, passwordData) => {
const cfg = {
headers: {
Authorization: localStorage.getItem('token'),
'Content-Type': 'application/json',
},
};
try {
const response = await axios.put(`${API_URL}/user/update/password/${userId}`, passwordData, cfg);
return response.data;
} catch (error) {
throw error;
}
};
export default {
fetchProfile,
updateProfile,
updatePassword
};