import Tipp from 'src/models/TippModel';

/**
 * Save a new tipp
 * @param {Object} req Request object
 * @param {Object} res Response object
 * @param {Function} next Callback for next middleware in route
 */
export const postTipp = (req, res, next) => {
  const tipp = new Tipp(req.body);

  return tipp.save()
    .then(res.json)
    .catch(next);
};

/**
 * Delete a tipp, needs authentication
 * @param {Object} req Request object
 * @param {Object} res Response object
 * @param {Function} next Callback for next middleware in route
 */
export const deleteTipp = (req, res, next) => {
  return Tipp.remove({
    _id: req.params.id,
  })
    .then(res.json)
    .catch(next);
};

/**
 * Update a tipp
 * @param {Objec} req
 * @param {Object} res
 * @param {Function} next Callback for next middleware in route
 */
export const putTipp = (req, res, next) => {
  return Tipp.findByIdAndUpdate(req.params.id, {
    $set: req.body,
  })
    .then(res.json)
    .catch(next);
};

/**
 * Get a list of all tipps
 * @param {Object} req
 * @param {Object} res
 * @param {Function} next Callback for next middleware in route
 */
export const listTipps = (req, res, next) => {
  return Tipp.find({})
    .then(res.json)
    .catch(next);
};

/**
 * Get one tipp
 * @param {Object} req
 * @param {Object} res
 * @param {Function} next Callback for next middleware in route
 */
export const getTipp = (req, res, next) => {
  return Tipp.findOne({
    _id: req.params.id,
  })
    .then(res.json)
    .catch(next);
};

@@ -250,25 +250,8 @@
 ) =%3E
- %7B%0A  const tipp =
  new
@@ -269,32 +269,16 @@
 ody)
-;%0A%0A  return tipp
 .save()%0A
     
@@ -273,26 +273,24 @@
 .save()%0A
-  
   .then(
 res.json
@@ -277,32 +277,40 @@
 e()%0A  .then(
+data =%3E 
 res.json
 )%0A    .catch
@@ -297,37 +297,50 @@
 res.json
+(data)
 )%0A  
- 
- 
 .catch(
-next);%0A%7D
+err =%3E next(err))
 ;%0A%0A/**%0A 
@@ -563,35 +563,24 @@
 es, next) =%3E
- %7B%0A  return
  Tipp.remove
@@ -580,26 +580,24 @@
 .remove(%7B%0A  
- 
- 
 _id: req.par
@@ -600,39 +600,35 @@
 .params.id,%0A
-  
 %7D)%0A
-  
   .then(
 res.json)%0A  
@@ -619,37 +619,58 @@
 hen(
-res.json)%0A    .catch(next);%0A%7D
+data =%3E res.json(data))%0A  .catch(err =%3E next(err))
 ;%0A%0A/
@@ -840,35 +840,24 @@
 es, next) =%3E
- %7B%0A  return
  Tipp.findBy
@@ -885,18 +885,16 @@
 s.id, %7B%0A
-  
   $set: 
@@ -903,31 +903,45 @@
 q.body,%0A
-  
+%7D, %7B%0A  new: true,%0A
 %7D)%0A
-  
   .then(
 res.json
@@ -936,37 +936,58 @@
 hen(
-res.json)%0A    .catch(next);%0A%7D
+data =%3E res.json(data))%0A  .catch(err =%3E next(err))
 ;%0A%0A/
@@ -1170,35 +1170,24 @@
 es, next) =%3E
- %7B%0A  return
  Tipp.find(%7B
@@ -1189,26 +1189,24 @@
 ind(%7B%7D)%0A
-  
   .then(
 res.json
@@ -1193,32 +1193,40 @@
 %7B%7D)%0A  .then(
+data =%3E 
 res.json
 )%0A    .catch
@@ -1213,37 +1213,50 @@
 res.json
+(data)
 )%0A  
- 
- 
 .catch(
-next);%0A%7D
+err =%3E next(err))
 ;%0A%0A/**%0A 
@@ -1430,19 +1430,8 @@
 ) =%3E
- %7B%0A  return
  Tip
@@ -1444,18 +1444,16 @@
 One(%7B%0A  
- 
- 
 _id: req
@@ -1468,23 +1468,19 @@
 id,%0A
-  
 %7D)%0A
-  
   .then(
 res.
@@ -1479,35 +1479,56 @@
 hen(
-res.json)%0A    .catch(next);%0A%7D
+data =%3E res.json(data))%0A  .catch(err =%3E next(err))
 ;%0A

Fix tipps