full
This commit is contained in:
@@ -1,15 +1,23 @@
|
||||
const { ProvinceModel } = require('../../models/StateCity')
|
||||
|
||||
const getProvinces = async (req, res, next) => {
|
||||
try {
|
||||
const provinces = await ProvinceModel.find({})
|
||||
res.status(200).json({
|
||||
provinces
|
||||
})
|
||||
} catch (err) {
|
||||
res.status(500).send('Internal Server Error')
|
||||
}
|
||||
}
|
||||
module.exports = {
|
||||
getProvinces
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user