p5.js-web-editor/server/controllers/project.controller.js

56 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-06-17 18:11:52 +00:00
import Project from '../models/project'
export function createProject(req, res) {
2016-06-20 20:29:08 +00:00
let projectValues = {
2016-06-20 17:46:01 +00:00
user: req.user ? req.user._id : undefined,
2016-06-20 20:29:08 +00:00
file: {}
}
Object.assign(projectValues, req.body);
Project.create(projectValues, function(err, newProject) {
2016-06-20 17:46:01 +00:00
if (err) { return res.json({success: false}); }
return res.json({
id: newProject._id,
name: newProject.name,
2016-06-18 22:33:49 +00:00
file: {
2016-06-20 17:46:01 +00:00
name: newProject.file.name,
content: newProject.file.content
2016-06-18 22:33:49 +00:00
}
2016-06-20 17:46:01 +00:00
});
});
2016-06-18 22:33:49 +00:00
}
export function updateProject(req, res) {
Project.update({_id: req.params.project_id},
{
$set: req.body
}, function(err, updatedProject) {
if (err) { return res.json({success: false}) }
return res.json({
id: updatedProject._id,
name: updatedProject.name,
file: {
name: updatedProject.file.name,
content: updatedProject.file.content
}
});
});
}
export function getProject(req, res) {
2016-06-20 17:29:32 +00:00
Project.findById(req.params.project_id, function(err, project) {
if (err) {
return res.status(404).send({message: 'Project with that id does not exist'});
}
return res.json({
id: project._id,
name: project.name,
file: {
name: project.file.name,
content: project.file.conent
}
});
})
2016-06-17 18:11:52 +00:00
}