-
-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathOrganizationQueries.ts
More file actions
33 lines (30 loc) · 1.2 KB
/
OrganizationQueries.ts
File metadata and controls
33 lines (30 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import type OrganizationDataSource from '../../model/OrganizationDataSource'
import { GQLContext, OrganizationGQLFilter, QueryByIdType, Sort } from '../../types'
const OrganizationQueries = {
organization: async (_: any,
{ muuid }: QueryByIdType,
context: GQLContext, info) => {
const { dataSources } = context
const { organizations }: { organizations: OrganizationDataSource } = dataSources
if (muuid != null) {
return await organizations.findOneOrganizationByOrgId(muuid)
}
return null
},
organizations: async (
_,
{ filter, sort, limit = 40, offset = 0 }: { filter?: OrganizationGQLFilter, sort?: Sort, limit?: number, offset?: number },
{ dataSources }: GQLContext
) => {
const { organizations }: { organizations: OrganizationDataSource } = dataSources
const MAX_LIMIT = 500
const safeLimit = Math.min(limit, MAX_LIMIT)
const filtered = await organizations.findOrganizationsByFilter(filter)
if (sort != null) {
return await filtered.collation({ locale: 'en' }).sort(sort).skip(offset).limit(safeLimit).toArray()
} else {
return await filtered.skip(offset).limit(safeLimit).toArray()
}
}
}
export default OrganizationQueries