{"size": 1084, "ext": "js", "max_stars_repo_path": "server/api/fund.js", "max_stars_repo_name": "jormarcus/Ether-Fund", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "server/api/fund.js", "max_issues_repo_name": "jormarcus/Ether-Fund", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "server/api/fund.js", "max_forks_repo_name": "jormarcus/Ether-Fund", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.0888888889, "max_line_length": 56, "alphanum_fraction": 0.5913284133}
const router = require('express').Router()
const { Fund } = require('../db/models')
module.exports = router

//GET all funds
router.get('/', async(req, res, next) =>{
  try {
    const funds = await Fund.findAll()
    res.json(funds);
  } catch(error) {
    next(error)
  }
});

router.get('/:fundId', async (req, res, next) => {
  try {
    const fund = await Fund.findById(req.params.fundId);
    res.json(fund);
  } catch (error) { next (error) }
});

router.post('/', async (req, res, next) => {
  try {
    const newfund = await Fund.create(req.body);
    res.json(newfund);
  } catch (error) { next (error) }
});

router.put('/:fundId', async (req, res, next) => {
  try {
    const fund = await Fund.findById(req.params.fundId);
    if (!fund) {
      res.sendStatus(404);
    }
    const fundToUpdate = await fund.update(req.body);
    res.json(fundToUpdate);
  } catch (error) { next (error) }
});

router.delete('/:fundId', async (req, res, next) => {
  try {
    const id = req.params.fundId;
    await Fund.destroy( { where: {id} } )
  } catch (error) { next (error) }
});