Skip to content

Commit

Permalink
final user-actions code
Browse files Browse the repository at this point in the history
  • Loading branch information
ascott1 committed Apr 20, 2019
1 parent 7b22619 commit 1b994e6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions solutions/06-User-Actions/resolvers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { GraphQLDateTime } = require('graphql-iso-date');
module.exports = {
Query,
Mutation,
// Note,
// User,
Note,
User,
DateTime: GraphQLDateTime
};
4 changes: 4 additions & 0 deletions solutions/06-User-Actions/resolvers/mutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ module.exports = {
let noteCheck = await models.Note.findById(id);
const hasUser = noteCheck.favoritedBy.indexOf(user.id);

// if the user exists in the list
//pull them from the list and reduce the favoriteCount by 1
if (hasUser >= 0) {
return await models.Note.findByIdAndUpdate(
id,
Expand All @@ -101,6 +103,8 @@ module.exports = {
}
);
} else {
// if the user doesn't exists in the list
// add them to the list and increment the favoriteCount by 1
return await models.Note.findByIdAndUpdate(
id,
{
Expand Down

0 comments on commit 1b994e6

Please sign in to comment.