add models
This commit is contained in:
parent
4287ac8026
commit
e5c24e7dee
4 changed files with 148 additions and 0 deletions
23
backend/src/models/Collection.js
Normal file
23
backend/src/models/Collection.js
Normal 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'
|
||||||
|
}
|
||||||
|
});
|
42
backend/src/models/Rating.js
Normal file
42
backend/src/models/Rating.js
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
39
backend/src/models/User.js
Normal file
39
backend/src/models/User.js
Normal 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);
|
||||||
|
};
|
44
backend/src/models/Whisky.js
Normal file
44
backend/src/models/Whisky.js
Normal 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
|
||||||
|
}
|
||||||
|
});
|
Loading…
Reference in a new issue