Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified .husky/pre-commit
100644 → 100755
Empty file.
731 changes: 731 additions & 0 deletions backend/controllers/roomBookingController.js

Large diffs are not rendered by default.

16 changes: 12 additions & 4 deletions backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@ 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") {
app.set("trust proxy", 1);
}

app.use(cors({ origin: process.env.FRONTEND_URL, credentials: true }));
app.use(
cors({
origin: "http://localhost:3000",
credentials: true,
}),
);

// Connect to MongoDB
connectDB();
Expand All @@ -38,10 +44,11 @@ app.use(
session({
secret: "keyboard cat",
resave: false,
saveUninitialized: false,
saveUninitialized: true,
cookie: {
secure: process.env.NODE_ENV === "production", // HTTPS only in prod
sameSite: process.env.NODE_ENV === "production" ? "none" : "lax", // cross-origin in prod
secure: false,
sameSite: "lax",
httpOnly: true,
},
}),
);
Expand All @@ -68,6 +75,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
11 changes: 7 additions & 4 deletions backend/models/passportConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,18 @@ passport.use(
);

passport.serializeUser((user, done) => {
done(null, user);
done(null, user.id);
});

passport.deserializeUser(async (userKey, done) => {
passport.deserializeUser(async (id, done) => {
try {
let user = await User.findById(userKey._id);
let user = await User.findById(id);
if (!user) {
return done(null, false);
}
done(null, user);
} catch (err) {
done(err);
done(err, null);
}
});

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,
},
],
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