From 9510e8a4072df21d308c862b99fd18e2d377cd93 Mon Sep 17 00:00:00 2001 From: Xeovalyte Date: Tue, 6 Jun 2023 14:29:05 +0200 Subject: [PATCH] feat: Added team creation, closes #22 --- webv2/server/api/teams/index.post.ts | 12 ++++++++++++ webv2/server/utils/models.ts | 9 +++++++++ webv2/types/global.d.ts | 9 +++++++++ 3 files changed, 30 insertions(+) create mode 100644 webv2/server/api/teams/index.post.ts diff --git a/webv2/server/api/teams/index.post.ts b/webv2/server/api/teams/index.post.ts new file mode 100644 index 0000000..a8f69cc --- /dev/null +++ b/webv2/server/api/teams/index.post.ts @@ -0,0 +1,12 @@ +export default defineEventHandler(async (event) => { + const { name, color } = await readBody(event) + + const team = new TeamModel({ + name, + color + }) + + await team.save() + + return team +}) diff --git a/webv2/server/utils/models.ts b/webv2/server/utils/models.ts index 23275a5..8b95acd 100644 --- a/webv2/server/utils/models.ts +++ b/webv2/server/utils/models.ts @@ -27,5 +27,14 @@ const whitelistSchema = new Schema({ code: { type: String, required: true, unique: true, length: 6 } }) +const teamSchema = new Schema({ + name: { type: String, required: true, minLength: 3, maxLength: 16, unique: true, match: /^[a-zA-Z0-9]+$/ }, + color: { type: String, required: true, match: /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/ }, + amount: { type: Number, required: true, default: 1 }, + textChannelId: { type: String, required: false }, + voiceChannelId: { type: String, required: false } +}) + export const UserModel = model('User', userSchema) export const WhitelistModel = model('Whitelist', whitelistSchema) +export const TeamModel = model('Team', teamSchema) diff --git a/webv2/types/global.d.ts b/webv2/types/global.d.ts index fdea89e..b75bf2d 100644 --- a/webv2/types/global.d.ts +++ b/webv2/types/global.d.ts @@ -31,4 +31,13 @@ declare global { connected: boolean, code: string } + + interface ITeam { + _id: string, + name: string, + color: string, + amount: number, + textChannelId: string, + voiceChannelId: string + } }