delete files works, server side
This commit is contained in:
parent
34fe78d734
commit
3dfed2a11e
4 changed files with 33 additions and 5 deletions
|
@ -155,9 +155,25 @@ export function updateFileName(id, name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deleteFile(id, parentId) {
|
export function deleteFile(id, parentId) {
|
||||||
return {
|
return (dispatch, getState) => {
|
||||||
type: ActionTypes.DELETE_FILE,
|
const state = getState();
|
||||||
id,
|
const deleteConfig = {
|
||||||
parentId
|
params: {
|
||||||
|
parentId
|
||||||
|
}
|
||||||
|
};
|
||||||
|
axios.delete(`${ROOT_URL}/projects/${state.project.id}/files/${id}`, deleteConfig, { withCredentials: true })
|
||||||
|
.then(() => {
|
||||||
|
dispatch({
|
||||||
|
type: ActionTypes.DELETE_FILE,
|
||||||
|
id,
|
||||||
|
parentId
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(response => dispatch({
|
||||||
|
type: ActionTypes.ERROR,
|
||||||
|
error: response.data
|
||||||
|
})
|
||||||
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,4 +45,15 @@ export function createFile(req, res) {
|
||||||
// return res.json(updatedProject.files[updatedProject.files.length - 1]);
|
// return res.json(updatedProject.files[updatedProject.files.length - 1]);
|
||||||
// });
|
// });
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function deleteFile(req, res) {
|
||||||
|
Project.findById(req.params.project_id, (err, project) => {
|
||||||
|
project.files.id(req.params.file_id).remove();
|
||||||
|
const childrenArray = project.files.id(req.query.parentId).children;
|
||||||
|
project.files.id(req.query.parentId).children = childrenArray.filter(id => id !== req.params.file_id);
|
||||||
|
project.save(innerErr => {
|
||||||
|
res.json(project.files);
|
||||||
|
})
|
||||||
|
});
|
||||||
}
|
}
|
|
@ -35,7 +35,7 @@ const defaultCSS =
|
||||||
|
|
||||||
const fileSchema = new Schema({
|
const fileSchema = new Schema({
|
||||||
name: { type: String, default: 'sketch.js' },
|
name: { type: String, default: 'sketch.js' },
|
||||||
content: { type: String },
|
content: { type: String, default: '' },
|
||||||
url: { type: String },
|
url: { type: String },
|
||||||
children: { type: [ String ], default: [] },
|
children: { type: [ String ], default: [] },
|
||||||
fileType: { type: String },
|
fileType: { type: String },
|
||||||
|
|
|
@ -4,5 +4,6 @@ import * as FileController from '../controllers/file.controller';
|
||||||
const router = new Router();
|
const router = new Router();
|
||||||
|
|
||||||
router.route('/projects/:project_id/files').post(FileController.createFile);
|
router.route('/projects/:project_id/files').post(FileController.createFile);
|
||||||
|
router.route('/projects/:project_id/files/:file_id').delete(FileController.deleteFile);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
Loading…
Reference in a new issue