2016-12-28 08:49:23 -06:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const customUsersValidators = require('../helpers/custom-validators').users
|
|
|
|
|
2016-12-11 14:50:51 -06:00
|
|
|
module.exports = function (sequelize, DataTypes) {
|
|
|
|
const Author = sequelize.define('Author',
|
|
|
|
{
|
|
|
|
name: {
|
2016-12-28 08:49:23 -06:00
|
|
|
type: DataTypes.STRING,
|
|
|
|
allowNull: false,
|
|
|
|
validate: {
|
|
|
|
usernameValid: function (value) {
|
|
|
|
const res = customUsersValidators.isUserUsernameValid(value)
|
|
|
|
if (res === false) throw new Error('Username is not valid.')
|
|
|
|
}
|
|
|
|
}
|
2016-12-11 14:50:51 -06:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
classMethods: {
|
|
|
|
associate
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
return Author
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
function associate (models) {
|
|
|
|
this.belongsTo(models.Pod, {
|
|
|
|
foreignKey: {
|
|
|
|
name: 'podId',
|
|
|
|
allowNull: true
|
|
|
|
},
|
|
|
|
onDelete: 'cascade'
|
|
|
|
})
|
|
|
|
}
|