Skip to content
Merged
Empty file modified .husky/pre-commit
100644 → 100755
Empty file.
734 changes: 734 additions & 0 deletions backend/controllers/roomBookingController.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const dashboardRoutes = require("./routes/dashboard.js");

const analyticsRoutes = require("./routes/analytics.js");
const porRoutes = require("./routes/por.js");
const roomBookingRoutes = require("./routes/roomBooking.js");
const app = express();

if (process.env.NODE_ENV === "production") {
Expand All @@ -41,7 +42,7 @@ app.use(
saveUninitialized: false,
cookie: {
secure: process.env.NODE_ENV === "production", // HTTPS only in prod
sameSite: process.env.NODE_ENV === "production" ? "none" : "lax", // cross-origin in prod
sameSite: process.env.NODE_ENV === "production" ? "none" : "lax", // cross-origin in prod,
},
}),
);
Expand All @@ -68,6 +69,7 @@ app.use("/api/announcements", announcementRoutes);
app.use("/api/dashboard", dashboardRoutes);
app.use("/api/announcements", announcementRoutes);
app.use("/api/analytics", analyticsRoutes);
app.use("/api/rooms", roomBookingRoutes);
app.use("/api/por", porRoutes);

// Start the server
Expand Down
130 changes: 130 additions & 0 deletions backend/models/schema.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const mongoose = require("mongoose");
const passportLocalMongoose = require("passport-local-mongoose");
var findOrCreate = require("mongoose-findorcreate");
const { v4: uuidv4 } = require("uuid");
//user collection

const userSchema = new mongoose.Schema({
Expand Down Expand Up @@ -645,6 +646,133 @@ const OrganizationalUnit = mongoose.model(
);
const Announcement = mongoose.model("Announcement", announcementSchema);

const roomSchema = new mongoose.Schema({
room_id: {
type: String,
required: true,
unique: true,
default: () => `ROOM_${uuidv4()}`,
},
name: {
type: String,
required: true,
unique: true,
},
capacity: {
type: Number,
required: true,
},
location: {
type: String,
required: true,
},
amenities: [
{
type: String,
},
],
Comment thread
coderabbitai[bot] marked this conversation as resolved.
allowed_roles: {
type: [
{
type: String,
enum: [
"PRESIDENT",
"GENSEC_SCITECH",
"GENSEC_ACADEMIC",
"GENSEC_CULTURAL",
"GENSEC_SPORTS",
"CLUB_COORDINATOR",
"STUDENT",
],
},
],
default: [
"PRESIDENT",
"GENSEC_SCITECH",
"GENSEC_ACADEMIC",
"GENSEC_CULTURAL",
"GENSEC_SPORTS",
"CLUB_COORDINATOR",
],
},
is_active: {
type: Boolean,
default: true,
},
created_at: {
type: Date,
default: Date.now,
},
updated_at: {
type: Date,
default: Date.now,
},
});

const Room = mongoose.model("Room", roomSchema);

const roomBookingSchema = new mongoose.Schema({
room: {
type: mongoose.Schema.Types.ObjectId,
ref: "Room",
required: true,
},
event: {
type: mongoose.Schema.Types.ObjectId,
ref: "Event",
},
date: {
type: Date,
required: true,
},
startTime: {
type: Date,
required: true,
},
endTime: {
type: Date,
required: true,
validate: {
validator: function (value) {
if (!this.startTime || !value) {
return false;
}
return value > this.startTime;
},
message: "endTime must be after startTime",
},
},
purpose: {
type: String,
},
bookedBy: {
type: mongoose.Schema.Types.ObjectId,
ref: "User",
required: true,
},
status: {
type: String,
enum: ["Pending", "Approved", "Rejected", "Cancelled"],
default: "Pending",
},
reviewedBy: {
type: mongoose.Schema.Types.ObjectId,
ref: "User",
},
created_at: {
type: Date,
default: Date.now,
},
updated_at: {
type: Date,
default: Date.now,
},
});

roomBookingSchema.index({ room: 1, date: 1, startTime: 1, endTime: 1 });

const RoomBooking = mongoose.model("RoomBooking", roomBookingSchema);

module.exports = {
User,
Feedback,
Expand All @@ -656,4 +784,6 @@ module.exports = {
Position,
OrganizationalUnit,
Announcement,
Room,
RoomBooking,
};
Loading