( uid: string, stack: string, fields: K[], )
| 263 | * @throws MonkeyError if user does not exist |
| 264 | */ |
| 265 | export async function getPartialUser<K extends keyof DBUser>( |
| 266 | uid: string, |
| 267 | stack: string, |
| 268 | fields: K[], |
| 269 | ): Promise<Pick<DBUser, K>> { |
| 270 | const projection = new Map(fields.map((it) => [it, 1])); |
| 271 | const partialUser = await getUsersCollection().findOne( |
| 272 | { uid }, |
| 273 | { projection }, |
| 274 | ); |
| 275 | if (partialUser === null) throw new MonkeyError(404, "User not found", stack); |
| 276 | |
| 277 | if (fields.includes("personalBests" as K)) { |
| 278 | return migrateUser(partialUser); |
| 279 | } |
| 280 | return partialUser; |
| 281 | } |
| 282 | |
| 283 | export async function findByName(name: string): Promise<DBUser | undefined> { |
| 284 | const found = await getUsersCollection().findOne( |
no test coverage detected