mirror of
https://github.com/kevin-DL/complete-node-bootcamp.git
synced 2026-01-19 06:05:22 +00:00
Initial commit 🚀
This commit is contained in:
25
4-natours/after-section-13/public/js/updateSettings.js
Normal file
25
4-natours/after-section-13/public/js/updateSettings.js
Normal file
@@ -0,0 +1,25 @@
|
||||
/* eslint-disable */
|
||||
import axios from 'axios';
|
||||
import { showAlert } from './alerts';
|
||||
|
||||
// type is either 'password' or 'data'
|
||||
export const updateSettings = async (data, type) => {
|
||||
try {
|
||||
const url =
|
||||
type === 'password'
|
||||
? 'http://127.0.0.1:3000/api/v1/users/updateMyPassword'
|
||||
: 'http://127.0.0.1:3000/api/v1/users/updateMe';
|
||||
|
||||
const res = await axios({
|
||||
method: 'PATCH',
|
||||
url,
|
||||
data
|
||||
});
|
||||
|
||||
if (res.data.status === 'success') {
|
||||
showAlert('success', `${type.toUpperCase()} updated successfully!`);
|
||||
}
|
||||
} catch (err) {
|
||||
showAlert('error', err.response.data.message);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user