Skip to content

Commit

Permalink
sorted appointments
Browse files Browse the repository at this point in the history
  • Loading branch information
siddheshkothadi committed Mar 30, 2021
1 parent bbafc81 commit ffb75d0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
13 changes: 12 additions & 1 deletion backend/routes/patients.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,18 @@ router.route('/appointments').post(async (req, res) => {
try {
const googleId = req.body.googleId;
const appointments = await Appointment.find({patientId : googleId});
res.status(200).json(appointments);
sortedAppointments = appointments.sort((a, b) => {
console.log(`Date 1 : ${a.date} Time 1 : ${a.slotTime}`)
console.log(`Date 2 : ${b.date} Time 2 : ${b.slotTime}`)
d1 = Date.parse(a.date + 'T' + a.slotTime)
d2 = Date.parse(b.date + 'T' + b.slotTime)
console.log(d1)
console.log(d2)
console.log(d2-d1)
console.log(new Date("2021"))
return d2 - d1
})
res.status(200).json(sortedAppointments);
}
catch(err) {
console.log(err)
Expand Down
31 changes: 25 additions & 6 deletions frontend/src/Doctor/BookingSlots.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,36 @@ const BookingSlots = (props) => {
// console.log("Date: " + date + " DoctorId: " + doctorId);
const [dateId, setdateId] = useState();
const [Slots, setSlots] = useState([]);

function getDateString() {
let finalDate = date.getFullYear().toString()
const month = date.getMonth() + 1
const day = date.getDate();

if(month < 10) {
finalDate += ('-0' + month.toString())
}
else {
finalDate += month.toString()
}

if(day < 10) {
finalDate += ('-0' + day.toString())
}
else {
finalDate += day.toString()
}

return finalDate

}

const fetchDate = async () => {
const { data } = await Axios.post(
`${process.env.REACT_APP_SERVER_URL}/doctors/get-slots/`,
{
doctorId: doctor._id,
date:
date.getFullYear().toString() +
"-" +
(date.getMonth() + 1).toString() +
"-" +
date.getDate().toString(),
date: getDateString()
}
);
console.log(data);
Expand Down

0 comments on commit ffb75d0

Please sign in to comment.