mirror of
https://github.com/sergeyyarkov/todo-app.git
synced 2026-10-11 18:39:09 +03:00
upd
This commit is contained in:
parent
a7a895648f
commit
dcf7f71580
@ -2,7 +2,6 @@ const mongoose = require('mongoose')
|
||||
|
||||
const categorySchema = new mongoose.Schema({
|
||||
title: String,
|
||||
description: String,
|
||||
createdAt: String,
|
||||
updatedAt: String,
|
||||
})
|
||||
|
||||
@ -5,7 +5,6 @@ const todoSchema = mongoose.Schema({
|
||||
description: String,
|
||||
createdAt: String,
|
||||
updatedAt: String,
|
||||
status: String,
|
||||
deadline: String,
|
||||
categoryId: String,
|
||||
})
|
||||
|
||||
@ -6,10 +6,9 @@ const categoryResolvers = {
|
||||
category: (_, { id }) => Category.findById(id),
|
||||
},
|
||||
Mutation: {
|
||||
createCategory: (_, { title, description }) => {
|
||||
createCategory: (_, { title }) => {
|
||||
const category = new Category({
|
||||
title,
|
||||
description,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
})
|
||||
@ -19,7 +18,7 @@ const categoryResolvers = {
|
||||
const deletedCategory = await Category.findByIdAndRemove(id)
|
||||
return deletedCategory
|
||||
},
|
||||
updateCategory: (_, { id, title, description }) => Category.findByIdAndUpdate(id, { $set: { title, description, updatedAt: new Date().toISOString() } }, { new: true })
|
||||
updateCategory: (_, { id, title }) => Category.findByIdAndUpdate(id, { $set: { title, updatedAt: new Date().toISOString() } }, { new: true })
|
||||
},
|
||||
Category: {
|
||||
todos: ({ id }) => Todo.find({ categoryId: id }),
|
||||
|
||||
@ -12,7 +12,6 @@ const todoResolvers = {
|
||||
description,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
status: 'open',
|
||||
deadline,
|
||||
categoryId,
|
||||
})
|
||||
@ -22,7 +21,7 @@ const todoResolvers = {
|
||||
const deletedTodo = await Todo.findByIdAndRemove(id)
|
||||
return deletedTodo
|
||||
},
|
||||
updateTodo: (_, { id, title, description, status, deadline, categoryId }) => Todo.findByIdAndUpdate(id, { $set: { title, description, updatedAt: new Date().toISOString(), status, deadline, categoryId } }, { new: true }),
|
||||
updateTodo: (_, { id, title, description, deadline, categoryId }) => Todo.findByIdAndUpdate(id, { $set: { title, description, updatedAt: new Date().toISOString(), deadline, categoryId } }, { new: true }),
|
||||
},
|
||||
Todo: {
|
||||
category: ({ categoryId }) => Category.findById(categoryId),
|
||||
|
||||
@ -8,7 +8,17 @@ const port = config.get('port')
|
||||
|
||||
const startServer = async () => {
|
||||
try {
|
||||
const server = new ApolloServer({ typeDefs, resolvers })
|
||||
const server = new ApolloServer({
|
||||
typeDefs,
|
||||
resolvers,
|
||||
// context: (integrationContext) => {
|
||||
// const query = integrationContext.req.query.query || integrationContext.req.body.query || '';
|
||||
// console.log(query.length)
|
||||
// if (query.length > 500) {
|
||||
// throw new Error('Query too large');
|
||||
// }
|
||||
// },
|
||||
});
|
||||
await mongoose.connect(config.get('db'), {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
|
||||
@ -5,12 +5,12 @@ const mutation = gql`
|
||||
# Todo mutations
|
||||
createTodo(title: String! description: String! deadline: String! categoryId: String!): Todo
|
||||
deleteTodo(id: ID!): Todo
|
||||
updateTodo(id: ID! title: String! description: String! status: String! deadline: String! categoryId: String!): Todo
|
||||
updateTodo(id: ID! title: String! description: String! deadline: String! categoryId: String!): Todo
|
||||
|
||||
# Category mutations
|
||||
createCategory(title: String! description: String!): Category
|
||||
createCategory(title: String!): Category
|
||||
deleteCategory(id: ID!): Category
|
||||
updateCategory(id: ID! title: String! description: String!): Category
|
||||
updateCategory(id: ID! title: String!): Category
|
||||
}
|
||||
`
|
||||
|
||||
|
||||
@ -4,7 +4,6 @@ const categoryType = gql`
|
||||
type Category {
|
||||
id: ID
|
||||
title: String
|
||||
description: String
|
||||
createdAt: String
|
||||
updatedAt: String
|
||||
todos: [Todo]
|
||||
|
||||
@ -7,7 +7,6 @@ const todoType = gql`
|
||||
description: String
|
||||
createdAt: String
|
||||
updatedAt: String
|
||||
status: String
|
||||
deadline: String
|
||||
categoryId: String
|
||||
category: Category
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user