diff --git a/server/controllers/project.controller.js b/server/controllers/project.controller.js index 6ed7d741..45537997 100644 --- a/server/controllers/project.controller.js +++ b/server/controllers/project.controller.js @@ -1,14 +1,14 @@ import Project from '../models/project' export function createProject(req, res) { - Project.create({ + let projectValues = { user: req.user ? req.user._id : undefined, - name: req.body.name, - file: { - name: req.body.file.name, - content: req.body.file.content - } - }, function(err, newProject) { + file: {} + } + + Object.assign(projectValues, req.body); + + Project.create(projectValues, function(err, newProject) { if (err) { return res.json({success: false}); } return res.json({ id: newProject._id, diff --git a/shared/redux/actions/project.js b/shared/redux/actions/project.js index c5508800..6636b017 100644 --- a/shared/redux/actions/project.js +++ b/shared/redux/actions/project.js @@ -41,6 +41,7 @@ export function saveProject() { var state = getState(); var formParams = Object.assign({}, state.project); formParams.file = state.file; + debugger; if (state.id) { axios.put(`${ROOT_URL}/projects/${state.id}`, formParams, {withCredentials: true}) .then(response => { @@ -78,6 +79,7 @@ export function createProject() { return function(dispatch) { axios.post(`${ROOT_URL}/projects`, {}, {withCredentials: true}) .then(response => { + browserHistory.push('/projects/' + response.data.id); dispatch({ type: ActionTypes.NEW_PROJECT, name: response.data.name, @@ -87,7 +89,6 @@ export function createProject() { content: response.data.file.content } }); - browserHistory.push('/' + response.data.id); }) .catch(response => dispatch({ type: ActionTypes.PROJECT_SAVE_FAIL