import {regions} from "../../utils/constans/cities";

module.exports.getSignUpLocationController = (req, res, next) => {

    const searchIntersection = [];

    if(req.query.city.length > 0) {

        regions.map(region => {
            region.options.map(city => {
                city = city.value.toLowerCase();
                const requestCity = req.query.city.toLowerCase();

                if( city.indexOf(requestCity) != -1 ) {

                    city = city[0].toUpperCase() + city.slice(1);
                    searchIntersection.push(city + ", " + region.label);
                }
            });
        });
    }

    if(searchIntersection.length == 0 && req.query.city.length > 0) {
        res.send(null);
    }else {
        res.send(searchIntersection);

    }
};