Add logic to handle duplicate names (#2958)

This commit is contained in:
Bruce Berrios 2022-05-08 02:59:12 -04:00 committed by GitHub
parent c50218f709
commit cdbc0bf770
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View file

@ -64,9 +64,13 @@ export async function updateName(
throw new MonkeyError(400, "Invalid username");
}
return await db
.collection<MonkeyTypes.User>("users")
.updateOne({ uid }, { $set: { name, lastNameChange: Date.now() } });
return await getUsersCollection().updateOne(
{ uid },
{
$set: { name, lastNameChange: Date.now() },
$unset: { needsToUpdateName: "" },
}
);
}
export async function clearPb(uid: string): Promise<UpdateResult> {

View file

@ -71,6 +71,7 @@ declare namespace MonkeyTypes {
banned?: boolean;
canManageApeKeys?: boolean;
favoriteQuotes?: Record<string, string[]>;
needsToUpdateName?: boolean;
}
type UserQuoteRatings = Record<string, Record<string, number>>;