add more project saving stuff
This commit is contained in:
parent
d8f47d714b
commit
17836fcd88
2 changed files with 9 additions and 8 deletions
|
@ -1,14 +1,14 @@
|
||||||
import Project from '../models/project'
|
import Project from '../models/project'
|
||||||
|
|
||||||
export function createProject(req, res) {
|
export function createProject(req, res) {
|
||||||
Project.create({
|
let projectValues = {
|
||||||
user: req.user ? req.user._id : undefined,
|
user: req.user ? req.user._id : undefined,
|
||||||
name: req.body.name,
|
file: {}
|
||||||
file: {
|
}
|
||||||
name: req.body.file.name,
|
|
||||||
content: req.body.file.content
|
Object.assign(projectValues, req.body);
|
||||||
}
|
|
||||||
}, function(err, newProject) {
|
Project.create(projectValues, 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,
|
||||||
|
|
|
@ -41,6 +41,7 @@ export function saveProject() {
|
||||||
var state = getState();
|
var state = getState();
|
||||||
var formParams = Object.assign({}, state.project);
|
var formParams = Object.assign({}, state.project);
|
||||||
formParams.file = state.file;
|
formParams.file = state.file;
|
||||||
|
debugger;
|
||||||
if (state.id) {
|
if (state.id) {
|
||||||
axios.put(`${ROOT_URL}/projects/${state.id}`, formParams, {withCredentials: true})
|
axios.put(`${ROOT_URL}/projects/${state.id}`, formParams, {withCredentials: true})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
@ -78,6 +79,7 @@ export function createProject() {
|
||||||
return function(dispatch) {
|
return function(dispatch) {
|
||||||
axios.post(`${ROOT_URL}/projects`, {}, {withCredentials: true})
|
axios.post(`${ROOT_URL}/projects`, {}, {withCredentials: true})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
browserHistory.push('/projects/' + response.data.id);
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ActionTypes.NEW_PROJECT,
|
type: ActionTypes.NEW_PROJECT,
|
||||||
name: response.data.name,
|
name: response.data.name,
|
||||||
|
@ -87,7 +89,6 @@ export function createProject() {
|
||||||
content: response.data.file.content
|
content: response.data.file.content
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
browserHistory.push('/' + response.data.id);
|
|
||||||
})
|
})
|
||||||
.catch(response => dispatch({
|
.catch(response => dispatch({
|
||||||
type: ActionTypes.PROJECT_SAVE_FAIL
|
type: ActionTypes.PROJECT_SAVE_FAIL
|
||||||
|
|
Loading…
Reference in a new issue