File: //home/arjun/projects/good-life-be/models/CountDetails.js
import { DataTypes, Sequelize } from 'sequelize';
import sequelize from '../config/sequelize-config.js';
const EventsCount = sequelize.define(
'eventsCount',
{
category_name: {
type: DataTypes.STRING,
allowNull: true,
},
user_id: {
type: DataTypes.UUID,
allowNull: true, // Assuming the user must be associated with the event
},
monthly_count: {
type: DataTypes.JSONB, // Storing both original_count and current_count as JSONB
allowNull: true,
},
weekly_count: {
type: DataTypes.JSONB, // Storing both original_count and current_count as JSONB
allowNull: true,
},
createdAt: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
},
updatedAt: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
onUpdate: Sequelize.literal('CURRENT_TIMESTAMP'),
},
},
{
timestamps: true,
}
);
EventsCount.associate = (models) => {
EventsCount.belongsTo(models.user, {
foreignKey: 'user_id',
});
};
export default EventsCount;