save project without logging in

This commit is contained in:
catarak 2016-06-20 13:46:01 -04:00
parent 44b41072c1
commit d8f47d714b
2 changed files with 18 additions and 21 deletions

View file

@ -1,28 +1,24 @@
import Project from '../models/project' import Project from '../models/project'
export function createProject(req, res) { export function createProject(req, res) {
if (req.user) { Project.create({
Project.create({ user: req.user ? req.user._id : undefined,
user: req.user._id, name: req.body.name,
name: req.body.name, file: {
name: req.body.file.name,
content: req.body.file.content
}
}, function(err, newProject) {
if (err) { return res.json({success: false}); }
return res.json({
id: newProject._id,
name: newProject.name,
file: { file: {
name: req.body.file.name, name: newProject.file.name,
content: req.body.file.content content: newProject.file.content
} }
}, function(err, newProject) { });
if (err) { return res.json({success: false}) } });
return res.json({
id: newProject._id,
name: newProject.name,
file: {
name: newProject.file.name,
content: newProject.file.content
}
});
});
} else {
res.json({success: false});
}
} }
export function updateProject(req, res) { export function updateProject(req, res) {

View file

@ -1,4 +1,5 @@
import * as ActionTypes from '../constants/constants' import * as ActionTypes from '../constants/constants'
import { browserHistory } from 'react-router'
import axios from 'axios' import axios from 'axios'
const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api'; const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api';
@ -54,7 +55,7 @@ export function saveProject() {
else { else {
axios.post(`${ROOT_URL}/projects`, formParams, {withCredentials: true}) axios.post(`${ROOT_URL}/projects`, formParams, {withCredentials: true})
.then(response => { .then(response => {
browserHistory.push('/' + response.data.id); browserHistory.push('/projects/' + response.data.id);
dispatch({ dispatch({
type: ActionTypes.NEW_PROJECT, type: ActionTypes.NEW_PROJECT,
name: response.data.name, name: response.data.name,