Archived
1
0
Fork 0

Import DB models

This commit is contained in:
Ethanell 2020-05-29 11:59:25 +02:00
parent f0c5397b49
commit 1690e70cc1
9 changed files with 254 additions and 0 deletions

3
.gitignore vendored
View file

@ -106,3 +106,6 @@ dist
# Sequelize
migrations
config/config.json
# JetBrains
.idea

63
models/command.js Normal file
View file

@ -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;
};

22
models/dessert.js Normal file
View file

@ -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;
};

31
models/dish.js Normal file
View file

@ -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;
};

22
models/drink.js Normal file
View file

@ -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;
};

23
models/ingredient.js Normal file
View file

@ -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;
};

24
models/sauce.js Normal file
View file

@ -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;
};

31
models/service.js Normal file
View file

@ -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;
};

35
models/user.js Normal file
View file

@ -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;
};