forked from kaverti/website
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
module.exports = (sequelize, DataTypes) => {
|
|
let Report = sequelize.define('Report', {
|
|
reason: {
|
|
type: DataTypes.ENUM,
|
|
values: ['spam', 'inappropriate', 'harassment','impersonatingme','impersonatingmybrandentity','impersonatingrepresent'],
|
|
validate: {
|
|
isIn: {
|
|
args: [['spam', 'inappropriate', 'harassment','impersonatingme','impersonatingmybrandentity','impersonatingrepresent']],
|
|
msg: "Report reason can only be one of the pre-defined options"
|
|
}
|
|
}
|
|
}
|
|
})
|
|
Report.associate = function (models) {
|
|
Report.belongsTo(models.User, { as: 'FlaggedByUser' })
|
|
Report.belongsTo(models.Post)
|
|
}
|
|
Report.InvalidPostId = function (value) {
|
|
return new sequelize.ValidationError('Post ID is not valid', [
|
|
new sequelize.ValidationErrorItem(
|
|
'Post id is not valid',
|
|
'Validation error',
|
|
'postId',
|
|
value
|
|
)
|
|
])
|
|
}
|
|
Report.InvalidUserId = function (value) {
|
|
return new sequelize.ValidationError('User ID is not valid', [
|
|
new sequelize.ValidationErrorItem(
|
|
'User ID is not valid',
|
|
'Validation error',
|
|
'userId',
|
|
value
|
|
)
|
|
])
|
|
}
|
|
|
|
return Report
|
|
}
|