Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

166840939 like specific comment #38

Merged
merged 1 commit into from
Aug 14, 2019

Conversation

olorunwalawrence
Copy link
Contributor

What does this PR do?

Like a specific comment

Description of the task to be completed

  • create like functionality
  • create like route and middleware

How to manually test this PR

  • clone the repo
  • on your terminal, run 166840939-like-specific-comment
  • create a user model and migration
  • on your terminal, run npm install to install dependencies
  • on your terminal, run npm run start:dev to start the application.

What is the story identity?

#166840919

@@ -0,0 +1,17 @@
import express from 'express';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

@@ -0,0 +1,44 @@
import checkProp from '../helpers/utils';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

@@ -0,0 +1,27 @@
import responseGenerator from './responseGenerator';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

return CommentLikes;
};

export default commentLikes;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

return Comments;
};

export default comments;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

@@ -0,0 +1,46 @@
module.exports = {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'module' is not defined no-undef

@@ -0,0 +1,46 @@
module.exports = {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'module' is not defined no-undef

@@ -0,0 +1,25 @@
import models from '../database/models/index';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

Copy link
Contributor

@timi-codes timi-codes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Job @olorunwalawrence, Please document your endpoints and use the Joi validation middleware instead of the check props as we discussed

* @param {String} type The list of properties to be searched for
* @returns {object} An object that contains a valid (bool) and invalidMessages (array) property
*/
checkProps(obj, params, type) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use Joi validation middleware for this.

@@ -0,0 +1,46 @@
module.exports = {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'module' is not defined no-undef

@@ -0,0 +1,46 @@
module.exports = {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'module' is not defined no-undef

@@ -0,0 +1,73 @@
/* eslint-disable require-jsdoc */
import models from '../database/models';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

return CommentLike;
};

export default commentLike;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

@olorunwalawrence olorunwalawrence force-pushed the 166840939-like-specific-comment branch 3 times, most recently from 8d66e74 to 4e6a12c Compare July 31, 2019 14:03
Copy link
Contributor

@Onyimatics Onyimatics left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job @olorunwalawrence. Please kindly resolve the conflicts on this PR and also squash your commits. Thank you

Copy link
Contributor

@tolumide-ng tolumide-ng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job so far @olorunwalawrence , Please check my comments and make the necessary changes. I would also love to know your opinion on the possibility of the author of a comment liking their own comment

}

// This block creates the toggle effect of liking and unliking
return model.update({ liked: !liked }, { where: likeData }).then(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, this should be implemented as remove since we would not be having a dislike feature on the project.
The first request to this api adds the like for such comment while the second removes the likes

@@ -0,0 +1,46 @@
module.exports = {
up: (queryInterface, Sequelize) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be two create-comment migration files here. could you remove one?

module.exports = {
up: (queryInterface, Sequelize) =>
queryInterface.createTable(
'CommentLike',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a migration file, so the tableName should be plural. Sequelize should normally do this by default. Please make the changes here

as: 'userId'
}
},
liked: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A user should only be able to like a comment and NOT unlike. Hence if the user has liked the comment before, they should be able to remove such like on the comment. I think there is no need or this column in that case.

This table should only reflect list of people that have liked a specific article and when someone removes there like? then the row should be removed from this table

@@ -0,0 +1,49 @@
const comments = (sequelize, DataTypes) => {
const Comments = sequelize.define(
'Comments',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Model should have singular name to maintain consistency within the project, please check here https://github.com/andela/ah-kifaru-backend/blob/develop/src/database/models/follower.js

Hence, when creating a comment table use: =>cmd to create table comment<=

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been solved on the comment branch

);
});

it('sshould unlike a comment for an article', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should

expect(res.body.data).to.be.equal('Comment liked');
});

it('should throw error if article id is invalid', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test should not depend on the previous, please create a separate user or this test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kindly check below to see the user creating the like

);
});

it('sshould unlike a comment for an article', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current project does not support features like unlike, users should only be able to remove there previous likes. Please amend this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but this branch support feature that makes an authenticated user to like or unlike a specific comment. the PT board story says "Users should be able to like a specific comment".
if I have liked a specific comment and then later I am not interested in such comment anymore I should unlike it.

const userId = req.currentUser.id;

const likeData = { commentId, userId };
return liker(CommentLike, res, likeData, 'Comment');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job @olorunwalawrence , is there a reason why you abstracted the liker method?

const { liker } = commentHelpers;

const likeController = async (req, res) => {
const { commentId: id } = req.params;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be no check for the aspiring liker being the author of the comment. This means the author of a comment can like their own comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is cool, there is no need to check for any aspiring liker because we are not stating any statistics base on the number of users that like specific comment, any user can like any comment

@@ -0,0 +1,46 @@
module.exports = {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'module' is not defined no-undef

@olorunwalawrence olorunwalawrence force-pushed the 166840939-like-specific-comment branch 2 times, most recently from 0a7c5d4 to 15d3797 Compare August 8, 2019 08:18
@@ -0,0 +1,44 @@
export default (sequelize, DataTypes) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

@@ -0,0 +1,59 @@
module.exports = {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'module' is not defined no-undef

- create like functionality
- create middleware for like
- create route for like

[Delivers #166840939]
@olorunwalawrence olorunwalawrence merged commit 04082cc into develop Aug 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants