Skip to content

Commit

Permalink
Merge pull request #149 from partio-scout/bugfix/filtering-dates-amon…
Browse files Browse the repository at this point in the history
…g-other-fields

Bugfix/filtering dates among other fields
  • Loading branch information
googol authored Jul 20, 2016
2 parents 819edb6 + 34130ce commit 76acdf1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/common/models/participant.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ export default function (Participant) {

if (where.and) {
dates = where.and.filter(filter => filter.dates);
dates = dates.dates;
where.and = where.and.filter(filter => !filter.dates);
if (dates && !_.isEmpty(dates)) {
dates = dates[0].dates;
where.and = where.and.filter(filter => !filter.dates);
}
} else {
dates = where.dates;
}
Expand Down
8 changes: 4 additions & 4 deletions test/date-search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Date search', () => {
'campGroup': 'Leirilippukunta',
'village': 'Kylä',
'subCamp': 'Alaleiri2',
'ageGroup': 'sudenpentu',
'ageGroup': 'seikkailija',
'memberNumber': 345,
},
{
Expand Down Expand Up @@ -104,7 +104,7 @@ describe('Date search', () => {
it('Query with other filter', () =>
queryParticipants({ 'ageGroup':'sudenpentu' }, accessToken)
.then(res => {
expectParticipants([ 'Tero', 'Teemu' ], res.body);
expectParticipants([ 'Teemu' ], res.body);
})
);

Expand All @@ -116,14 +116,14 @@ describe('Date search', () => {
);

it('Query with one date', () =>
queryParticipants({ 'dates': ['2016-07-23T00:00:00.000Z'] }, accessToken)
queryParticipants({ 'dates': ['2016-07-22T00:00:00.000Z'] }, accessToken)
.then(res => {
expectParticipants([ 'Tero', 'Teemu' ], res.body);
})
);

it('Query with one date and other filter', () =>
queryParticipants({ 'and': [ { 'dates': ['2016-07-23T00:00:00.000Z'] }, { 'subCamp': 'Alaleiri2' } ] }, accessToken)
queryParticipants({ 'and': [ { 'dates': ['2016-07-23T00:00:00.000Z'] }, { 'ageGroup': 'seikkailija' } ] }, accessToken)
.then(res => {
expectParticipants([ 'Tero' ], res.body);
})
Expand Down

0 comments on commit 76acdf1

Please sign in to comment.