-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from andela/ft-user-can-follow-166816111
#166816111 User follow another user
- Loading branch information
Showing
9 changed files
with
738 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.createTable('Follows', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
userId: { | ||
type: Sequelize.INTEGER, | ||
required: true, | ||
allowNull: false, | ||
references: { | ||
model: 'Users', | ||
key: 'id', | ||
as: 'userFollowers' | ||
} | ||
}, | ||
friendUserId: { | ||
type: Sequelize.INTEGER, | ||
references: { | ||
model: 'Users', | ||
key: 'id', | ||
as: 'Follow' | ||
} | ||
}, | ||
isFollowing: { | ||
type: Sequelize.BOOLEAN, | ||
allowNull: false, | ||
defaultValue: true | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}); | ||
}, | ||
down: queryInterface => { | ||
return queryInterface.dropTable('Follows'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
export default (sequelize, DataTypes) => { | ||
const Follow = sequelize.define('Follow', { | ||
userId: { | ||
type: DataTypes.STRING, | ||
allowNull: { | ||
args: false, | ||
msg: 'Please provide a userId' | ||
}, | ||
validate: { | ||
isInt: { | ||
args: true, | ||
msg: 'Please provide a user' | ||
} | ||
} | ||
}, | ||
friendUserId: { | ||
type: DataTypes.STRING, | ||
allowNull: { | ||
args: false, | ||
msg: 'Please provide a userId' | ||
}, | ||
validate: { | ||
isInt: { | ||
args: true, | ||
msg: 'Please provide a user' | ||
} | ||
} | ||
}, | ||
isFollowing: { | ||
type: DataTypes.STRING, | ||
allowNull: false, | ||
defaultValue: true | ||
} | ||
}); | ||
Follow.associate = models => { | ||
Follow.belongsTo(models.User, { | ||
foreignKey: 'userId', | ||
as: 'userFollowers' | ||
}); | ||
|
||
Follow.belongsTo(models.User, { | ||
foreignKey: 'friendUserId', | ||
as: 'follower' | ||
}); | ||
}; | ||
|
||
return Follow; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.