Polarcraft/webv2/server/utils/models.ts

45 lines
1.5 KiB
TypeScript
Raw Normal View History

import { Schema, Types, model } from 'mongoose'
const userSchema = new Schema({
2023-06-06 13:49:27 +02:00
username: { type: String, required: false },
usernameType: { type: String, required: true, default: 'discord' },
2023-06-06 18:22:36 +02:00
team: { type: Types.ObjectId, ref: 'Team', required: false },
discord: {
id: { type: String, required: true, unique: true },
2023-06-12 16:48:38 +02:00
username: { type: String, required: true },
avatarHash: { 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: [
2023-06-06 22:28:26 +02:00
{ type: Types.ObjectId, ref: 'Team' }
]
2023-06-06 13:48:24 +02:00
})
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 }
})
2023-06-06 14:29:05 +02:00
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 },
2023-06-06 18:22:36 +02:00
voiceChannelId: { type: String, required: false },
members: [
{ type: Types.ObjectId, ref: 'User' }
]
2023-06-06 14:29:05 +02:00
})
export const UserModel = model<IUser>('User', userSchema)
export const WhitelistModel = model<IWhitelist>('Whitelist', whitelistSchema)
2023-06-06 14:29:05 +02:00
export const TeamModel = model<ITeam>('Team', teamSchema)