Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
765 B
4
Indexable
Never
exports.getCompetitions = async (req, res, next) => {
    let sport = getSportCroatian(req.query.sport);
    let sportObj = await Sport.findOne({ name : sport});
    let startDate = getDateObject(req.query.dateStart)
    let endDate = getDateObject(req.query.dateEnd)
    console.log(sport, startDate, endDate)
    query = {startDate : { $gt : startDate, $lt : endDate}, sport : sportObj._id, sex : req.query.sex,organisation : req.query.organisation }
    if (req.query.teamId) {
        query["teams"] = req.query.teamId
    }

    let competitions = await Competition.find(query, {name : 1, startDate : 1, _id : 1})
    res.status(201).json({ 
        message: 'competitions fetched successfully', 
        competitions : competitions
    });

}