38745-vm/backend/src/db/models/voice_samples.js
2026-02-24 18:13:10 +00:00

149 lines
2.0 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 voice_samples = sequelize.define(
'voice_samples',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
sample_type: {
type: DataTypes.ENUM,
values: [
"training",
"validation"
],
},
duration_seconds: {
type: DataTypes.DECIMAL,
},
recorded_at: {
type: DataTypes.DATE,
},
is_deleted_by_user: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
voice_samples.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.voice_samples.belongsTo(db.voice_profiles, {
as: 'voice_profile',
foreignKey: {
name: 'voice_profileId',
},
constraints: false,
});
db.voice_samples.belongsTo(db.organizations, {
as: 'organizations',
foreignKey: {
name: 'organizationsId',
},
constraints: false,
});
db.voice_samples.hasMany(db.file, {
as: 'audio_file',
foreignKey: 'belongsToId',
constraints: false,
scope: {
belongsTo: db.voice_samples.getTableName(),
belongsToColumn: 'audio_file',
},
});
db.voice_samples.belongsTo(db.users, {
as: 'createdBy',
});
db.voice_samples.belongsTo(db.users, {
as: 'updatedBy',
});
};
return voice_samples;
};