moves find to findOne, cleans up requestHandlers

This commit is contained in:
James
2019-02-16 11:27:05 -05:00
parent 0c11f5b4a2
commit 682efd0318
9 changed files with 24 additions and 26 deletions

View File

@@ -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) {

View File

@@ -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 });

View File

@@ -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;

View File

@@ -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
}

View File

@@ -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');