feat: Added verify account route, closes #28
All checks were successful
Build and Deploy / Deploy Web (push) Successful in 1m2s
Build and Deploy / Deploy Discord Bot (push) Successful in 44s

This commit is contained in:
Xeovalyte 2023-06-05 16:05:03 +02:00
parent 11a59d39af
commit d74a51db7f
4 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,24 @@
export default defineEventHandler(async (event) => {
const { uuid } = getQuery(event)
let whitelistDoc
try {
whitelistDoc = await WhitelistModel.findOneAndUpdate({ uuid }, {
$set: {
uuid
},
$setOnInsert: {
code: generateCode(),
connected: false
}
}, { returnDocument: 'after', upsert: true })
return whitelistDoc
} catch (e: any) {
throw createError({ statusCode: 500, statusMessage: 'Failed to update/insert whitelist document' })
}
})
const generateCode = () => {
return Math.floor(100000 + Math.random() * 900000)
}

View File

@ -21,4 +21,11 @@ const userSchema = new Schema({
] ]
}) })
const whitelistSchema = new Schema({
uuid: { type: String, required: true, unique: true },
connected: { type: Boolean, required: true, default: false },
code: { type: String, required: true, unique: true, length: 6 }
})
export const UserModel = model<IUser>('User', userSchema) export const UserModel = model<IUser>('User', userSchema)
export const WhitelistModel = model<IWhitelist>('Whitelist', whitelistSchema)

View File

@ -21,4 +21,11 @@ declare global {
teamId: string, teamId: string,
accessToken?: string accessToken?: string
} }
interface IWhitelist {
_id: string,
uuid: string,
connected: boolean,
code: string
}
} }