2016-06-23 22:29:55 +00:00
|
|
|
import Project from '../models/project';
|
2016-06-17 18:11:52 +00:00
|
|
|
|
|
|
|
export function createProject(req, res) {
|
2016-06-23 22:29:55 +00:00
|
|
|
const projectValues = {
|
|
|
|
user: req.user ? req.user._id : undefined, // eslint-disable-line no-underscore-dangle
|
|
|
|
file: {}
|
|
|
|
};
|
2016-06-20 20:29:08 +00:00
|
|
|
|
2016-06-23 22:29:55 +00:00
|
|
|
Object.assign(projectValues, req.body);
|
|
|
|
|
|
|
|
Project.create(projectValues, (err, newProject) => {
|
|
|
|
if (err) { return res.json({ success: false }); }
|
|
|
|
return res.json({
|
|
|
|
id: newProject._id, // eslint-disable-line no-underscore-dangle
|
|
|
|
name: newProject.name,
|
|
|
|
file: {
|
|
|
|
name: newProject.file.name,
|
|
|
|
content: newProject.file.content
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2016-06-18 22:33:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function updateProject(req, res) {
|
2016-06-28 23:35:56 +00:00
|
|
|
Project.findByIdAndUpdate(req.params.project_id,
|
2016-06-23 22:29:55 +00:00
|
|
|
{
|
|
|
|
$set: req.body
|
|
|
|
}, (err, updatedProject) => {
|
|
|
|
if (err) { return res.json({ success: false }); }
|
|
|
|
return res.json({
|
|
|
|
id: updatedProject._id, // eslint-disable-line no-underscore-dangle
|
|
|
|
name: updatedProject.name,
|
|
|
|
file: {
|
|
|
|
name: updatedProject.file.name,
|
|
|
|
content: updatedProject.file.content
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2016-06-18 22:33:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getProject(req, res) {
|
2016-06-23 22:29:55 +00:00
|
|
|
Project.findById(req.params.project_id, (err, project) => {
|
|
|
|
if (err) {
|
|
|
|
return res.status(404).send({ message: 'Project with that id does not exist' });
|
|
|
|
}
|
2016-06-20 17:29:32 +00:00
|
|
|
|
2016-06-23 22:29:55 +00:00
|
|
|
return res.json({
|
|
|
|
id: project._id, // eslint-disable-line no-underscore-dangle
|
|
|
|
name: project.name,
|
|
|
|
file: {
|
|
|
|
name: project.file.name,
|
2016-06-29 16:52:16 +00:00
|
|
|
content: project.file.content
|
2016-06-23 22:29:55 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|