mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
32 lines
773 B
JavaScript
32 lines
773 B
JavaScript
import { Track } from "@db_models"
|
|
|
|
export default async (track_id, { limit = 50, offset = 0 } = {}) => {
|
|
if (!track_id) {
|
|
throw new OperationError(400, "Missing track_id")
|
|
}
|
|
|
|
const isMultiple = track_id.includes(",")
|
|
|
|
if (isMultiple) {
|
|
const track_ids = track_id.split(",")
|
|
|
|
const tracks = await Track.find({ _id: { $in: track_ids } })
|
|
.limit(limit)
|
|
.skip(offset)
|
|
|
|
return {
|
|
total_count: await Track.countDocuments({ _id: { $in: track_ids } }),
|
|
list: tracks.map(track => track.toObject()),
|
|
}
|
|
}
|
|
|
|
const track = await Track.findOne({
|
|
_id: track_id
|
|
})
|
|
|
|
if (!track) {
|
|
throw new OperationError(404, "Track not found")
|
|
}
|
|
|
|
return track
|
|
} |