implemented region search by name

This commit is contained in:
Mikayla Dobson
2022-09-27 16:51:16 -05:00
parent d020fa8af4
commit efa74d1c16
11 changed files with 38 additions and 220 deletions

View File

@@ -6,11 +6,22 @@ module.exports = (app) => {
app.use('/api/regions', router);
router.get('/', async (req, res, next) => {
try {
const response = await RegionsInstance.getAll();
res.status(200).send(response);
} catch(e) {
next(e);
const { name } = req.query;
if (name) {
try {
const response = await RegionsInstance.getOneByName(name);
res.status(200).send(response);
} catch(e) {
next(e);
}
} else {
try {
const response = await RegionsInstance.getAll();
res.status(200).send(response);
} catch(e) {
next(e);
}
}
})