Skip to content

Commit 666fa4c

Browse files
committed
New area datasource getChildren endpoint
1 parent cc0e38d commit 666fa4c

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/graphql/resolvers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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
},

src/model/AreaDataSource.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { MongoDataSource } from 'apollo-datasource-mongodb'
22
import { Filter } from 'mongodb'
33
import muuid from 'uuid-mongodb'
44
import bboxPolygon from '@turf/bbox-polygon'
5+
import { Types as mongooseTypes } from 'mongoose'
56

67
import { getAreaModel, getMediaModel, getMediaObjectModel } from '../db/index.js'
78
import { 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

0 commit comments

Comments
 (0)