Files
bowlingManager/backend/models/Event.js
T
2025-04-24 13:48:53 +09:00

101 lines
1.9 KiB
JavaScript

const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');
const Event = sequelize.define('Event', {
id: {
type: DataTypes.INTEGER.UNSIGNED,
primaryKey: true,
autoIncrement: true
},
clubId: {
type: DataTypes.INTEGER.UNSIGNED,
allowNull: false,
references: {
model: 'Clubs',
key: 'id'
}
},
title: {
type: DataTypes.STRING,
allowNull: false
},
description: {
type: DataTypes.TEXT,
allowNull: true
},
eventType: {
type: DataTypes.ENUM('정기전', '번개', '연습', '교류전', '이벤트', '기타'),
allowNull: false,
defaultValue: '정기전'
},
startDate: {
type: DataTypes.DATE,
allowNull: false
},
endDate: {
type: DataTypes.DATE,
allowNull: true
},
location: {
type: DataTypes.STRING,
allowNull: true
},
gameCount: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 3
},
participantFee: {
type: DataTypes.DECIMAL(10, 2),
allowNull: false,
defaultValue: 0
},
maxParticipants: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0
},
registrationDeadline: {
type: DataTypes.DATE,
allowNull: true
},
participantCount: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0
},
status: {
type: DataTypes.ENUM('준비', '활성', '완료', '취소', '삭제'),
allowNull: false,
defaultValue: '활성'
},
createdAt: {
type: DataTypes.DATE,
allowNull: false
},
updatedAt: {
type: DataTypes.DATE,
allowNull: false
}
}, {
tableName: 'Events',
timestamps: true
});
// 관계 설정
Event.associate = (models) => {
Event.belongsTo(models.Club, {
foreignKey: 'clubId'
});
Event.hasMany(models.EventParticipant, {
foreignKey: 'eventId'
});
Event.hasMany(models.EventScore, {
foreignKey: 'eventId'
});
};
module.exports = Event;