bullpen/backend/sequelize/models/user.model.js

43 lines
1.0 KiB
JavaScript

const { DataTypes } = require('sequelize');
// We export a function that defines the model.
// This function will automatically receive as parameter the Sequelize connection object.
module.exports = (sequelize) => {
sequelize.define('user', {
// The following specification of the 'id' attribute could be omitted
// since it is the default.
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: DataTypes.INTEGER
},
firstName: {
type: DataTypes.STRING,
allowNull: false
},
lastName: {
type: DataTypes.STRING,
allowNull: false
},
email: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
validate: {
// We require usernames to have length of at least 3, and
// only use letters, numbers and underscores.
is: /^\w{3,}$/
}
},
password: {
type: DataTypes.STRING,
allowNull: false
}
}, {
sequelize,
modelName: 'User',
tableName: "Users",
});
};