combine.fm/routes/recent.js

24 lines
564 B
JavaScript
Raw Permalink Normal View History

2020-01-18 10:19:20 +00:00
import models from '../models/index.cjs';
const recentQuery = {
include: [
{ model: models.artist },
{ model: models.match },
],
2017-11-11 21:29:47 +00:00
limit: 9,
order: [
['updatedAt', 'DESC'],
],
};
2018-04-13 21:44:31 +01:00
export default async function (ctx) {
const recentAlbums = await models.album.findAll(recentQuery);
const recentTracks = await models.track.findAll(recentQuery);
2018-04-13 21:44:31 +01:00
ctx.body = {
recents: recentAlbums.map(album => album.toJSON())
.concat(recentTracks.map(track => track.toJSON()))
2017-11-11 21:29:47 +00:00
.sort((a, b) => a.createdAt < b.createdAt).slice(0, 9),
};
}