I need help friends! I need to write function for get request in my REST API. In this function I need to get all playlists by branchId, and get for each playlist files by playlistId, and send array of objects with properties [{playlist, files}, {playlist, files}, {playlist, files}].
I think my function need to be async. I try it, but I have some problems when I want to get files for each playlist.
exports.findBranchePlaylists = async function(req, res) {
let data = [];
let playlists = await Playlist.find({branch_id: req.params.branchId});
playlists.forEach(async (playlist) => {
let files = await File.find({playlistId: playlist._id });
data.push({playlist, files});
})
res.send(playlists);
};
I know that it is wrong code, I want to show you, what I want to do. this code send me only this - [].