24 lines
752 B
JavaScript
24 lines
752 B
JavaScript
const { ProvinceModel } = require('../../models/StateCity')
|
|
|
|
// Iran's id in data/geo/countries.json — callers that omit country_id keep getting
|
|
// exactly the old Iran-only province list (unchanged behavior for existing screens).
|
|
const DEFAULT_COUNTRY_ID = 103
|
|
|
|
const getProvinces = async (req, res, next) => {
|
|
try {
|
|
const { country_id: countryIdParam } = req.query
|
|
const countryId = countryIdParam !== undefined ? Number(countryIdParam) : DEFAULT_COUNTRY_ID
|
|
const provinces = await ProvinceModel.find(
|
|
Number.isFinite(countryId) ? { country_id: countryId } : {}
|
|
)
|
|
res.status(200).json({
|
|
provinces
|
|
})
|
|
} catch (err) {
|
|
res.status(500).send('Internal Server Error')
|
|
}
|
|
}
|
|
module.exports = {
|
|
getProvinces
|
|
}
|