Skip to content

Commit

Permalink
fix(applications): fetch all bodies once for JC export (#1195)
Browse files Browse the repository at this point in the history
Co-authored-by: WikiRik <WikiRik@users.noreply.github.com>
  • Loading branch information
WikiRik and WikiRik committed Apr 10, 2024
1 parent 293a2a9 commit e718bfa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/applications.js
Original file line number Diff line number Diff line change
Expand Up @@ -877,10 +877,12 @@ exports.exportDelegatesJc = async (req, res) => {
mails = await core.getMails(req, userIds);
}

const bodies = await core.getBodies(req);

// Returns a CSV string
const exportString = await Promise.all(applications.map(async (application) => {
const user = mails.find((m) => application.user_id === m.id);
const body = await core.getBody(req, application.body_id);
const body = bodies.find((b) => application.body_id === b.id);
const regex = /[^a-zA-z\-\ ]/; // eslint-disable-line
application.first_name = application.first_name.replace(regex, '?');
application.last_name = application.last_name.replace(regex, '?');
Expand Down
2 changes: 1 addition & 1 deletion test/api/export-delegates-jc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('Export Delegates JC', () => {
});

test('should return the application if it is not cancelled, accepted and a delegate', async () => {
await generator.createApplication({ user_id: regularUser.id, status: 'accepted', participant_type: 'delegate' }, event);
await generator.createApplication({ user_id: regularUser.id, status: 'accepted', participant_type: 'delegate', body_id: 34 }, event);
const res = await request({
uri: '/events/' + event.id + '/applications/export/delegates_jc',
method: 'GET',
Expand Down

0 comments on commit e718bfa

Please sign in to comment.