Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions server/getdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,4 @@ async function fecthData(){
console.log(error)
}
}

fecthData();

module.exports = fecthData;
fecthData()
17 changes: 17 additions & 0 deletions server/helper/bcrypt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const bcrypt = require("bcryptjs");

const hashPassword = (password) => {
const salt = bcrypt.genSaltSync(10);
const hash = bcrypt.hashSync(password, salt);
return hash;
}
const comparePassword = (pwd, hashedpassword) => {
return bcrypt.compareSync(pwd, hashedpassword);
}



module.exports = {
hashPassword,
comparePassword
};
3 changes: 0 additions & 3 deletions server/migrations/20231113131418-create-team.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ module.exports = {
failed_to_score: {
type: Sequelize.INTEGER
},
goal_againts: {
type: Sequelize.INTEGER
},
authorId: {
type: Sequelize.INTEGER,
references: {
Expand Down
113 changes: 106 additions & 7 deletions server/models/team.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,117 @@ module.exports = (sequelize, DataTypes) => {
*/
static associate(models) {
// define association here
Team.belongsTo(models.User, {foreignKey: "authorId"})
}
}
Team.init({
name: DataTypes.STRING,
win: DataTypes.INTEGER,
draw: DataTypes.INTEGER,
lose: DataTypes.INTEGER,
win: {
type: DataTypes.INTEGER,
allowNull: false,
validate: {
notEmpty: {
msg: "Win is required"
},
notNull: {
msg: "Win is required"
},
isNumeric:{
msg: "Win must be a number"
}
}
},
draw: {
type: DataTypes.INTEGER,
allowNull: false,
validate: {
notEmpty: {
msg: "Draw is required"
},
notNull: {
msg: "Draw is required"
},
isNumeric:{
msg: "Draw must be a number"
}
}
},
lose: {
type: DataTypes.INTEGER,
allowNull: false,
validate: {
notEmpty: {
msg: "Lose is required"
},
notNull: {
msg: "Lose is required"
},
isNumeric:{
msg: "Lose must be a number"
}
}
},
logo: DataTypes.STRING,
clean_sheet: DataTypes.INTEGER,
goal_average: DataTypes.INTEGER,
failed_to_score: DataTypes.INTEGER,
authorId: DataTypes.INTEGER
clean_sheet: {
type: DataTypes.INTEGER,
allowNull: false,
validate: {
notEmpty: {
msg: "Clean Sheet is required"
},
notNull: {
msg: "Clean Sheet is required"
},
isNumeric:{
msg: "Clean Sheet must be a number"
}
}
},
goal_average: {
type: DataTypes.INTEGER,
allowNull: false,
validate: {
notEmpty: {
msg: "Average Goal is required"
},
notNull: {
msg: "Average Goal is required"
},
isNumeric:{
msg: "Average Goal must be a number"
}
}
},
failed_to_score: {
type: DataTypes.INTEGER,
allowNull: false,
validate: {
notEmpty: {
msg: "Fail to Score is required"
},
notNull: {
msg: "Fail to Score is required"
},
isNumeric:{
msg: "Fail to Score must be a number"
}
}
},
authorId: {
type: DataTypes.INTEGER,
allowNull: false,
validate: {
notEmpty: {
msg: "Author Id is required"
},
notNull: {
msg: "Author Id is required"
},
isNumeric:{
msg: "Author Id must be a number"
}
}
}
}, {
sequelize,
modelName: 'Team',
Expand Down
34 changes: 32 additions & 2 deletions server/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const {
Model
} = require('sequelize');
const { hashPassword } = require('../helper/bcrypt');
module.exports = (sequelize, DataTypes) => {
class User extends Model {
/**
Expand All @@ -11,15 +12,44 @@ module.exports = (sequelize, DataTypes) => {
*/
static associate(models) {
// define association here
User.hasMany(models.Team, {foreignKey: "authorId"})
}
}
User.init({
name: DataTypes.STRING,
email: DataTypes.STRING,
password: DataTypes.STRING
email: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
validate: {
notEmpty: {
msg: "Email is required"
},
notNull:{
msg: "Email is required"
}
}
},
password: {
type: DataTypes.STRING,
allowNull: false,
validate: {
notEmpty: {
msg: "Password is required"
},
notNull:{
msg: "Password is required"
}
}
}
}, {
sequelize,
modelName: 'User',
});

User.beforeCreate((el) => {
el.password = hashPassword(el.password)
})

return User;
};
Loading