add more project saving stuff

This commit is contained in:
catarak 2016-06-20 16:29:08 -04:00
parent d8f47d714b
commit 17836fcd88
2 changed files with 9 additions and 8 deletions

View file

@ -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,

View file

@ -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