combine.fm/routes/recent.js
2020-01-18 10:19:20 +00:00

23 lines
564 B
JavaScript

import models from '../models/index.cjs';
const recentQuery = {
include: [
{ model: models.artist },
{ model: models.match },
],
limit: 9,
order: [
['updatedAt', 'DESC'],
],
};
export default async function (ctx) {
const recentAlbums = await models.album.findAll(recentQuery);
const recentTracks = await models.track.findAll(recentQuery);
ctx.body = {
recents: recentAlbums.map(album => album.toJSON())
.concat(recentTracks.map(track => track.toJSON()))
.sort((a, b) => a.createdAt < b.createdAt).slice(0, 9),
};
}