create-ex-den-kit
Version:
Create exam projects with Ex-Den-Kit
47 lines (43 loc) • 911 B
JavaScript
import { DataTypes } from 'sequelize';
import sequelize from '../config/database.js';
import User from './User.js';
const Entry = sequelize.define('Entry', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
userId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: User,
key: 'id',
},
},
type: {
type: DataTypes.STRING,
allowNull: false,
},
status: {
type: DataTypes.STRING,
defaultValue: 'new',
},
data: {
type: DataTypes.JSONB,
allowNull: false,
defaultValue: {},
},
rejectionReason: {
type: DataTypes.TEXT,
allowNull: true,
},
isArchived: {
type: DataTypes.BOOLEAN,
defaultValue: false,
},
});
// Связи
Entry.belongsTo(User, { foreignKey: 'userId', as: 'user' });
User.hasMany(Entry, { foreignKey: 'userId', as: 'entries' });
export default Entry;