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({ const todoSchema = mongoose.Schema({
title: String, title: String,
description: String,
createdAt: String, createdAt: String,
updatedAt: String, updatedAt: String,
status: String, status: String,
deadline: String,
categoryId: String, categoryId: String,
}) })

View File

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

View File

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

View File

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