33449/backend/src/db/models/products.js
2025-08-18 06:41:48 +00:00

90 lines
1.3 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 products = sequelize.define(
'products',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
title: {
type: DataTypes.TEXT,
},
description: {
type: DataTypes.TEXT,
},
unit: {
type: DataTypes.TEXT,
},
price: {
type: DataTypes.DECIMAL,
},
stock: {
type: DataTypes.INTEGER,
},
harvest_date: {
type: DataTypes.DATE,
},
organic: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
approved: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
products.associate = (db) => {
db.products.belongsTo(db.users, {
as: 'createdBy',
});
db.products.belongsTo(db.users, {
as: 'updatedBy',
});
};
return products;
};