Spaces:
Running
Running
Upload 9 files
Browse files- src/services/classroom.js +22 -0
src/services/classroom.js
CHANGED
|
@@ -41,6 +41,28 @@ export async function createRoom(promotedCode = null, hostName = 'Unknown') {
|
|
| 41 |
return roomCode;
|
| 42 |
}
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
/**
|
| 45 |
* Verifies instructor password against Firestore (Auto-seeds if missing)
|
| 46 |
* @param {string} inputPassword
|
|
|
|
| 41 |
return roomCode;
|
| 42 |
}
|
| 43 |
|
| 44 |
+
/**
|
| 45 |
+
* Cleans up rooms older than 14 days (inactive)
|
| 46 |
+
*/
|
| 47 |
+
export async function cleanupOldRooms() {
|
| 48 |
+
try {
|
| 49 |
+
const fourteenDaysAgo = new Date();
|
| 50 |
+
fourteenDaysAgo.setDate(fourteenDaysAgo.getDate() - 14);
|
| 51 |
+
|
| 52 |
+
const roomsRef = collection(db, ROOMS_COLLECTION);
|
| 53 |
+
const q = query(roomsRef, where("createdAt", "<", fourteenDaysAgo));
|
| 54 |
+
|
| 55 |
+
const snapshot = await getDocs(q);
|
| 56 |
+
if (snapshot.empty) return;
|
| 57 |
+
|
| 58 |
+
const deletePromises = snapshot.docs.map(doc => deleteDoc(doc.ref));
|
| 59 |
+
await Promise.all(deletePromises);
|
| 60 |
+
console.log(`Cleaned up ${snapshot.size} old rooms.`);
|
| 61 |
+
} catch (e) {
|
| 62 |
+
console.error("Cleanup failed:", e);
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
/**
|
| 67 |
* Verifies instructor password against Firestore (Auto-seeds if missing)
|
| 68 |
* @param {string} inputPassword
|