save project without logging in
This commit is contained in:
parent
44b41072c1
commit
d8f47d714b
2 changed files with 18 additions and 21 deletions
|
@ -1,16 +1,15 @@
|
|||
import Project from '../models/project'
|
||||
|
||||
export function createProject(req, res) {
|
||||
if (req.user) {
|
||||
Project.create({
|
||||
user: req.user._id,
|
||||
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) {
|
||||
if (err) { return res.json({success: false}) }
|
||||
if (err) { return res.json({success: false}); }
|
||||
return res.json({
|
||||
id: newProject._id,
|
||||
name: newProject.name,
|
||||
|
@ -20,9 +19,6 @@ export function createProject(req, res) {
|
|||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
res.json({success: false});
|
||||
}
|
||||
}
|
||||
|
||||
export function updateProject(req, res) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import * as ActionTypes from '../constants/constants'
|
||||
import { browserHistory } from 'react-router'
|
||||
import axios from 'axios'
|
||||
|
||||
const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api';
|
||||
|
@ -54,7 +55,7 @@ export function saveProject() {
|
|||
else {
|
||||
axios.post(`${ROOT_URL}/projects`, formParams, {withCredentials: true})
|
||||
.then(response => {
|
||||
browserHistory.push('/' + response.data.id);
|
||||
browserHistory.push('/projects/' + response.data.id);
|
||||
dispatch({
|
||||
type: ActionTypes.NEW_PROJECT,
|
||||
name: response.data.name,
|
||||
|
|
Loading…
Reference in a new issue