UNPKG

create-exam-project

Version:

Create exam projects with React + Express + PostgreSQL in seconds

57 lines (53 loc) 1.12 kB
const { DataTypes } = require('sequelize'); const sequelize = require('../config/database'); const User = require('./User'); const Application = sequelize.define('Application', { id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true }, userId: { type: DataTypes.INTEGER, allowNull: false, references: { model: User, key: 'id' } }, status: { type: DataTypes.ENUM('new', 'in_progress', 'completed', 'cancelled'), defaultValue: 'new' }, type: { type: DataTypes.STRING, allowNull: false }, data: { type: DataTypes.JSONB, allowNull: false, defaultValue: {} }, adminComment: { type: DataTypes.TEXT, allowNull: true }, rating: { type: DataTypes.INTEGER, allowNull: true, validate: { min: 1, max: 5 } }, review: { type: DataTypes.TEXT, allowNull: true } }, { timestamps: true }); // Associations Application.belongsTo(User, { foreignKey: 'userId', as: 'user' }); User.hasMany(Application, { foreignKey: 'userId', as: 'applications' }); module.exports = Application;