moves find to findOne, cleans up requestHandlers
This commit is contained in:
@@ -20,8 +20,9 @@ const withEditData = PassedComponent => {
|
||||
|
||||
fetchData = () => {
|
||||
const slug = this.props.match.params.slug;
|
||||
|
||||
const params = {
|
||||
lang: this.props.locale
|
||||
locale: this.props.locale
|
||||
};
|
||||
|
||||
if (slug) {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import httpStatus from 'http-status';
|
||||
|
||||
const destroy = (req, res) => {
|
||||
req.model.findOneAndDelete({ _id: req.params.id }, (err, doc) => {
|
||||
req.model.setDefaultLanguage(req.locale);
|
||||
req.model.findOneAndDelete({ slug: req.params.slug }, (err, doc) => {
|
||||
if (err)
|
||||
return res.status(httpStatus.INTERNAL_SERVER_ERROR).json({ error: err });
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import httpStatus from 'http-status';
|
||||
|
||||
const find = (req, res) => {
|
||||
req.model.findById(req.params.id, (err, doc) => {
|
||||
const findOne = (req, res) => {
|
||||
req.model.setDefaultLanguage(req.locale);
|
||||
|
||||
req.model.findOne({ slug: { en: req.params.slug } }, (err, doc) => {
|
||||
if (err)
|
||||
return res.status(httpStatus.INTERNAL_SERVER_ERROR).json({ error: err });
|
||||
|
||||
@@ -17,4 +19,4 @@ const find = (req, res) => {
|
||||
});
|
||||
};
|
||||
|
||||
export default find;
|
||||
export default findOne;
|
||||
@@ -1,13 +1,13 @@
|
||||
import create from './create';
|
||||
import destroy from './destroy';
|
||||
import find from './find';
|
||||
import findOne from './findOne';
|
||||
import query from './query';
|
||||
import update from './update';
|
||||
|
||||
export {
|
||||
create,
|
||||
destroy,
|
||||
find,
|
||||
findOne,
|
||||
query,
|
||||
update
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import httpStatus from 'http-status';
|
||||
|
||||
const update = (req, res) => {
|
||||
req.model.setDefaultLanguage(req.locale);
|
||||
req.model.findOne({ _id: req.params.id }, '', {}, (err, doc) => {
|
||||
req.model.findOne({ slug: req.params.slug }, '', {}, (err, doc) => {
|
||||
if (!doc)
|
||||
return res.status(httpStatus.NOT_FOUND).send('Not Found');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user