add models

This commit is contained in:
Kyle Belanger 2025-03-05 12:38:41 -05:00
parent 4287ac8026
commit e5c24e7dee
4 changed files with 148 additions and 0 deletions

View file

@ -0,0 +1,23 @@
const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/db');
const Collection = sequelize.define('Collection', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
purchaseDate: {
type: DataTypes.DATE
},
purchasePrice: {
type: DataTypes.FLOAT
},
notes: {
type: DataTypes.TEXT
},
bottleStatus: {
type: DataTypes.ENUM('sealed', 'opened', 'empty'),
defaultValue: 'sealed'
}
});

View file

@ -0,0 +1,42 @@
const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/db');
const Rating = sequelize.define('Rating', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
score: {
type: DataTypes.INTEGER,
allowNull: false,
validate: {
min: 0,
max: 100
}
},
notes: {
type: DataTypes.TEXT
},
nose: {
type: DataTypes.INTEGER,
validate: {
min: 0,
max: 10
}
},
taste: {
type: DataTypes.INTEGER,
validate: {
min: 0,
max: 10
}
},
finish: {
type: DataTypes.INTEGER,
validate: {
min: 0,
max: 10
}
}
});

View file

@ -0,0 +1,39 @@
const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/db');
const bcrypt = require('bcrypt');
const User = sequelize.define('User', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
username: {
type: DataTypes.STRING,
allowNull: false,
unique: true
},
email: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
validate: {
isEmail: true
}
},
password: {
type: DataTypes.STRING,
allowNull: false
}
}, {
hooks: {
beforeCreate: async (user) => {
const salt = await bcrypt.genSalt(10);
user.password = await bcrypt.hash(user.password, salt);
}
}
});
User.prototype.validatePassword = async function(password) {
return await bcrypt.compare(password, this.password);
};

View file

@ -0,0 +1,44 @@
const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/db');
const Whiskey = sequelize.define('Whiskey', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
name: {
type: DataTypes.STRING,
allowNull: false
},
distillery: {
type: DataTypes.STRING,
allowNull: false
},
type: {
type: DataTypes.STRING,
allowNull: false
},
country: {
type: DataTypes.STRING,
allowNull: false
},
region: {
type: DataTypes.STRING
},
age: {
type: DataTypes.INTEGER
},
abv: {
type: DataTypes.FLOAT
},
price: {
type: DataTypes.FLOAT
},
description: {
type: DataTypes.TEXT
},
imageUrl: {
type: DataTypes.STRING
}
});