spee.ch/server/models/file.js

68 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-06-22 08:33:03 +02:00
module.exports = (sequelize, { STRING, BOOLEAN, INTEGER }) => {
const File = sequelize.define(
'File',
{
name: {
type : STRING,
allowNull: false,
},
2017-06-20 00:25:14 +02:00
claimId: {
type : STRING,
allowNull: false,
},
address: {
type : STRING,
allowNull: false,
},
outpoint: {
type : STRING,
allowNull: false,
},
2017-06-22 08:33:03 +02:00
height: {
type : INTEGER,
allowNull: false,
default : 0,
},
2017-06-20 00:25:14 +02:00
fileName: {
type : STRING,
allowNull: false,
},
2017-06-20 00:25:14 +02:00
filePath: {
type : STRING,
allowNull: false,
},
2017-06-20 00:25:14 +02:00
fileType: {
type: STRING,
},
nsfw: {
type : BOOLEAN,
allowNull : false,
defaultValue: false,
},
trendingEligible: {
type : BOOLEAN,
allowNull : false,
defaultValue: true,
},
},
{
freezeTableName: true,
}
);
2017-07-13 00:30:31 +02:00
File.associate = db => {
File.hasMany(db.Request);
2017-09-15 23:41:47 +02:00
File.hasOne(db.Claim);
2017-07-13 00:30:31 +02:00
};
2017-11-01 01:19:26 +01:00
File.getRecentClaims = function () {
return this.findAll({
where: { nsfw: false, trendingEligible: true },
order: [['createdAt', 'DESC']],
limit: 25,
});
};
return File;
};