MCPcopy Create free account
hub / github.com/monkeytypegame/monkeytype / getResults

Function getResults

backend/src/dal/result.ts:109–145  ·  view source on GitHub ↗
(
  uid: string,
  opts?: GetResultsOpts,
)

Source from the content-addressed store, hash-verified

107};
108
109export 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}

Callers

nothing calls this directly

Calls 1

getResultCollectionFunction · 0.85

Tested by

no test coverage detected