You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.6 KiB
70 lines
1.6 KiB
const { DataTypes } = require('sequelize');
|
|
const sequelize = require('../config/database');
|
|
|
|
|
|
const Table = sequelize.define('Table', {
|
|
id: {
|
|
type: DataTypes.INTEGER,
|
|
primaryKey: true,
|
|
autoIncrement: true
|
|
},
|
|
nom: {
|
|
type: DataTypes.STRING(100),
|
|
allowNull: false,
|
|
validate: {
|
|
notEmpty: {
|
|
msg: 'Table name cannot be empty'
|
|
},
|
|
len: {
|
|
args: [1, 100],
|
|
msg: 'Table name must be between 1 and 100 characters'
|
|
}
|
|
}
|
|
},
|
|
capacity: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: true,
|
|
defaultValue: 4,
|
|
validate: {
|
|
min: {
|
|
args: [1],
|
|
msg: 'Capacity must be at least 1'
|
|
},
|
|
max: {
|
|
args: [20],
|
|
msg: 'Capacity cannot exceed 20'
|
|
}
|
|
}
|
|
},
|
|
status: {
|
|
type: DataTypes.ENUM('available', 'occupied', 'reserved', 'maintenance'),
|
|
defaultValue: 'available',
|
|
allowNull: false
|
|
},
|
|
location: {
|
|
type: DataTypes.STRING(50),
|
|
allowNull: true,
|
|
validate: {
|
|
len: {
|
|
args: [0, 50],
|
|
msg: 'Location must be less than 50 characters'
|
|
}
|
|
}
|
|
}
|
|
}, {
|
|
tableName: 'tables',
|
|
timestamps: true,
|
|
createdAt: 'created_at',
|
|
updatedAt: 'updated_at',
|
|
indexes: [
|
|
{
|
|
fields: ['status']
|
|
},
|
|
{
|
|
fields: ['nom'],
|
|
unique: true
|
|
}
|
|
]
|
|
});
|
|
|
|
module.exports = Table;
|
|
|