Updated changes in backend

This commit is contained in:
2026-06-19 11:54:20 +05:30
parent 7fb507c47e
commit ee81ca9228
33 changed files with 40 additions and 2538 deletions

View File

@@ -132,58 +132,17 @@ async function seedDatabaseIfEmpty() {
}
}
// Clean up existing dummy events with "Sample event for" description
const eventsSnap = await getDocs(collection(db, 'ems_events'));
if (eventsSnap.empty) {
console.log("[Firebase Backend] Seeding events...");
const venues = [
"GB 4th floor auditorium",
"Wozniak Auditorium",
"C6-02 Indoor Theatre",
"H Block Guest Lecture Theatre"
];
const categories = ["ACADEMIC", "CLUB", "PLACEMENT", "SPORTS"];
const types = ["Workshop", "Seminar", "Guest Lecture", "Competition"];
const statuses = ["REQUESTED", "APPROVED", "COMPLETED"];
let evId = 100;
const now = new Date();
for (let month = now.getMonth() - 2; month <= now.getMonth() + 2; month++) {
const targetMonth = (month + 12) % 12;
const targetYear = now.getFullYear() + (month < 0 ? -1 : (month > 11 ? 1 : 0));
for (const dept of ["CSE", "AI&ML"]) {
const start = new Date(targetYear, targetMonth, 15, 10, 0);
const end = new Date(targetYear, targetMonth, 15, 13, 0);
const venue = venues[Math.floor(Math.random() * venues.length)];
const cat = categories[Math.floor(Math.random() * categories.length)];
const type = types[Math.floor(Math.random() * types.length)];
const status = statuses[Math.floor(Math.random() * statuses.length)];
const event = {
id: evId++,
title: `${dept} ${type} - ${targetMonth + 1}/15`,
description: `Sample event for ${dept} department.`,
startDate: start.toISOString(),
endDate: end.toISOString(),
location: venue,
category: cat,
type: type,
institution: "RIT",
department: dept,
academicYears: ["3rd Year"],
status: status,
budget: 5000,
hasRegistrationFee: false,
registrationFee: 0,
proposer: { id: 2, fullName: "Dr. Faculty Member", email: "faculty@rit.edu", role: "FACULTY" }
};
await setDoc(doc(db, 'ems_events', String(event.id)), event);
}
for (const d of eventsSnap.docs) {
const data = d.data();
if (data.description && data.description.startsWith("Sample event for")) {
console.log("[Firebase Backend] Deleting dummy event:", data.title);
await deleteDoc(d.ref);
}
}
} catch (err) {
console.error("Seeding failed:", err);
console.error("Cleanup failed:", err);
}
}
@@ -678,6 +637,7 @@ window.fetch = async function(input: RequestInfo | URL, init?: RequestInit): Pro
registrationFee: feeStr === "" ? 0.0 : parseFloat(feeStr),
centreName: payload.centreName || null,
isPublicEvent: !!payload.isPublicEvent,
image: payload.image || null,
proposer: {
id: proposer.id,
fullName: proposer.fullName,
@@ -740,6 +700,7 @@ window.fetch = async function(input: RequestInfo | URL, init?: RequestInit): Pro
academicYears: ay,
status: payload.status || "APPROVED",
requirements: payload.requirements || [],
image: payload.image || null,
proposer
};
@@ -925,6 +886,7 @@ window.fetch = async function(input: RequestInfo | URL, init?: RequestInit): Pro
}
if (payload.centreName !== undefined) updatedFields.centreName = payload.centreName;
if (payload.isPublicEvent !== undefined) updatedFields.isPublicEvent = !!payload.isPublicEvent;
if (payload.image !== undefined) updatedFields.image = payload.image;
if (payload.status !== undefined && isAdmin) {
updatedFields.status = payload.status;
}