]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/models/author.js
3 const customUsersValidators
= require('../helpers/custom-validators').users
5 module
.exports = function (sequelize
, DataTypes
) {
6 const Author
= sequelize
.define('Author',
9 type: DataTypes
.STRING
,
12 usernameValid: function (value
) {
13 const res
= customUsersValidators
.isUserUsernameValid(value
)
14 if (res
=== false) throw new Error('Username is not valid.')
32 fields: [ 'name', 'podId' ],
47 // ---------------------------------------------------------------------------
49 function associate (models
) {
50 this.belongsTo(models
.Pod
, {
58 this.belongsTo(models
.User
, {
67 function findOrCreateAuthor (name
, podId
, userId
, transaction
, callback
) {
69 callback
= transaction
84 if (transaction
) query
.transaction
= transaction
86 this.findOrCreate(query
).asCallback(function (err
, result
) {
87 if (err
) return callback(err
)
89 // [ instance, wasCreated ]
90 return callback(null, result
[0])