Skip to content

Commit

Permalink
fix(stats): only use 1 application per user (#794)
Browse files Browse the repository at this point in the history
Co-authored-by: Rik Smale <git@riksmale.info>
  • Loading branch information
WikiRik and Rik Smale committed Sep 24, 2024
1 parent f1ebe80 commit b21cd98
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/applications.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,23 @@ exports.getStats = async (req, res) => {
.countByField(applications, 'event_id')
.map(({ type, value }) => ({ type: events.find((event) => event.id === type).name, value }));

// TODO: only use one application per user from here
let uniqueApplicationUsersQuery = {
...applicationQuery,
attributes: ['user_id', 'body_name', 'nationality', 'event_id'],
group: ['user_id', 'body_name', 'nationality', 'event_id'],
};

if (req.query.season) {
uniqueApplicationUsersQuery = { ...uniqueApplicationUsersQuery, group: ['user_id', 'body_name', 'nationality', 'event_id', 'event.id'] };
}

const uniqueApplicationUsers = await Application.findAll(uniqueApplicationUsersQuery);

statsObject.by_body = helpers
.countByField(applications, 'body_name');
.countByField(uniqueApplicationUsers, 'body_name');

statsObject.by_nationality = helpers
.countByField(applications, 'nationality');
.countByField(uniqueApplicationUsers, 'nationality');

return res.json({
success: true,
Expand Down
2 changes: 2 additions & 0 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ exports.getEventPermissions = async ({ permissions, event, user }) => {
status: 'accepted'
} });

// TODO: when is this permission checked? It should be done everytime an application is created or updated
// TODO: we've seen duplicate applications and people confirmed for two separate events
permissions.apply = event.application_status === 'open'
&& event.published === 'covid'
&& permissions.apply_general
Expand Down

0 comments on commit b21cd98

Please sign in to comment.