diff --git a/src/activity/services/activity/activity.service.spec.ts b/src/activity/services/activity/activity.service.spec.ts index 093930b..03e1038 100644 --- a/src/activity/services/activity/activity.service.spec.ts +++ b/src/activity/services/activity/activity.service.spec.ts @@ -46,7 +46,7 @@ describe('ActivityService', () => { }); describe('getAllActivities', () => { it('should return an array of events', async () => { - const query = { page: '1', tag: 'tech' }; + const query = { page: '1', tags: 'tech' }; jest.spyOn(model, 'find').mockImplementation( () => ({ @@ -62,11 +62,13 @@ describe('ActivityService', () => { ); const result = await activityService.getAllActivities(query); expect(model.find).toHaveBeenCalledWith({ - eventTags: { + $and: [{ + eventTags: { // using regex to look if any entries contain the text - $regex: 'tech', - $options: 'i', // case insensitive - }, + $regex: 'tech', + $options: 'i', // case insensitive + }, + }], isArchived: false, isHidden: false }); diff --git a/src/activity/services/activity/activity.service.ts b/src/activity/services/activity/activity.service.ts index 9915ebf..59a204c 100644 --- a/src/activity/services/activity/activity.service.ts +++ b/src/activity/services/activity/activity.service.ts @@ -27,23 +27,22 @@ export class ActivityService { // skips the number of results according to page number and number of results per page const skip = resPerPage * (currentPage - 1); - // TODO: add ability to query by host/club - // search by event tags - const tag = query.tag - ? { - eventTags: { - // using regex to look if any entries contain the text - $regex: query.tag, - $options: 'i', // case insensitive - }, + const tagsArray = query.tags && typeof query.tags === 'string' ? query.tags.split(',') : []; + const tags = tagsArray.length > 0 + ? { + $and: tagsArray.map(tag => ({ + eventTags: { + $regex: tag, + $options: 'i', // case insensitive + }, + })), } - : {}; + : {}; const filter: any = { - ...tag, + ...tags, isArchived: query.isArchived || false, isHidden: query.isHidden || false, }; - // Auto archive the old events const now = new Date(); await this.activityModel.updateMany(