mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
sort liked tracks
This commit is contained in:
parent
cea012a1c7
commit
81fac75765
@ -9,6 +9,7 @@ export default async (req, res) => {
|
||||
let likedIds = await TrackLike.find({
|
||||
user_id: req.session.user_id,
|
||||
})
|
||||
.sort({ created_at: -1 })
|
||||
|
||||
likedIds = likedIds.map((item) => {
|
||||
return item.track_id
|
||||
@ -30,5 +31,12 @@ export default async (req, res) => {
|
||||
return item
|
||||
})
|
||||
|
||||
tracks.sort((a, b) => {
|
||||
const indexA = likedIds.indexOf(a._id.toString())
|
||||
const indexB = likedIds.indexOf(b._id.toString())
|
||||
|
||||
return indexA - indexB
|
||||
})
|
||||
|
||||
return res.json(tracks)
|
||||
}
|
@ -28,6 +28,7 @@ export default async (req, res) => {
|
||||
like = new TrackLike({
|
||||
track_id: track_id,
|
||||
user_id: req.session.user_id,
|
||||
created_at: new Date().getTime(),
|
||||
})
|
||||
|
||||
await like.save()
|
||||
|
@ -9,6 +9,9 @@ export default {
|
||||
track_id: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
created_at: {
|
||||
type: Date,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user