37871-vm/backend/src/db/models/testimonials.js
2026-01-27 11:19:41 +00:00

109 lines
1.5 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 testimonials = sequelize.define(
'testimonials',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
author_name: {
type: DataTypes.TEXT,
},
content: {
type: DataTypes.TEXT,
},
rating: {
type: DataTypes.INTEGER,
},
visible: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
testimonials.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.testimonials.hasMany(db.file, {
as: 'author_photo',
foreignKey: 'belongsToId',
constraints: false,
scope: {
belongsTo: db.testimonials.getTableName(),
belongsToColumn: 'author_photo',
},
});
db.testimonials.belongsTo(db.users, {
as: 'createdBy',
});
db.testimonials.belongsTo(db.users, {
as: 'updatedBy',
});
};
return testimonials;
};