diff --git a/.gitignore b/.gitignore index 8ca3e76..488747a 100644 --- a/.gitignore +++ b/.gitignore @@ -106,3 +106,6 @@ dist # Sequelize migrations config/config.json + +# JetBrains +.idea diff --git a/models/command.js b/models/command.js new file mode 100644 index 0000000..ea25b53 --- /dev/null +++ b/models/command.js @@ -0,0 +1,63 @@ +"use strict"; +module.exports = (sequelize, DataTypes) => { + const Command = sequelize.define('Command', { + number: { + type: DataTypes.INTEGER, + allowNull: false + }, + price: { + type: DataTypes.FLOAT, + allowNull: false + }, + date: { + type: DataTypes.DATEONLY, + defaultValue: DataTypes.NOW, + allowNull: false + }, + take: { + type: DataTypes.DATE, + defaultValue: DataTypes.NOW, + allowNull: false + }, + done: { + type: DataTypes.DATE + }, + give: { + type: DataTypes.DATE + }, + WIP: { + type: DataTypes.BOOLEAN, + defaultValue: false, + allowNull: false + }, + error: { + type: DataTypes.BOOLEAN, + defaultValue: false, + allowNull: false + } + }, { + tableName: "Commands" + }); + Command.associate = function(models) { + // associations can be defined here + Command.belongsTo(models.User, { + as: "command" + }); + Command.belongsTo(models.User, { + as: "pcCommand" + }); + Command.belongsTo(models.User, { + as: "sandwichCommand" + }); + Command.belongsTo(models.Dish); + Command.belongsToMany(models.Ingredient, { + through: "CommandsIngredients" + }); + Command.belongsToMany(models.Sauce, { + through: "CommandsSauces" + }); + Command.belongsTo(models.Drink); + Command.belongsTo(models.Dessert); + }; + return Command; +}; diff --git a/models/dessert.js b/models/dessert.js new file mode 100644 index 0000000..112e68f --- /dev/null +++ b/models/dessert.js @@ -0,0 +1,22 @@ +'use strict'; +module.exports = (sequelize, DataTypes) => { + const Dessert = sequelize.define('Dessert', { + name: { + type: DataTypes.STRING, + allowNull: false, + unique: true + }, + price: { + type: DataTypes.FLOAT, + defaultValue: 0, + allowNull: false + } + }, { + tableName: "Desserts" + }); + Dessert.associate = function(models) { + // associations can be defined here + Dessert.hasMany(models.Command); + }; + return Dessert; +}; \ No newline at end of file diff --git a/models/dish.js b/models/dish.js new file mode 100644 index 0000000..2e5ecb3 --- /dev/null +++ b/models/dish.js @@ -0,0 +1,31 @@ +"use strict"; +module.exports = (sequelize, DataTypes) => { + const Dish = sequelize.define('Dish', { + name: { + type: DataTypes.STRING, + allowNull: false, + unique: true + }, + price: { + type: DataTypes.FLOAT, + defaultValue: 0, + allowNull: false + }, + avoidIngredients: { + type: DataTypes.BOOLEAN, + defaultValue: false, + allowNull: false + }, + avoidSauces: { + type: DataTypes.BOOLEAN, + defaultValue: false, + allowNull: false + } + }, { + tableName: "dishes" + }); + Dish.associate = function(models) { + Dish.hasMany(models.Command); + }; + return Dish; +}; diff --git a/models/drink.js b/models/drink.js new file mode 100644 index 0000000..c934a62 --- /dev/null +++ b/models/drink.js @@ -0,0 +1,22 @@ +"use strict"; +module.exports = (sequelize, DataTypes) => { + const Drink = sequelize.define('Drink', { + name: { + type:DataTypes.STRING, + allowNull: false, + unique: true + }, + price: { + type: DataTypes.FLOAT, + defaultValue: 0, + allowNull: false + } + }, { + tableName: "Drinks" + }); + Drink.associate = function(models) { + // associations can be defined here + Drink.hasMany(models.Command); + }; + return Drink; +}; diff --git a/models/ingredient.js b/models/ingredient.js new file mode 100644 index 0000000..80caa15 --- /dev/null +++ b/models/ingredient.js @@ -0,0 +1,23 @@ +"use strict"; +module.exports = (sequelize, DataTypes) => { + const Ingredient = sequelize.define('Ingredient', { + name: { + type: DataTypes.STRING, + allowNull: false, + unique: true + }, + price: { + type: DataTypes.FLOAT, + defaultValue: 0, + allowNull: false + } + }, { + tableName: "Ingredients" + }); + Ingredient.associate = function(models) { + Ingredient.belongsToMany(models.Command, { + through: "CommandsIngredients" + }); + }; + return Ingredient; +}; diff --git a/models/sauce.js b/models/sauce.js new file mode 100644 index 0000000..c9e312b --- /dev/null +++ b/models/sauce.js @@ -0,0 +1,24 @@ +"use strict"; +module.exports = (sequelize, DataTypes) => { + const Sauce = sequelize.define('Sauce', { + name: { + type: DataTypes.STRING, + allowNull: false, + unique: true + }, + price: { + type: DataTypes.FLOAT, + defaultValue: 0, + allowNull: false + } + }, { + tableName: "Sauces" + }); + Sauce.associate = function(models) { + // associations can be defined here + Sauce.belongsToMany(models.Command, { + through: "CommandsSauces" + }); + }; + return Sauce; +}; diff --git a/models/service.js b/models/service.js new file mode 100644 index 0000000..bb9d5de --- /dev/null +++ b/models/service.js @@ -0,0 +1,31 @@ +'use strict'; +module.exports = (sequelize, DataTypes) => { + const Service = sequelize.define('Service', { + date: { + type: DataTypes.DATEONLY, + defaultValue: DataTypes.NOW, + primaryKey: true + } + }, { + tableName: "Services" + }); + Service.associate = function(models) { + // associations can be defined here + Service.hasOne(models.User, { + as: "sandwich1" + }); + Service.hasOne(models.User, { + as: "sandwich2" + }); + Service.hasOne(models.User, { + as: "sandwich3" + }); + Service.hasOne(models.User, { + as: "commi1" + }); + Service.hasOne(models.User, { + as: "commi2" + }) + }; + return Service; +}; \ No newline at end of file diff --git a/models/user.js b/models/user.js new file mode 100644 index 0000000..4e39b0d --- /dev/null +++ b/models/user.js @@ -0,0 +1,35 @@ +"use strict"; +module.exports = (sequelize, DataTypes) => { + const User = sequelize.define('User', { + username: { + type: DataTypes.STRING, + allowNull: false + }, + passwordHash: { + type: DataTypes.STRING + }, + firstName: { + type: DataTypes.STRING, + allowNull: false + }, + lastName: { + type: DataTypes.STRING, + allowNull: false + } + }, { + tableName: "Users" + }); + User.associate = function(models) { + // associations can be defined here + User.hasMany(models.Command, { + as: "client" + }); + User.hasMany(models.Command, { + as: "pc" + }); + User.hasMany(models.Command, { + as: "sandwich" + }) + }; + return User; +};