bullpen/backend/models/bullpenSession.model.js

36 lines
872 B
JavaScript

'use strict';
const { Model } = require('sequelize');
module.exports = (sequelize, DataTypes) => {
class BullpenSession extends Model {
/**
* Helper method for defining associations.
* This method is not a part of Sequelize lifecycle.
* The `models/index` file will call this method automatically.
*/
static associate(models) {
BullpenSession.hasMany(models.Pitch, {
foreignKey: 'bullpenSessionId',
as: 'pitches',
});
BullpenSession.belongsTo(models.User, {
foreignKey: "pitcherId"
});
}
}
BullpenSession.init({
startedAt: {
type: DataTypes.DATE,
allowNull: false,
},
finishedAt: {
type: DataTypes.DATE,
allowNull: false,
}
}, {
sequelize,
modelName: 'BullpenSession',
tableName: 'BullpenSessions'
});
return BullpenSession;
};