31 lines
1.5 KiB
JavaScript
31 lines
1.5 KiB
JavaScript
const { DataTypes } = require('sequelize');
|
|
const { sequelize } = require('../config/database');
|
|
|
|
const Subject = sequelize.define('subjects', {
|
|
id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true },
|
|
category_id: { type: DataTypes.UUID, allowNull: false, comment: 'Danh mục chủ đề' },
|
|
subject_code: { type: DataTypes.STRING(20), unique: true, allowNull: false },
|
|
subject_name: { type: DataTypes.STRING(100), allowNull: false },
|
|
subject_name_en: { type: DataTypes.STRING(100) },
|
|
description: { type: DataTypes.TEXT },
|
|
is_active: { type: DataTypes.BOOLEAN, defaultValue: true },
|
|
is_premium: { type: DataTypes.BOOLEAN, defaultValue: false, comment: 'Nội dung premium' },
|
|
is_training: { type: DataTypes.BOOLEAN, defaultValue: false, comment: 'Nội dung đào tạo nhân sự' },
|
|
is_public: { type: DataTypes.BOOLEAN, defaultValue: false, comment: 'Nội dung tự học công khai' },
|
|
required_role: { type: DataTypes.STRING(50), comment: 'Role yêu cầu' },
|
|
min_subscription_tier: { type: DataTypes.STRING(50), comment: 'Gói tối thiểu: basic, premium, vip' },
|
|
created_at: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW },
|
|
updated_at: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW },
|
|
}, {
|
|
tableName: 'subjects',
|
|
timestamps: true,
|
|
underscored: true,
|
|
indexes: [
|
|
{ fields: ['is_premium'] },
|
|
{ fields: ['is_training'] },
|
|
{ fields: ['is_public'] },
|
|
],
|
|
});
|
|
|
|
module.exports = Subject;
|