-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
224 additions
and
31 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,29 @@ | ||
import jwt from 'jsonwebtoken'; | ||
import dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
/** | ||
* this class returns the current user | ||
*/ | ||
class LoggedInUser { | ||
/** | ||
* @author frank harerimana | ||
* @param {*} token | ||
*/ | ||
constructor(token) { | ||
this.token = token; | ||
} | ||
|
||
/** | ||
* @returns {*} userId | ||
*/ | ||
async user() { | ||
const bearer = this.token.split(' '); | ||
const bearerToken = bearer[1]; | ||
const result = bearerToken; | ||
const response = await jwt.verify(result, process.env.SECRETKEY); | ||
return response; | ||
} | ||
} | ||
|
||
export default LoggedInUser; |
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,28 @@ | ||
|
||
|
||
module.exports = { | ||
up: (queryInterface, Sequelize) => queryInterface.createTable('followings', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
followee: { | ||
type: Sequelize.INTEGER | ||
}, | ||
follower: { | ||
type: Sequelize.INTEGER | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}), | ||
// eslint-disable-next-line no-unused-vars | ||
down: (queryInterface, Sequelize) => queryInterface.dropTable('followings') | ||
}; |
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,18 @@ | ||
|
||
|
||
const followingModel = (sequelize, DataTypes) => { | ||
const Following = sequelize.define('following', { | ||
followee: { type: DataTypes.INTEGER, allowNull: false }, | ||
follower: { type: DataTypes.INTEGER, allowNull: false } | ||
}); | ||
Following.newRecord = (followee, follower) => Following.create({ followee, follower }); | ||
Following.finder = (followee, follower) => Following.findOne({ where: { followee, follower } }); | ||
Following.followings = followee => Following.count({ where: { followee } }); | ||
Following.DeleteRe = (followee, follower) => Following.destroy({ where: { followee, follower } }); | ||
Following.followers = follower => Following.count({ where: { follower } }); | ||
// Following.associate = function (models) { | ||
// // associations can be defined here | ||
// }; | ||
return Following; | ||
}; | ||
export default followingModel; |
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,8 @@ | ||
import express from 'express'; | ||
import user from '../../controllers/user'; | ||
|
||
const router = express.Router(); | ||
|
||
router.post('/:username/follow', user.follow); | ||
|
||
export default router; |
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,10 +1,12 @@ | ||
import express from 'express'; | ||
import articleRoutes from './api/articles'; | ||
import authentication from './api/authentication'; | ||
import follwingRoute from './api/following'; | ||
|
||
const app = express(); | ||
|
||
app.use('/auth', authentication); | ||
app.use('/articles', articleRoutes); | ||
app.use('/profiles', follwingRoute); | ||
|
||
export default app; |
Oops, something went wrong.