39948-vm/backend/src/db/models/project_audio_tracks.js

104 lines
2.0 KiB
JavaScript

module.exports = function (sequelize, DataTypes) {
const project_audio_tracks = sequelize.define(
'project_audio_tracks',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
environment: {
type: DataTypes.ENUM,
values: ['dev', 'stage', 'production'],
},
source_key: {
type: DataTypes.TEXT,
},
name: {
type: DataTypes.TEXT,
validate: {
len: {
args: [0, 255],
msg: 'Audio track name must be at most 255 characters',
},
},
},
slug: {
type: DataTypes.TEXT,
},
url: {
type: DataTypes.TEXT,
},
loop: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
volume: {
type: DataTypes.DECIMAL,
validate: {
min: { args: [0], msg: 'Volume must be at least 0' },
max: { args: [1], msg: 'Volume must be at most 1' },
},
},
sort_order: {
type: DataTypes.INTEGER,
},
is_enabled: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
project_audio_tracks.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
//end loop
db.project_audio_tracks.belongsTo(db.projects, {
as: 'project',
foreignKey: {
name: 'projectId',
},
constraints: true,
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
});
db.project_audio_tracks.belongsTo(db.users, {
as: 'createdBy',
});
db.project_audio_tracks.belongsTo(db.users, {
as: 'updatedBy',
});
};
return project_audio_tracks;
};