@@ -14,13 +14,17 @@ import {
14
14
ACTIVE ,
15
15
createNode ,
16
16
createRelationships ,
17
+ defineSorters ,
17
18
filter ,
18
19
matchProps ,
19
20
merge ,
20
21
paginate ,
21
- sorting ,
22
+ sortWith ,
22
23
} from '~/core/database/query' ;
23
- import { fieldZoneFilters } from '../field-zone/field-zone.repository' ;
24
+ import {
25
+ fieldZoneFilters ,
26
+ fieldZoneSorters ,
27
+ } from '../field-zone/field-zone.repository' ;
24
28
import {
25
29
type CreateFieldRegion ,
26
30
FieldRegion ,
@@ -113,7 +117,7 @@ export class FieldRegionRepository extends DtoRepository(FieldRegion) {
113
117
. query ( )
114
118
. match ( node ( 'node' , 'FieldRegion' ) )
115
119
. apply ( fieldRegionFilters ( input . filter ) )
116
- . apply ( sorting ( FieldRegion , input ) )
120
+ . apply ( sortWith ( fieldRegionSorters , input ) )
117
121
. apply ( paginate ( input , this . hydrate ( ) ) )
118
122
. first ( ) ;
119
123
return result ! ; // result from paginate() will always have 1 row.
@@ -143,3 +147,16 @@ export const fieldRegionFilters = filter.define(() => FieldRegionFilters, {
143
147
] ) ,
144
148
) ,
145
149
} ) ;
150
+
151
+ export const fieldRegionSorters = defineSorters ( FieldRegion , {
152
+ // eslint-disable-next-line @typescript-eslint/naming-convention
153
+ 'fieldZone.*' : ( query , input ) =>
154
+ query
155
+ . with ( 'node as region' )
156
+ . match ( [
157
+ node ( 'region' ) ,
158
+ relation ( 'out' , '' , 'zone' , ACTIVE ) ,
159
+ node ( 'node' , 'FieldZone' ) ,
160
+ ] )
161
+ . apply ( sortWith ( fieldZoneSorters , input ) ) ,
162
+ } ) ;
0 commit comments