Files
modstagram-back/controllers/application/provincesController.js
payacom 3f416a7a60 full
2026-08-31 20:45:41 +03:30

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
}