parent
b282a002b8
commit
98a01bb3ca
7 changed files with 58 additions and 43 deletions
@ -1,28 +0,0 @@ |
||||
const models = require('../models'); |
||||
import * as api from '../../client/src/api'; |
||||
import { EndpointError, EndpointHandler, catchUnhandledErrors } from './types'; |
||||
|
||||
export const QueryArtistsEndpointHandler: EndpointHandler = async (req: any, res: any) => { |
||||
if (!api.checkQueryArtistsRequest(req.body)) { |
||||
const e: EndpointError = { |
||||
internalMessage: 'Invalid QueryArtists request: ' + JSON.stringify(req.body), |
||||
httpStatus: 400 |
||||
}; |
||||
throw e; |
||||
} |
||||
const reqObject: api.QueryArtistsRequest = req.body; |
||||
|
||||
await models.Artist.findAll({ |
||||
offset: reqObject.offset, |
||||
limit: reqObject.limit, |
||||
}) |
||||
.then((artists: any[]) => { |
||||
const response: api.QueryArtistsResponse = { |
||||
ids: artists.map((artist: any) => { |
||||
return artist.id |
||||
}) |
||||
} |
||||
res.send(response); |
||||
}) |
||||
.catch(catchUnhandledErrors); |
||||
} |
@ -0,0 +1,13 @@ |
||||
module.exports = (sequelize, DataTypes) => { |
||||
var Ranking = sequelize.define('Ranking', { |
||||
rank: DataTypes.DOUBLE |
||||
}); |
||||
|
||||
Ranking.associate = function (models) { |
||||
models.Ranking.hasOne(models.Tag, { as: 'tagContext' }); |
||||
models.Ranking.hasOne(models.Artist, { as: 'artistContext' }); |
||||
models.Ranking.belongsToMany(models.Song, { through: 'SongRankings' }); |
||||
}; |
||||
|
||||
return Ranking; |
||||
}; |
Loading…
Reference in new issue