2025-04-29 15:03:27 +00:00

90 lines
1.6 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 meals = sequelize.define(
'meals',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
food_item: {
type: DataTypes.TEXT,
},
quantity: {
type: DataTypes.DECIMAL,
},
calories: {
type: DataTypes.DECIMAL,
},
protein: {
type: DataTypes.DECIMAL,
},
carbs: {
type: DataTypes.DECIMAL,
},
fats: {
type: DataTypes.DECIMAL,
},
meal_date: {
type: DataTypes.DATE,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
meals.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.meals.belongsTo(db.users, {
as: 'user',
foreignKey: {
name: 'userId',
},
constraints: false,
});
db.meals.belongsTo(db.organizations, {
as: 'organizations',
foreignKey: {
name: 'organizationsId',
},
constraints: false,
});
db.meals.belongsTo(db.users, {
as: 'createdBy',
});
db.meals.belongsTo(db.users, {
as: 'updatedBy',
});
};
return meals;
};