-
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.
feature(follow-user):user follow another user
To allow a user follow another user To create a migration and model file for follow table To write test for follow function To get a user followers [#166816111]
- Loading branch information
1 parent
3a9ef89
commit db79e67
Showing
9 changed files
with
824 additions
and
67 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.