From cdbc0bf7701dc183c790fa5ce337a6caef90bd0e Mon Sep 17 00:00:00 2001 From: Bruce Berrios <58147810+Bruception@users.noreply.github.com> Date: Sun, 8 May 2022 02:59:12 -0400 Subject: [PATCH] Add logic to handle duplicate names (#2958) --- backend/src/dal/user.ts | 10 +++++++--- backend/src/types/types.d.ts | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/backend/src/dal/user.ts b/backend/src/dal/user.ts index 5711299cd..b8e972c73 100644 --- a/backend/src/dal/user.ts +++ b/backend/src/dal/user.ts @@ -64,9 +64,13 @@ export async function updateName( throw new MonkeyError(400, "Invalid username"); } - return await db - .collection("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 { diff --git a/backend/src/types/types.d.ts b/backend/src/types/types.d.ts index d37f2a9e3..65f60a947 100644 --- a/backend/src/types/types.d.ts +++ b/backend/src/types/types.d.ts @@ -71,6 +71,7 @@ declare namespace MonkeyTypes { banned?: boolean; canManageApeKeys?: boolean; favoriteQuotes?: Record; + needsToUpdateName?: boolean; } type UserQuoteRatings = Record>;