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

Function addUser

backend/src/dal/user.ts:82–111  ·  view source on GitHub ↗
(
  name: string,
  email: string,
  uid: string,
)

Source from the content-addressed store, hash-verified

80 db.collection<DBUser>("users");
81
82export 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
113export async function deleteUser(uid: string): Promise<void> {
114 await getUsersCollection().deleteOne({ uid });

Callers

nothing calls this directly

Calls 1

getUsersCollectionFunction · 0.85

Tested by

no test coverage detected