Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hawk.api",
"version": "1.4.10",
"version": "1.4.11",
"main": "index.ts",
"license": "BUSL-1.1",
"scripts": {
Expand Down
42 changes: 38 additions & 4 deletions src/models/eventsFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ class EventsFactory extends Factory {
? Object.fromEntries(
Object
.entries(filters)
.filter(([mark]) => markFilters.includes(mark))
.filter(([ mark ]) => markFilters.includes(mark))
.map(([mark, exists]) => [`event.marks.${mark}`, { $exists: exists } ])
)
: {};
Expand All @@ -364,9 +364,43 @@ class EventsFactory extends Factory {
}
: {};

const assigneeFilter = assignee
? { 'event.assignee': String(assignee) }
: {};
/**
* Sentinel values from garage assignee filter (not user ids)
*/
const FILTER_UNASSIGNED = '__filter_unassigned__';
const FILTER_ANY_ASSIGNEE = '__filter_any_assignee__';

const assigneeFilter = (() => {
if (!assignee) {
return {};
}
if (assignee === FILTER_UNASSIGNED) {
/**
* Use $and so this does not collide with searchFilter’s top-level $or in $match spread
*/
return {
$and: [
{
$or: [
{ 'event.assignee': { $exists: false } },
{ 'event.assignee': null },
{ 'event.assignee': '' },
],
},
],
};
}
if (assignee === FILTER_ANY_ASSIGNEE) {
return {
'event.assignee': {
$exists: true,
$nin: [null, ''],
},
};
}

return { 'event.assignee': String(assignee) };
})();

pipeline.push(
/**
Expand Down
2 changes: 1 addition & 1 deletion src/typeDefs/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ type Project {
release: String

"""
User id to filter events by assignee
Filter by assignee: workspace user id, or sentinels __filter_unassigned__ (no assignee) / __filter_any_assignee__ (has assignee)
"""
assignee: ID
): DailyEventsPortion
Expand Down
32 changes: 32 additions & 0 deletions test/resolvers/project-daily-events-portion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,38 @@ describe('Project resolver dailyEventsPortion', () => {
);
});

it('should pass assignee sentinel for unassigned filter to factory', async () => {
const findDailyEventsPortion = jest.fn().mockResolvedValue({
nextCursor: null,
dailyEvents: [],
});
(getEventsFactory as unknown as jest.Mock).mockReturnValue({
findDailyEventsPortion,
});

const project = { _id: 'project-1' };
const args = {
limit: 50,
nextCursor: null,
sort: 'BY_DATE',
filters: {},
search: '',
assignee: '__filter_unassigned__',
};

await projectResolver.Project.dailyEventsPortion(project, args, {});

expect(findDailyEventsPortion).toHaveBeenCalledWith(
50,
null,
'BY_DATE',
{},
'',
undefined,
'__filter_unassigned__'
);
});

it('should keep old call shape when assignee is not provided', async () => {
const findDailyEventsPortion = jest.fn().mockResolvedValue({
nextCursor: null,
Expand Down