Skip to content

Commit

Permalink
Add endpoint to retrieve all cities with subdivisions
Browse files Browse the repository at this point in the history
  • Loading branch information
guillecro committed Dec 20, 2024
1 parent 13e8153 commit ad919f2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
21 changes: 21 additions & 0 deletions controllers/utilsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,27 @@ exports.getSubdivisions = async (req, res) => {
}
}

exports.getCities = async (req, res) => {
try {
// get all cities
const cities = await models.City.findAll({
attributes: ['id', 'name'],
include: [
{
model: models.Subdivision,
as: 'subdivisions',
attributes: ['id', 'name'],
}
]
});

return res.status(200).json(cities);
} catch (error) {
console.error(error);
res.status(500).json({ message: msg.error.default });
}
}

exports.getDimensions = async (req, res) => {
try {
// get all dimensions
Expand Down
4 changes: 4 additions & 0 deletions routes/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ router.get('/configs',
UtilsController.getConfigs
);

router.get('/cities',
UtilsController.getCities
)


// -----------------------------------------------

Expand Down

0 comments on commit ad919f2

Please sign in to comment.