-
-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathTickQueries.ts
More file actions
24 lines (21 loc) · 1.02 KB
/
TickQueries.ts
File metadata and controls
24 lines (21 loc) · 1.02 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
import { TickByClimbSelectors, TickType, TickUserSelectors } from '../../db/TickTypes'
import type TickDataSource from '../../model/TickDataSource'
const DEFAULT_LIMIT = 50
const MAX_LIMIT = 500
const TickQueries = {
userTicks: async (_, input: TickUserSelectors, { dataSources }): Promise<TickType[] | null> => {
const { ticks }: { ticks: TickDataSource } = dataSources
const { limit, offset, ...selectors } = input
const safeLimit = Math.min(limit ?? DEFAULT_LIMIT, MAX_LIMIT)
const safeOffset = offset ?? 0
return await ticks.ticksByUser(selectors, safeLimit, safeOffset)
},
userTicksByClimbId: async (_, input: TickByClimbSelectors, { dataSources }): Promise<TickType[] | null> => {
const { ticks }: { ticks: TickDataSource } = dataSources
const { climbId, userId, limit, offset } = input
const safeLimit = Math.min(limit ?? DEFAULT_LIMIT, MAX_LIMIT)
const safeOffset = offset ?? 0
return await ticks.ticksByUserIdAndClimb(climbId, userId, safeLimit, safeOffset)
}
}
export default TickQueries