Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. import {Todos} from '../../../../lib/Collections'
  2. export default function (root, options, context) {
  3. console.log(options)
  4. if (!context.userId) {
  5. throw new Error('Unknown User (not logged in)')
  6. }
  7. // validate the todo belongs to the user
  8. const todo = Todos.findOne({$and: [{_id: options.todoId}, {owner: context.userId}]})
  9. // if not found throw Error
  10. if (!todo) {
  11. throw new Error('Todo not found on the user')
  12. }
  13.  
  14. const todoId = Todos.update(todo._id, {$set: {completed: !todo.completed}})
  15. if (todoId) {
  16. todo.completed = !todo.completed
  17. console.log(todo)
  18. return todo // return the todo
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement