-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(follow-users):Users should be able to follow each other [Fini…
…shes #167313409]
- Loading branch information
Noah Kalyesubula
authored and
Noah Kalyesubula
committed
Aug 15, 2019
1 parent
e01eef2
commit 922e848
Showing
11 changed files
with
321 additions
and
122 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
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,26 @@ | ||
import Joi from 'joi'; | ||
import Util from '../../helpers/util'; | ||
|
||
const util = new Util(); | ||
|
||
export default (req, res, next) => { | ||
const { userId } = req.params; | ||
|
||
const schema = { | ||
userId: Joi.number().positive().required() | ||
}; | ||
const { error } = Joi.validate({ | ||
userId | ||
}, schema); | ||
|
||
if (!error) return next(); | ||
const errorMessageFromJoi = error.details[0].message; | ||
switch (errorMessageFromJoi) { | ||
case '"userId" must be a number': | ||
util.setError(400, 'userId must be a non negative integer'); | ||
return util.send(res); | ||
default: | ||
util.setError(400, errorMessageFromJoi); | ||
return util.send(res); | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,23 +1,21 @@ | ||
'use strict'; | ||
module.exports = (sequelize, DataTypes) => { | ||
const Follow = sequelize.define('Follow', { | ||
followerEmail: DataTypes.STRING, | ||
followedUserEmail: DataTypes.STRING | ||
followerId: DataTypes.INTEGER, | ||
followedUserId: DataTypes.INTEGER | ||
}, {}); | ||
Follow.associate = function(models) { | ||
Follow.associate = ({ user }) => { | ||
// associations can be defined here | ||
// Follow.belongsTo(models.User, { | ||
// foreignKey: 'followerId', | ||
// sourceKey: 'followerId', | ||
// as: 'follower', | ||
// onDelete: 'CASCADE', | ||
// }); | ||
// Follow.belongsTo(models.User, { | ||
// foreignKey: 'followedUserId', | ||
// sourceKey: 'followedUserId', | ||
// as: 'followedUser', | ||
// onDelete: 'CASCADE', | ||
// }); | ||
Follow.belongsTo(user, { | ||
foreignKey: 'followerId', | ||
onDelete: 'CASCADE', | ||
as: 'authorDetails' | ||
}); | ||
Follow.belongsTo(user, { | ||
foreignKey: 'followedUserId', | ||
onDelete: 'CASCADE', | ||
as: 'followerDetails' | ||
}); | ||
}; | ||
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.