File tree Expand file tree Collapse file tree 2 files changed +8
-3
lines changed
Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -202,7 +202,7 @@ const resolvers = {
202202
203203 children : async ( parent : AreaType , _ , { dataSources : { areas } } : Context ) => {
204204 if ( parent . children . length > 0 ) {
205- return await areas . findManyByIds ( parent . children )
205+ return await areas . findChildren ( parent . children )
206206 }
207207 return [ ]
208208 } ,
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { MongoDataSource } from 'apollo-datasource-mongodb'
22import { Filter } from 'mongodb'
33import muuid from 'uuid-mongodb'
44import bboxPolygon from '@turf/bbox-polygon'
5+ import { Types as mongooseTypes } from 'mongoose'
56
67import { getAreaModel , getMediaModel , getMediaObjectModel } from '../db/index.js'
78import { AreaType } from '../db/AreaTypes'
@@ -111,8 +112,7 @@ export default class AreaDataSource extends MongoDataSource<AreaType> {
111112 } ,
112113 {
113114 $set : {
114- climbs : { $sortArray : { input : '$climbs' , sortBy : { 'metadata.left_right_index' : 1 } } } ,
115- children : { $sortArray : { input : '$children' , sortBy : { 'metadata.leftRightIndex' : 1 } } }
115+ climbs : { $sortArray : { input : '$climbs' , sortBy : { 'metadata.left_right_index' : 1 } } }
116116 }
117117 }
118118 ] )
@@ -123,6 +123,11 @@ export default class AreaDataSource extends MongoDataSource<AreaType> {
123123 throw new Error ( `Area ${ uuid . toUUID ( ) . toString ( ) } not found.` )
124124 }
125125
126+ async findChildren ( children : mongooseTypes . ObjectId [ ] ) : Promise < AreaType [ ] > {
127+ return await this . areaModel . find ( ) . where ( '_id' ) . in ( children )
128+ . sort ( { 'metadata.leftRightIndex' : 1 } ) . lean ( )
129+ }
130+
126131 async findManyClimbsByUuids ( uuidList : muuid . MUUID [ ] ) : Promise < ClimbType [ ] > {
127132 const rs = await this . climbModel . find ( ) . where ( '_id' ) . in ( uuidList )
128133 return rs
You can’t perform that action at this time.
0 commit comments