2026-01-27 17:00:08 +00:00

130 lines
1.8 KiB
JavaScript

const config = require('../../config');
const providers = config.providers;
const crypto = require('crypto');
const bcrypt = require('bcrypt');
const moment = require('moment');
module.exports = function(sequelize, DataTypes) {
const artists = sequelize.define(
'artists',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
name: {
type: DataTypes.TEXT,
},
genre: {
type: DataTypes.TEXT,
},
origin: {
type: DataTypes.TEXT,
},
website: {
type: DataTypes.TEXT,
},
description: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
artists.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
db.artists.hasMany(db.events, {
as: 'events_artist',
foreignKey: {
name: 'artistId',
},
constraints: false,
});
db.artists.hasMany(db.searches, {
as: 'searches_artist',
foreignKey: {
name: 'artistId',
},
constraints: false,
});
//end loop
db.artists.hasMany(db.file, {
as: 'images',
foreignKey: 'belongsToId',
constraints: false,
scope: {
belongsTo: db.artists.getTableName(),
belongsToColumn: 'images',
},
});
db.artists.belongsTo(db.users, {
as: 'createdBy',
});
db.artists.belongsTo(db.users, {
as: 'updatedBy',
});
};
return artists;
};