Skip to content

Commit

Permalink
Update track.js
Browse files Browse the repository at this point in the history
  • Loading branch information
anika213 authored Jul 31, 2023
1 parent 8183647 commit e0804f1
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions backend/controllers/track.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ const isValidTrack = (track) =>
// 3. If still less than 15 songs, search youtube and filter the results. If a yt track already exists in the database, use that instead. If not, create a new track in the database
const loadInitialPlayset = async (req, res) => {
const { patientId } = req.body;

console.log("in loadinitialplayset")
const patient = await patientModel.findById(patientId);
const era = Math.floor((patient.birthdate.getTime() / (1000 * 60 * 60 * 24 * 365) + 18) / 10 ) * 10 + 1960;

Expand All @@ -303,7 +303,18 @@ const loadInitialPlayset = async (req, res) => {
{
patient.trackRatings.push({ track: track._id, rating: 3 })
});
await patient.save();
// console.log(patient.trackRatings)
if(patient.trackRatings.length < 15){
// generate a function to check mongodb for all the tracks with the patient's language and get the first 15
const allTracks = await trackModel.find({ Language: patient.language});
const first15Tracks = allTracks.slice(0, 15);
// iterate through first15Tracks and add them to the patient's trackRatings array
first15Tracks.forEach((track) =>{
patient.trackRatings.push({ track: track._id, rating: 3 })
})
// console.log(patient.trackRatings)
}
await patient.save();

return res.status(200).json({ status: "OK", message: "Found tracks for patient: " + patientId });
};
Expand Down Expand Up @@ -443,4 +454,4 @@ module.exports = {
updateTrackRating,
getTitles,
manualYtQuery
};
};

0 comments on commit e0804f1

Please sign in to comment.