Skip to content

Commit f139701

Browse files
committed
Add Project.primaryPartnership sorting & filtering
1 parent 5eda0ac commit f139701

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

src/components/project/dto/list-projects.dto.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
Sensitivity,
1212
SortablePaginationInput,
1313
} from '~/common';
14+
import { PartnershipFilters } from '../../partnership/dto';
1415
import { ProjectStatus } from './project-status.enum';
1516
import { ProjectStep } from './project-step.enum';
1617
import { ProjectType } from './project-type.enum';
@@ -99,6 +100,9 @@ export abstract class ProjectFilters {
99100
readonly partnerId?: ID;
100101

101102
readonly userId?: ID;
103+
104+
@FilterField(() => PartnershipFilters)
105+
readonly primaryPartnership?: PartnershipFilters & {};
102106
}
103107

104108
@InputType()

src/components/project/project-filters.query.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { greaterThan, inArray, node, relation } from 'cypher-query-builder';
2-
import { ACTIVE, filter, matchProjectSens, path } from '~/core/database/query';
2+
import {
3+
ACTIVE,
4+
filter,
5+
matchProjectSens,
6+
path,
7+
variable,
8+
} from '~/core/database/query';
9+
import { partnershipFilters } from '../partnership/partnership.repository';
310
import { ProjectFilters } from './dto';
411
import { ProjectNameIndex } from './project.repository';
512

@@ -85,4 +92,15 @@ export const projectFilters = filter.define(() => ProjectFilters, {
8592
.with('*')
8693
.where({ sensitivity: inArray(value) })
8794
: query,
95+
primaryPartnership: filter.sub(() => partnershipFilters)((sub) =>
96+
sub
97+
.with('node as project')
98+
.match([
99+
node('project'),
100+
relation('out', '', 'partnership', ACTIVE),
101+
node('node', 'Partnership'),
102+
relation('out', '', 'primary', ACTIVE),
103+
node('', 'Property', { value: variable('true') }),
104+
]),
105+
),
88106
});

src/components/project/project.repository.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
} from '~/core/database/query';
3232
import { Privileges } from '../authorization';
3333
import { locationSorters } from '../location/location.repository';
34+
import { partnershipSorters } from '../partnership/partnership.repository';
3435
import {
3536
CreateProject,
3637
IProject,
@@ -377,4 +378,23 @@ export const projectSorters = defineSorters(IProject, {
377378
.where(not(path(getPath(true))))
378379
.return<SortCol>('null as sortValue');
379380
},
381+
// eslint-disable-next-line @typescript-eslint/naming-convention
382+
'primaryPartnership.*': (query, input) => {
383+
const getPath = (anon = false) => [
384+
node('project'),
385+
relation('out', '', 'partnership', ACTIVE),
386+
node(anon ? '' : 'node', 'Partnership'),
387+
relation('out', '', 'primary', ACTIVE),
388+
node('', 'Property', { value: variable('true') }),
389+
];
390+
return query
391+
.with('node as project')
392+
.match(getPath())
393+
.apply(sortWith(partnershipSorters, input))
394+
.union()
395+
.with('node')
396+
.with('node as project')
397+
.where(not(path(getPath(true))))
398+
.return<SortCol>('null as sortValue');
399+
},
380400
});

0 commit comments

Comments
 (0)