Skip to content

Commit

Permalink
fix(application): add season query parameter to stats (#790)
Browse files Browse the repository at this point in the history
Co-authored-by: Rik Smale <[email protected]>
  • Loading branch information
WikiRik and Rik Smale authored Sep 20, 2024
1 parent ba34b0a commit f3cc396
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/applications.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,16 @@ exports.getStats = async (req, res) => {
by_nationality: []
};

const applications = await Application.findAll({ attributes: ['event_id', 'body_name', 'nationality'] });
const events = await Event.findAll({ attributes: ['id', 'name'] });
let applicationQuery = { attributes: ['event_id', 'body_name', 'nationality'] };
let eventQuery = { attributes: ['id', 'name'] };

if (req.query.season) {
applicationQuery = { ...applicationQuery, ...{ include: [{ model: Event, where: { season: Number(req.query.season) } }] } };
eventQuery = { ...eventQuery, ...{ where: { season: Number(req.query.season) } } };
}

const applications = await Application.findAll(applicationQuery);
const events = await Event.findAll(eventQuery);

statsObject.by_event = helpers
.countByField(applications, 'event_id')
Expand Down

0 comments on commit f3cc396

Please sign in to comment.