Skip to content

Commit fcfd81b

Browse files
authored
Merge pull request #120 from manipalutsav/testing
2 parents d3f881c + 45ef839 commit fcfd81b

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/controllers/practiceSlot.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,49 @@ const getPracticeSlots = async (req, res, next) => {
154154
};
155155

156156

157+
const getSoltsByDate = async (req, res, next) => {
158+
try {
159+
const date = req.body.date
160+
// Fetch practice slots with populated college details
161+
162+
const slots = await PracticeSlotModel.find({date: new Date(date)});
163+
164+
// Check if practice slots are found
165+
if (!slots || slots.length === 0) {
166+
return res.status(404).json({ status: 404, message: "Practice slots not found" });
167+
}
168+
169+
// Map the practice slots data to include college name, location, and team details
170+
const populatedSlots = await Promise.all(slots.map(async (slot) => {
171+
const College = await CollegeModel.findById(slot.college);
172+
// Check if college is found
173+
if (!College) {
174+
throw new Error("College not found for practice slot");
175+
}
176+
// Format the data with college name and location
177+
const slotData = {
178+
order: slot.number,
179+
date:slot.date,
180+
college: College.name,
181+
location: College.location,
182+
team: slot.index
183+
};
184+
return slotData;
185+
}));
186+
187+
// Return the populated data with college details
188+
return res.json({
189+
status: 200,
190+
message: "Success",
191+
data: populatedSlots
192+
});
193+
} catch (error) {
194+
console.error("Error fetching practice slots:", error);
195+
return res.status(500).json({ status: 500, message: "Internal Server Error" });
196+
}
197+
};
198+
199+
157200

158201
const deletePracticeSlots = async (req, res) => {
159202
const date = req.body.date;
@@ -167,5 +210,6 @@ const deletePracticeSlots = async (req, res) => {
167210
module.exports = {
168211
createPracticeSlot,
169212
getPracticeSlots,
170-
deletePracticeSlots
213+
deletePracticeSlots,
214+
getSoltsByDate
171215
}

src/routes/practiceSlot.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const PracticeSlot = require("../controllers/practiceSlot");
55

66
router.post("/", PracticeSlot.createPracticeSlot);
77
router.get("/", PracticeSlot.getPracticeSlots);
8+
router.post("/getSlotsByDate", PracticeSlot.getSoltsByDate);
89
router.delete("/", PracticeSlot.deletePracticeSlots);
910

1011
module.exports = router;

0 commit comments

Comments
 (0)