forked from Deen-Bridge/dnb-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpace.js
More file actions
88 lines (81 loc) · 1.87 KB
/
Copy pathSpace.js
File metadata and controls
88 lines (81 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import mongoose from "mongoose";
import { buildMeetingUrl } from "../utils/jitsi.js";
const spaceSchema = new mongoose.Schema(
{
title: {
type: String,
required: true,
trim: true,
},
description: {
type: String,
required: true,
},
category: {
type: String,
required: true,
},
thumbnail: {
type: String, // image URL
},
// Host of the space (user who created it)
host: {
type: mongoose.Schema.Types.ObjectId,
ref: "User",
required: true,
},
price: {
type: Number,
default: 0, // 0 means free, any other value means paid
},
status: {
type: String,
enum: ["live", "upcoming", "ended"],
default: "upcoming",
},
eventDate: {
type: Date,
required: true,
},
eventTime: {
type: String, // e.g., "14:00" or "18:30"
required: true,
},
waitList: [
{
type: mongoose.Schema.Types.ObjectId,
ref: "User",
},
],
duration: {
type: Number, // in minutes
required: true,
},
enrolledUsers: [{ type: mongoose.Schema.Types.ObjectId, ref: "User" }],
meetingRoom: {
type: String,
required: true,
unique: true,
},
meetingUrl: {
type: String,
required: true,
},
},
{ timestamps: true }
);
spaceSchema.pre("validate", function (next) {
const domain = process.env.JITSI_MEET_DOMAIN || "meet.jit.si";
if (!this.meetingRoom) {
const suffix = Math.random().toString(36).slice(2, 8);
this.meetingRoom = `deenbridge-space-${this._id
.toString()
.slice(-6)}-${suffix}`;
}
if (!this.meetingUrl) {
this.meetingUrl = buildMeetingUrl(domain, this.meetingRoom);
}
next();
});
spaceSchema.index({ title: "text", description: "text", category: "text" });
export default mongoose.model("Space", spaceSchema);