Polarcraft/webv2/server/utils/models.ts
Xeovalyte f9c13e5ada
All checks were successful
Build and Deploy / Deploy Web (push) Successful in 1m3s
Build and Deploy / Deploy Discord Bot (push) Successful in 43s
feat: Added team leave
2023-06-06 18:22:36 +02:00

44 lines
1.4 KiB
TypeScript

import { Schema, Types, model } from 'mongoose'
const userSchema = new Schema({
username: { type: String, required: false },
usernameType: { type: String, required: true, default: 'discord' },
team: { type: Types.ObjectId, ref: 'Team', required: false },
discord: {
id: { type: String, required: true, unique: true },
username: { type: String, required: true }
},
minecraft: {
uuid: { type: String, required: false, unique: true },
username: { type: String, required: false }
},
role: {
admin: Boolean,
moderator: Boolean,
teamAdmin: Boolean
},
teamInvites: [
Types.ObjectId
]
})
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 }
})
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})$/ },
textChannelId: { type: String, required: false },
voiceChannelId: { type: String, required: false },
members: [
{ type: Types.ObjectId, ref: 'User' }
]
})
export const UserModel = model<IUser>('User', userSchema)
export const WhitelistModel = model<IWhitelist>('Whitelist', whitelistSchema)
export const TeamModel = model<ITeam>('Team', teamSchema)