Skip to content

Commit

Permalink
get strain by id
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshimii committed May 31, 2020
1 parent b27e4b2 commit cd22659
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions admin/strains/strainsRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@ router.get('/all_strains', restricted, (req, res) =>
})
});

router.get('/:strain_id', restricted, (req, res) =>
{
const id = req.params.strain_id

Strains.getById(id)
.then(strain=>
{ if ( strain.length === 0)
{
res.status(200).json({successMessage: "No strains with that ID found"})
} else
{
res.status(200).json({successMessage: `Strain of id: ${id} retrieved`, strainRetrieved: strain})
}
})
.catch(err =>
{
res.status(500).json({errorMessage: 'Could not retrieve strain', systemError: err})
})
});

router.post('/add', restricted, (req, res) =>
{ // TODO: Error handling for existing strains
Strains.addStrain(req.body)
Expand All @@ -29,6 +49,8 @@ router.post('/add', restricted, (req, res) =>
})
});

//----- Admin Access Only -----

router.delete('/del', restricted, (req, res) =>
{
id = req.body.id
Expand All @@ -41,8 +63,6 @@ router.delete('/del', restricted, (req, res) =>
})
});

//----- Admin Access Only -----

router.put('/:strain_id', restricted, (req, res) =>
{ // TODO: Make Admin role function only and separate admin from user routes
const strain_id = req.params.strain_id
Expand Down

0 comments on commit cd22659

Please sign in to comment.