2020-01-18 10:19:20 +00:00
|
|
|
import models from '../models/index.cjs';
|
2016-10-03 13:31:29 +01:00
|
|
|
|
|
|
|
const recentQuery = {
|
|
|
|
include: [
|
|
|
|
{ model: models.artist },
|
|
|
|
{ model: models.match },
|
|
|
|
],
|
2017-11-11 21:29:47 +00:00
|
|
|
limit: 9,
|
2016-10-03 13:31:29 +01:00
|
|
|
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);
|
2016-10-03 13:31:29 +01:00
|
|
|
|
2018-04-13 21:44:31 +01:00
|
|
|
ctx.body = {
|
2016-10-03 13:31:29 +01:00
|
|
|
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),
|
2016-10-03 13:31:29 +01:00
|
|
|
};
|
|
|
|
}
|