feat: Added applyUsername function

This commit is contained in:
2023-06-06 13:49:27 +02:00
parent 89027590ca
commit e28d2278cb
8 changed files with 25 additions and 7 deletions

View File

@@ -1,7 +1,7 @@
import { Schema, Types, model } from 'mongoose'
const userSchema = new Schema({
username: { type: String, required: true },
username: { type: String, required: false },
usernameType: { type: String, required: true, default: 'discord' },
discord: {
id: { type: String, required: true, unique: true },

View File

@@ -46,3 +46,15 @@ export const getUser = async (userId: string, event: any) => {
throw createError({ statusCode: 500, statusMessage: 'Failed to get user' })
}
}
export const applyUsername = async (user: IUser) => {
if (user.usernameType === 'discord' || user.$isEmpty('minecraft') || !user.minecraft) {
user.username = user.discord.username
await user.save()
} else {
user.username = user.minecraft.username
await user.save()
}
}