Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhruv9544 committed Nov 25, 2023
2 parents 8260df6 + fdc90c2 commit 1dbc3fa
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
44 changes: 44 additions & 0 deletions Controller/GuestController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Guest = require("../Model/GuestModel");
const instructorModel = require("../Model/instructorModel");

// Add data controller
(module.exports.addUser = async function (req, res) {
Expand All @@ -19,3 +20,46 @@ const Guest = require("../Model/GuestModel");
res.status(500).json({ error: error.message });
}
});

module.exports.gettimeslotfrominstructor = async function (req, res) {
try {
let data = await instructorModel.find({
SportComplexId: req.query.SportComplexId,
});
let timeslot = [];

for (let index = 0; index < data.length; index++) {
const element = data[index];
for (let j = 0; j < element.sports.length; j++) {
const ele = element.sports[j];
if (ele.sport.equals(req.query.sportId)) {
timeslot = timeslot.concat(ele.timeSlot);
}
}
}

res.json({ data: timeslot, rcode: 200 });
} catch (error) {
console.error("Error:", error);
res.status(500).json({ error: "Internal Server Error", rcode: 500 });
}
};

// module.exports.gettimeslotfrominstructor = async function (req, res) {
// let data = await instructorModel.find({
// SportComplexId: req.query.SportComplexId,
// });
// let timeslot = [];

// for (let index = 0; index < data.length; index++) {
// const element = data[index];
// for (let index = 0; index < element.sports.length; index++) {
// const ele = element.sports[index];
// if (ele === req.query.sportId) {
// // timeslot = ele.timeSlot;
// timeslot.push(ele.timeSlot);
// }
// }
// }
// res.json({ data: timeslot, rcode: 200 });
// };
8 changes: 4 additions & 4 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const SupervisorDashboardController = require("./Controller/SupervisorDashboardC
const UpdatesController = require("./Controller/UpdatesController");
const UpdatesImageController = require("./Controller/UpdatesImageController");
const UtilizationController = require("./Controller/UtilizationController");
const GuestController = require("./Controller/GuestController")
const GuestController = require("./Controller/GuestController");

const {
filtersportsforcomplex,
Expand Down Expand Up @@ -434,8 +434,8 @@ cron.schedule("*/1 * * * *", async function () {
});

//Guest route
app.post('/addGuest',GuestController.addUser)
app.get('/getGuest',GuestController.getAllUsers)

app.post("/addGuest", GuestController.addUser);
app.get("/getGuest", GuestController.getAllUsers);
app.get("/gettimeslotforguest", GuestController.gettimeslotfrominstructor);
app.listen(9999);
console.log("server started at 9999");

0 comments on commit 1dbc3fa

Please sign in to comment.