From e5c24e7deeac35d53afbb965b9304f84d46eee3b Mon Sep 17 00:00:00 2001 From: Kyle Belanger Date: Wed, 5 Mar 2025 12:38:41 -0500 Subject: [PATCH] add models --- backend/src/models/Collection.js | 23 +++++++++++++++++ backend/src/models/Rating.js | 42 ++++++++++++++++++++++++++++++ backend/src/models/User.js | 39 ++++++++++++++++++++++++++++ backend/src/models/Whisky.js | 44 ++++++++++++++++++++++++++++++++ 4 files changed, 148 insertions(+) create mode 100644 backend/src/models/Collection.js create mode 100644 backend/src/models/Rating.js create mode 100644 backend/src/models/User.js create mode 100644 backend/src/models/Whisky.js diff --git a/backend/src/models/Collection.js b/backend/src/models/Collection.js new file mode 100644 index 0000000..b2cb0cd --- /dev/null +++ b/backend/src/models/Collection.js @@ -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' + } +}); \ No newline at end of file diff --git a/backend/src/models/Rating.js b/backend/src/models/Rating.js new file mode 100644 index 0000000..9c8b403 --- /dev/null +++ b/backend/src/models/Rating.js @@ -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 + } + } +}); \ No newline at end of file diff --git a/backend/src/models/User.js b/backend/src/models/User.js new file mode 100644 index 0000000..b39ae1a --- /dev/null +++ b/backend/src/models/User.js @@ -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); +}; \ No newline at end of file diff --git a/backend/src/models/Whisky.js b/backend/src/models/Whisky.js new file mode 100644 index 0000000..3f0cd19 --- /dev/null +++ b/backend/src/models/Whisky.js @@ -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 + } +}); \ No newline at end of file