fix: Auto add user to new team

This commit is contained in:
Xeovalyte 2023-06-06 16:35:25 +02:00
parent 9510e8a407
commit 034e203c1e
3 changed files with 8 additions and 3 deletions

View File

@ -1,5 +1,3 @@
export default defineEventHandler((event) => {
return {
hello: 'world'
}
const userId: string = event.context.params ? event.context.params.id : '@me'
})

View File

@ -1,6 +1,8 @@
export default defineEventHandler(async (event) => {
const { name, color } = await readBody(event)
const user = await getUser('@me', event)
const team = new TeamModel({
name,
color
@ -8,5 +10,9 @@ export default defineEventHandler(async (event) => {
await team.save()
user.teamId = team._id
await user.save()
return team
})

View File

@ -3,6 +3,7 @@ import { Schema, Types, model } from 'mongoose'
const userSchema = new Schema({
username: { type: String, required: false },
usernameType: { type: String, required: true, default: 'discord' },
teamId: { type: Types.ObjectId, ref: 'Team', required: false },
discord: {
id: { type: String, required: true, unique: true },
username: { type: String, required: true }