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'
|
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._id,
|
user: req.user ? req.user._id : undefined,
|
||||||
name: req.body.name,
|
name: req.body.name,
|
||||||
file: {
|
file: {
|
||||||
name: req.body.file.name,
|
name: req.body.file.name,
|
||||||
content: req.body.file.content
|
content: req.body.file.content
|
||||||
}
|
}
|
||||||
}, function(err, newProject) {
|
}, function(err, newProject) {
|
||||||
if (err) { return res.json({success: false}) }
|
if (err) { return res.json({success: false}); }
|
||||||
return res.json({
|
return res.json({
|
||||||
id: newProject._id,
|
id: newProject._id,
|
||||||
name: newProject.name,
|
name: newProject.name,
|
||||||
|
@ -20,9 +19,6 @@ export function createProject(req, res) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
res.json({success: false});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateProject(req, res) {
|
export function updateProject(req, res) {
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue