Last active
January 13, 2017 15:16
-
-
Save HERRKIN/101e0a2f3aaa545838f3d53054de5724 to your computer and use it in GitHub Desktop.
addTodo resolver
This file contains hidden or 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
import {Todos} from '../../../../lib/Collections' | |
export default function (root, options, context) { | |
// it wont let anonymous users create a todo | |
if (!context.userId) { | |
throw new Error('Unknown User (not logged in)') | |
} | |
// pack the todo adding the userId as the owner id | |
const newTodo = { | |
text: options.text, | |
completed: false, | |
owner: context.userId | |
} | |
const TodoId = Todos.insert(newTodo) | |
if (TodoId) { | |
const todo = {_id: TodoId, ...newTodo} | |
// log the todo so we know the todo was inserted correctly via the console | |
console.log(todo) | |
return todo // return the todo | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment