( name: string, email: string, uid: string, )
| 80 | db.collection<DBUser>("users"); |
| 81 | |
| 82 | export async function addUser( |
| 83 | name: string, |
| 84 | email: string, |
| 85 | uid: string, |
| 86 | ): Promise<void> { |
| 87 | const newUserDocument: Partial<DBUser> = { |
| 88 | name, |
| 89 | email, |
| 90 | uid, |
| 91 | addedAt: Date.now(), |
| 92 | personalBests: { |
| 93 | time: {}, |
| 94 | words: {}, |
| 95 | quote: {}, |
| 96 | zen: {}, |
| 97 | custom: {}, |
| 98 | }, |
| 99 | testActivity: {}, |
| 100 | }; |
| 101 | |
| 102 | const result = await getUsersCollection().updateOne( |
| 103 | { uid }, |
| 104 | { $setOnInsert: newUserDocument }, |
| 105 | { upsert: true }, |
| 106 | ); |
| 107 | |
| 108 | if (result.upsertedCount === 0) { |
| 109 | throw new MonkeyError(409, "User document already exists", "addUser"); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | export async function deleteUser(uid: string): Promise<void> { |
| 114 | await getUsersCollection().deleteOne({ uid }); |
nothing calls this directly
no test coverage detected