added fields description & deadline to todo

This commit is contained in:
Sergey Yarkov 2020-06-10 21:59:43 +03:00
parent 5b1db0b395
commit d845959d39
4 changed files with 11 additions and 5 deletions

View File

@ -2,9 +2,11 @@ const mongoose = require('mongoose')
const todoSchema = mongoose.Schema({
title: String,
description: String,
createdAt: String,
updatedAt: String,
status: String,
deadline: String,
categoryId: String,
})

View File

@ -6,12 +6,14 @@ const todoResolvers = {
todo: (_, { id }) => Todo.findById(id),
},
Mutation: {
createTodo: (_, { title, categoryId }) => {
createTodo: (_, { title, description, deadline, categoryId }) => {
const todo = new Todo({
title,
description,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
status: 'open',
deadline,
categoryId,
})
return todo.save()
@ -20,7 +22,7 @@ const todoResolvers = {
const deletedTodo = await Todo.findByIdAndRemove(id)
return deletedTodo
},
updateTodo: (_, { id, title, status, categoryId }) => Todo.findByIdAndUpdate(id, { $set: { title, updatedAt: new Date().toISOString(), status, categoryId } }, { new: true }),
updateTodo: (_, { id, title, description, status, deadline, categoryId }) => Todo.findByIdAndUpdate(id, { $set: { title, description, updatedAt: new Date().toISOString(), status, deadline, categoryId } }, { new: true }),
},
Todo: {
category: ({ categoryId }) => Category.findById(categoryId),

View File

@ -3,12 +3,12 @@ const { gql } = require('apollo-server')
const mutation = gql`
type Mutation {
# Todo mutations
createTodo(title: String!, categoryId: String!): Todo
createTodo(title: String! description: String! deadline: String! categoryId: String!): Todo
deleteTodo(id: ID!): Todo
updateTodo(id: ID! title: String! status: String! categoryId: String!): Todo
updateTodo(id: ID! title: String! description: String! status: String! deadline: String! categoryId: String!): Todo
# Category mutations
createCategory(title: String!, description: String!): Category
createCategory(title: String! description: String!): Category
deleteCategory(id: ID!): Category
updateCategory(id: ID! title: String! description: String!): Category
}

View File

@ -4,9 +4,11 @@ const todoType = gql`
type Todo {
id: ID
title: String
description: String
createdAt: String
updatedAt: String
status: String
deadline: String
categoryId: String
category: Category
}