mirror of
https://github.com/sergeyyarkov/todo-app.git
synced 2026-10-11 10:29:14 +03:00
added fields description & deadline to todo
This commit is contained in:
parent
5b1db0b395
commit
d845959d39
@ -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,
|
||||
})
|
||||
|
||||
|
||||
@ -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),
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user