From d8f47d714b442ab4e16ec4de567db7110de2e4e6 Mon Sep 17 00:00:00 2001 From: catarak Date: Mon, 20 Jun 2016 13:46:01 -0400 Subject: [PATCH] save project without logging in --- server/controllers/project.controller.js | 36 +++++++++++------------- shared/redux/actions/project.js | 3 +- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/server/controllers/project.controller.js b/server/controllers/project.controller.js index d9900b98..6ed7d741 100644 --- a/server/controllers/project.controller.js +++ b/server/controllers/project.controller.js @@ -1,28 +1,24 @@ import Project from '../models/project' export function createProject(req, res) { - if (req.user) { - Project.create({ - user: req.user._id, - name: req.body.name, + Project.create({ + 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}); } + return res.json({ + id: newProject._id, + name: newProject.name, file: { - name: req.body.file.name, - content: req.body.file.content + name: newProject.file.name, + 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) { diff --git a/shared/redux/actions/project.js b/shared/redux/actions/project.js index 11028859..c5508800 100644 --- a/shared/redux/actions/project.js +++ b/shared/redux/actions/project.js @@ -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,