33027/backend/src/db/models/vendors.js
2025-07-25 02:55:19 +00:00

64 lines
1.2 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 vendors = sequelize.define(
'vendors',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
name: {
type: DataTypes.TEXT,
},
contact_info: {
type: DataTypes.TEXT,
},
category: {
type: DataTypes.ENUM,
values: ['Caterer', 'Decorator', 'Entertainer'],
},
rating: {
type: DataTypes.DECIMAL,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
vendors.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.vendors.belongsTo(db.users, {
as: 'createdBy',
});
db.vendors.belongsTo(db.users, {
as: 'updatedBy',
});
};
return vendors;
};