2020-01-14 23:26:39 +01:00
|
|
|
module.exports = models => {
|
|
|
|
const {
|
|
|
|
User,
|
|
|
|
PermissionLevel,
|
|
|
|
Shelf,
|
|
|
|
Status,
|
|
|
|
Review,
|
|
|
|
Recommendation,
|
2020-01-20 18:47:31 +01:00
|
|
|
Follow,
|
2020-01-14 23:26:39 +01:00
|
|
|
} = models;
|
|
|
|
|
|
|
|
User.belongsTo(PermissionLevel, {
|
|
|
|
foreignKey: 'permissionLevel',
|
|
|
|
onDelete: 'SET NULL',
|
|
|
|
});
|
|
|
|
User.hasMany(Shelf);
|
|
|
|
User.hasMany(Status);
|
|
|
|
User.hasMany(Review);
|
|
|
|
User.hasMany(Recommendation, {
|
|
|
|
foreignKey: 'toUser',
|
|
|
|
});
|
2020-01-20 18:47:31 +01:00
|
|
|
User.hasMany(Follow, {
|
|
|
|
foreignKey: 'follower',
|
|
|
|
as: 'Followers',
|
|
|
|
});
|
|
|
|
User.belongsTo(Follow.scope('internal'), {
|
|
|
|
foreignKey: 'following',
|
|
|
|
as: 'Follows',
|
|
|
|
});
|
2020-01-14 23:26:39 +01:00
|
|
|
|
|
|
|
return User;
|
|
|
|
}
|