aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-03-17 20:54:05 -0500
committermat <github@matdoes.dev>2022-03-17 20:54:05 -0500
commitff7de90bc891242c7e0f17f8ed2e2c909513de80 (patch)
tree98ebee2017cad1f3288c430fd17191cfa96c1e60 /src
parent7158526469c2c8491e698545fdd3d6dfc2c62fb8 (diff)
downloadskyblock-api-ff7de90bc891242c7e0f17f8ed2e2c909513de80.tar.gz
skyblock-api-ff7de90bc891242c7e0f17f8ed2e2c909513de80.tar.bz2
skyblock-api-ff7de90bc891242c7e0f17f8ed2e2c909513de80.zip
Automatically update user's discord ids in accounts
Diffstat (limited to 'src')
-rw-r--r--src/database.ts11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/database.ts b/src/database.ts
index 26fa76f..c2fa026 100644
--- a/src/database.ts
+++ b/src/database.ts
@@ -93,6 +93,7 @@ interface SessionSchema {
export interface AccountCustomization {
backgroundUrl?: string
pack?: string
+ blurBackground?: boolean
emoji?: string
}
@@ -817,6 +818,16 @@ export async function fetchAccountFromDiscord(discordId: string): Promise<WithId
}
export async function updateAccount(discordId: string, schema: AccountSchema) {
+ if (schema.minecraftUuid) {
+ const existingAccount = await accountsCollection?.findOne({ minecraftUuid: schema.minecraftUuid })
+ // if the discord ids don't match, change the discord id of the existing account
+ if (existingAccount && existingAccount.discordId !== discordId) {
+ await accountsCollection?.updateOne(
+ { minecraftUuid: schema.minecraftUuid },
+ { '$set': { discordId } }
+ )
+ }
+ }
await accountsCollection?.updateOne({
discordId
}, { $set: schema }, { upsert: true })