update preferences server side
This commit is contained in:
parent
c76b1353c3
commit
9f9425c5e9
4 changed files with 29 additions and 9 deletions
|
@ -51,5 +51,7 @@ export const DELETE_FILE = 'DELETE_FILE';
|
||||||
export const SHOW_EDIT_FILE_NAME = 'SHOW_EDIT_FILE_NAME';
|
export const SHOW_EDIT_FILE_NAME = 'SHOW_EDIT_FILE_NAME';
|
||||||
export const HIDE_EDIT_FILE_NAME = 'HIDE_EDIT_FILE_NAME';
|
export const HIDE_EDIT_FILE_NAME = 'HIDE_EDIT_FILE_NAME';
|
||||||
|
|
||||||
|
export const TOGGLE_AUTOSAVE = 'SET_AUTOSAVE';
|
||||||
|
|
||||||
// eventually, handle errors more specifically and better
|
// eventually, handle errors more specifically and better
|
||||||
export const ERROR = 'ERROR';
|
export const ERROR = 'ERROR';
|
||||||
|
|
|
@ -82,3 +82,10 @@ export function indentWithSpace() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setAutosave(value) {
|
||||||
|
return {
|
||||||
|
type: ActionTypes.SET_AUTOSAVE,
|
||||||
|
value
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -3,7 +3,8 @@ import * as ActionTypes from '../../../constants';
|
||||||
const initialState = {
|
const initialState = {
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
indentationAmount: 2,
|
indentationAmount: 2,
|
||||||
isTabIndent: true
|
isTabIndent: true,
|
||||||
|
autosave: true
|
||||||
};
|
};
|
||||||
|
|
||||||
const preferences = (state = initialState, action) => {
|
const preferences = (state = initialState, action) => {
|
||||||
|
|
|
@ -30,13 +30,23 @@ export function createUser(req, res, next) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updatePreferences(req, res) {
|
export function updatePreferences(req, res) {
|
||||||
User.findByIdAndUpdate(req.user._id,
|
User.findById(req.user.id, (err, user) => {
|
||||||
{
|
if (err) {
|
||||||
$set: req.body
|
return res.status(500).json({error: err});
|
||||||
})
|
}
|
||||||
.populate('preferences')
|
if (!user){
|
||||||
.exec((err, updatedPreferences) => {
|
return res.status(404).json({error: 'Document not found'});
|
||||||
if (err) return res.json({ success: false });
|
}
|
||||||
return res.json(updatedPreferences);
|
|
||||||
|
const preferences = Object.assign({}, user.preferences, req.body.preferences);
|
||||||
|
user.preferences = preferences;
|
||||||
|
|
||||||
|
user.save((err) => {
|
||||||
|
if (err) {
|
||||||
|
return res.status(500).json({error: err});
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.json(user.preferences);
|
||||||
});
|
});
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue