Skip to content

Commit 6c236ac

Browse files
committed
Fix Project.primaryLocation null sorting
1 parent e95e09f commit 6c236ac

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/components/project/project.repository.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Injectable } from '@nestjs/common';
2-
import { inArray, node, Query, relation } from 'cypher-query-builder';
2+
import { inArray, node, not, Query, relation } from 'cypher-query-builder';
33
import { DateTime } from 'luxon';
44
import {
55
ID,
@@ -23,6 +23,7 @@ import {
2323
matchPropsAndProjectSensAndScopedRoles,
2424
merge,
2525
paginate,
26+
path,
2627
requestingUser,
2728
SortCol,
2829
sortWith,
@@ -351,18 +352,20 @@ export const projectSorters = defineSorters(IProject, {
351352
])
352353
.return<SortCol>('count(engagement) as sortValue'),
353354
// eslint-disable-next-line @typescript-eslint/naming-convention
354-
'primaryLocation.*': (query, input) =>
355-
query
356-
.with('node as proj')
357-
.match([
358-
node('proj'),
359-
relation('out', '', 'primaryLocation', ACTIVE),
360-
node('node'),
361-
])
355+
'primaryLocation.*': (query, input) => {
356+
const getPath = (anon = false) => [
357+
node('project'),
358+
relation('out', '', 'primaryLocation', ACTIVE),
359+
node(anon ? '' : 'node'),
360+
];
361+
return query
362+
.with('node as project')
363+
.match(getPath())
362364
.apply(sortWith(locationSorters, input))
363365
.union()
364366
.with('node')
365-
.with('node as proj')
366-
.raw('where not exists((node)-[:primaryLocation { active: true }]->())')
367-
.return<SortCol>('null as sortValue'),
367+
.with('node as project')
368+
.where(not(path(getPath(true))))
369+
.return<SortCol>('null as sortValue');
370+
},
368371
});

0 commit comments

Comments
 (0)