feat: Added applyUsername function
This commit is contained in:
@@ -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 },
|
||||
|
@@ -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()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user