diff --git a/src/client/actions/ParticipantActions.js b/src/client/actions/ParticipantActions.js index 36970e1b..2935ce15 100644 --- a/src/client/actions/ParticipantActions.js +++ b/src/client/actions/ParticipantActions.js @@ -42,7 +42,7 @@ export function getParticipantActions(alt, participantResource) { return dispatch => { dispatch(); - participantResource.findAll(`filter=${JSON.stringify(filters)}`) + participantResource.findAll(`filter=${encodeURIComponent(JSON.stringify(filters))}`) .then(participantList => this.participantListUpdated(participantList), err => this.participantListUpdateFailed(err)); }; @@ -59,7 +59,7 @@ export function getParticipantActions(alt, participantResource) { loadParticipantCount(filter) { return dispatch => { dispatch(); - participantResource.raw('get', 'count', { filters: `where=${JSON.stringify(filter)}` }) + participantResource.raw('get', 'count', { filters: `where=${encodeURIComponent(JSON.stringify(filter))}` }) .then(response => this.participantCountUpdated(response.count), err => this.participantCountUpdateFailed(err)); }; diff --git a/src/common/models/participant.js b/src/common/models/participant.js index 3bfc2b87..821e5231 100644 --- a/src/common/models/participant.js +++ b/src/common/models/participant.js @@ -27,8 +27,8 @@ export default function (Participant) { function constructTextSearchArray(string) { const stripRegex = function(s) { - // Remove all charactes except alphabets (with umlauts and accents), numbers and dash - return s.replace(/[^A-zÀ-úÀ-ÿ0-9-]/ig, ''); + // Remove all charactes except alphabets (with umlauts and accents), numbers, dash and hashtag + return s.replace(/[^A-zÀ-úÀ-ÿ0-9-#]/ig, ''); }; function nameQuery(string, string2) { @@ -46,6 +46,8 @@ export default function (Participant) { or.push({ staffPosition: { regexp: `/${stripRegex(string)}/i` } }); or.push({ staffPositionInGenerator: { regexp: `/${stripRegex(string)}/i` } }); + or.push({ campOfficeNotes: { regexp: `/${stripRegex(string)}/i` } }); + or.push({ editableInfo: { regexp: `/${stripRegex(string)}/i` } }); const splitted = string.split(' ', 2); diff --git a/test/text-search.test.js b/test/text-search.test.js index c6264849..fd6a6140 100644 --- a/test/text-search.test.js +++ b/test/text-search.test.js @@ -27,6 +27,7 @@ describe('Text search', () => { 'memberNumber': 123, 'staffPosition': null, 'staffPositionInGenerator': 'Tiskari', + 'editableInfo': 'Muokattava teksti', }, { 'participantId': 2, @@ -42,6 +43,7 @@ describe('Text search', () => { 'memberNumber': 345, 'staffPosition': 'Jumppaohjaaja', 'staffPositionInGenerator': null, + 'campOfficeNotes': 'Leiritoimiston jutut', }, { 'participantId': 3, @@ -56,7 +58,7 @@ describe('Text search', () => { 'ageGroup': 'seikkailija', 'memberNumber': 859, 'staffPosition': 'Kaivaja', - 'staffPositionInGenerator': 'Kaivuumies', + 'staffPositionInGenerator': '#Tiskari', }, ]; @@ -87,7 +89,7 @@ describe('Text search', () => { function queryParticipants(filter, accessToken) { return request(app) - .get(`/api/participants/?access_token=${accessToken}&filter={"where":${JSON.stringify(filter)},"skip":0,"limit":20}`) + .get(`/api/participants/?access_token=${accessToken}&filter={"where":${encodeURIComponent(JSON.stringify(filter))},"skip":0,"limit":20}`) .expect(200); } @@ -171,12 +173,33 @@ describe('Text search', () => { it('Query with staff position in generator', () => queryParticipants({ 'textSearch':'Tiskari' }, accessToken) .then(res => { - expectParticipants([ 'Teemu' ], res.body); + expectParticipants([ 'Teemu', 'Jussi' ], res.body); }) ); it('Query with partial staff position', () => queryParticipants({ 'textSearch':'tisk' }, accessToken) + .then(res => { + expectParticipants([ 'Teemu', 'Jussi' ], res.body); + }) + ); + + it('Query with hashtag', () => + queryParticipants({ 'textSearch':'#Tiskari' }, accessToken) + .then(res => { + expectParticipants([ 'Jussi' ], res.body); + }) + ); + + it('Query with camp office notes', () => + queryParticipants({ 'textSearch':'Leiritoimisto' }, accessToken) + .then(res => { + expectParticipants([ 'Tero' ], res.body); + }) + ); + + it('Query with editable info', () => + queryParticipants({ 'textSearch':'Muokattava' }, accessToken) .then(res => { expectParticipants([ 'Teemu' ], res.body); })