37914-vm/backend/src/db/models/wishlists.js
2026-01-28 15:36:11 +00:00

115 lines
1.7 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 wishlists = sequelize.define(
'wishlists',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
name: {
type: DataTypes.TEXT,
},
created_on: {
type: DataTypes.DATE,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
wishlists.associate = (db) => {
db.wishlists.belongsToMany(db.products, {
as: 'products',
foreignKey: {
name: 'wishlists_productsId',
},
constraints: false,
through: 'wishlistsProductsProducts',
});
db.wishlists.belongsToMany(db.products, {
as: 'products_filter',
foreignKey: {
name: 'wishlists_productsId',
},
constraints: false,
through: 'wishlistsProductsProducts',
});
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
//end loop
db.wishlists.belongsTo(db.users, {
as: 'user',
foreignKey: {
name: 'userId',
},
constraints: false,
});
db.wishlists.belongsTo(db.users, {
as: 'createdBy',
});
db.wishlists.belongsTo(db.users, {
as: 'updatedBy',
});
};
return wishlists;
};