From d845959d39115557abb23d77a42c4e92ea8fc329 Mon Sep 17 00:00:00 2001 From: Sergey Yarkov Date: Wed, 10 Jun 2020 21:59:43 +0300 Subject: [PATCH] added fields description & deadline to todo --- server/models/Todo.js | 2 ++ server/resolvers/todoResolvers.js | 6 ++++-- server/typeDefs/mutation.js | 6 +++--- server/typeDefs/types/todoType.js | 2 ++ 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/server/models/Todo.js b/server/models/Todo.js index ebdf775..7be3e8e 100644 --- a/server/models/Todo.js +++ b/server/models/Todo.js @@ -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, }) diff --git a/server/resolvers/todoResolvers.js b/server/resolvers/todoResolvers.js index fccc228..61d7d21 100644 --- a/server/resolvers/todoResolvers.js +++ b/server/resolvers/todoResolvers.js @@ -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), diff --git a/server/typeDefs/mutation.js b/server/typeDefs/mutation.js index ec16da6..bf93cd6 100644 --- a/server/typeDefs/mutation.js +++ b/server/typeDefs/mutation.js @@ -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 } diff --git a/server/typeDefs/types/todoType.js b/server/typeDefs/types/todoType.js index 3f9535c..61d6706 100644 --- a/server/typeDefs/types/todoType.js +++ b/server/typeDefs/types/todoType.js @@ -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 }