'use strict'; const { DataTypes } = require('sequelize'); const sequelize = require('../../config/db.config'); const { Course } = require('./courses.mdl'); const mdl_Product = sequelize.define('Product', { id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true }, course_id: { type: DataTypes.BIGINT, allowNull: false }, name: { type: DataTypes.STRING(200), allowNull: false }, description: { type: DataTypes.TEXT, allowNull: true }, price: { type: DataTypes.DECIMAL(10, 2), allowNull: false }, currency: { type: DataTypes.STRING(10), allowNull: false, defaultValue: 'USD' }, access_days: { type: DataTypes.INTEGER, allowNull: true }, is_active: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: true }, }, { tableName: 'products', timestamps: true, paranoid: true, }); // A course has one product listing; a product belongs to one course mdl_Product.belongsTo(Course, { foreignKey: 'course_id', as: 'course' }); Course.hasOne(mdl_Product, { foreignKey: 'course_id', as: 'product' }); module.exports = mdl_Product;