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

Function updateName

backend/src/dal/user.ts:163–187  ·  view source on GitHub ↗
(
  uid: string,
  name: string,
  previousName: string,
)

Source from the content-addressed store, hash-verified

161}
162
163export async function updateName(
164 uid: string,
165 name: string,
166 previousName: string,
167): Promise<void> {
168 if (name === previousName) {
169 throw new MonkeyError(400, "New name is the same as the old name");
170 }
171
172 if (
173 name?.toLowerCase() !== previousName?.toLowerCase() &&
174 !(await isNameAvailable(name, uid))
175 ) {
176 throw new MonkeyError(409, "Username already taken", name);
177 }
178
179 await getUsersCollection().updateOne(
180 { uid },
181 {
182 $set: { name, lastNameChange: Date.now() },
183 $unset: { needsToChangeName: "" },
184 $push: { nameHistory: previousName },
185 },
186 );
187}
188
189export async function flagForNameChange(uid: string): Promise<void> {
190 await getUsersCollection().updateOne(

Callers

nothing calls this directly

Calls 2

isNameAvailableFunction · 0.85
getUsersCollectionFunction · 0.85

Tested by

no test coverage detected