Fixes #1409 - adds username to url when fetching sketch from editor API
This commit is contained in:
parent
1dcdfd39db
commit
47e798a7e6
4 changed files with 20 additions and 32 deletions
|
@ -49,10 +49,10 @@ export function setNewProject(project) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getProject(id) {
|
export function getProject(id, username) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
dispatch(justOpenedProject());
|
dispatch(justOpenedProject());
|
||||||
axios.get(`${ROOT_URL}/projects/${id}`, { withCredentials: true })
|
axios.get(`${ROOT_URL}/${username}/projects/${id}`, { withCredentials: true })
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
dispatch(setProject(response.data));
|
dispatch(setProject(response.data));
|
||||||
dispatch(setUnsavedChanges(false));
|
dispatch(setUnsavedChanges(false));
|
||||||
|
|
|
@ -53,9 +53,9 @@ class IDEView extends React.Component {
|
||||||
|
|
||||||
this.props.stopSketch();
|
this.props.stopSketch();
|
||||||
if (this.props.params.project_id) {
|
if (this.props.params.project_id) {
|
||||||
const id = this.props.params.project_id;
|
const { project_id: id, username } = this.props.params;
|
||||||
if (id !== this.props.project.id) {
|
if (id !== this.props.project.id) {
|
||||||
this.props.getProject(id);
|
this.props.getProject(id, username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,24 +63,20 @@ export function updateProject(req, res) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getProject(req, res) {
|
export function getProject(req, res) {
|
||||||
const projectId = req.params.project_id;
|
const { project_id: projectId, username } = req.params;
|
||||||
Project.findById(projectId)
|
User.findOne({ username }, (err, user) => { // eslint-disable-line
|
||||||
|
if (!user) {
|
||||||
|
return res.status(404).send({ message: 'Project with that username does not exist' });
|
||||||
|
}
|
||||||
|
Project.findOne({ user: user._id, $or: [{ _id: projectId }, { slug: projectId }] })
|
||||||
.populate('user', 'username')
|
.populate('user', 'username')
|
||||||
.exec((err, project) => { // eslint-disable-line
|
.exec((err, project) => { // eslint-disable-line
|
||||||
if (err) {
|
if (err) {
|
||||||
return res.status(404).send({ message: 'Project with that id does not exist' });
|
console.log(err);
|
||||||
} else if (!project) {
|
|
||||||
Project.findOne({ slug: projectId })
|
|
||||||
.populate('user', 'username')
|
|
||||||
.exec((innerErr, projectBySlug) => {
|
|
||||||
if (innerErr || !projectBySlug) {
|
|
||||||
return res.status(404).send({ message: 'Project with that id does not exist' });
|
return res.status(404).send({ message: 'Project with that id does not exist' });
|
||||||
}
|
}
|
||||||
return res.json(projectBySlug);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return res.json(project);
|
return res.json(project);
|
||||||
}
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,18 +146,10 @@ export function projectForUserExists(username, projectId, callback) {
|
||||||
callback(false);
|
callback(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Project.findOne({ _id: projectId, user: user._id }, (innerErr, project) => {
|
Project.findOne({ user: user._id, $or: [{ _id: projectId }, { slug: projectId }] }, (innerErr, project) => {
|
||||||
if (project) {
|
if (project) {
|
||||||
callback(true);
|
callback(true);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
Project.findOne({ slug: projectId, user: user._id }, (slugError, projectBySlug) => {
|
|
||||||
if (projectBySlug) {
|
|
||||||
callback(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
callback(false);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ router.post('/projects', isAuthenticated, ProjectController.createProject);
|
||||||
|
|
||||||
router.put('/projects/:project_id', isAuthenticated, ProjectController.updateProject);
|
router.put('/projects/:project_id', isAuthenticated, ProjectController.updateProject);
|
||||||
|
|
||||||
router.get('/projects/:project_id', ProjectController.getProject);
|
router.get('/:username/projects/:project_id', ProjectController.getProject);
|
||||||
|
|
||||||
router.delete('/projects/:project_id', isAuthenticated, ProjectController.deleteProject);
|
router.delete('/projects/:project_id', isAuthenticated, ProjectController.deleteProject);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue