1
1
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' ;
3
3
import { DateTime } from 'luxon' ;
4
4
import {
5
5
ID ,
@@ -23,6 +23,7 @@ import {
23
23
matchPropsAndProjectSensAndScopedRoles ,
24
24
merge ,
25
25
paginate ,
26
+ path ,
26
27
requestingUser ,
27
28
SortCol ,
28
29
sortWith ,
@@ -351,18 +352,20 @@ export const projectSorters = defineSorters(IProject, {
351
352
] )
352
353
. return < SortCol > ( 'count(engagement) as sortValue' ) ,
353
354
// 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 ( ) )
362
364
. apply ( sortWith ( locationSorters , input ) )
363
365
. union ( )
364
366
. 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
+ } ,
368
371
} ) ;
0 commit comments