( uid: string, opts?: GetResultsOpts, )
| 107 | }; |
| 108 | |
| 109 | export async function getResults( |
| 110 | uid: string, |
| 111 | opts?: GetResultsOpts, |
| 112 | ): Promise<DBResult[]> { |
| 113 | const { onOrAfterTimestamp, offset, limit } = opts ?? {}; |
| 114 | |
| 115 | const condition: Filter<DBResult> = { uid }; |
| 116 | if ( |
| 117 | onOrAfterTimestamp !== undefined && |
| 118 | onOrAfterTimestamp !== null && |
| 119 | !isNaN(onOrAfterTimestamp) |
| 120 | ) { |
| 121 | condition.timestamp = { $gte: onOrAfterTimestamp }; |
| 122 | } |
| 123 | |
| 124 | let query = getResultCollection() |
| 125 | .find(condition, { |
| 126 | projection: { |
| 127 | chartData: 0, |
| 128 | keySpacingStats: 0, |
| 129 | keyDurationStats: 0, |
| 130 | name: 0, |
| 131 | }, |
| 132 | }) |
| 133 | .sort({ timestamp: -1 }); |
| 134 | |
| 135 | if (limit !== undefined) { |
| 136 | query = query.limit(limit); |
| 137 | } |
| 138 | if (offset !== undefined) { |
| 139 | query = query.skip(offset); |
| 140 | } |
| 141 | |
| 142 | const results = await query.toArray(); |
| 143 | if (results === undefined) throw new MonkeyError(404, "Result not found"); |
| 144 | return results.map(replaceLegacyValues); |
| 145 | } |
nothing calls this directly
no test coverage detected