Last active
April 28, 2020 22:56
-
-
Save nikosantis/518a9eee1d67563988cd11700028a7a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const connectDB = require('./db') | |
const { ObjectID } = require('mongodb') | |
module.exports = { | |
createTask: async ({ task }) => { | |
const inputTask = Object.assign(task) | |
let db | |
let newTask | |
try { | |
db = await connectDB | |
newTask = await db.collection('tasks').insertOne(inputTask) | |
inputTask._id = newTask.insertedId | |
} catch (error) { | |
console.log(error) | |
} | |
return newTask | |
}, | |
getTasks: async () => { | |
let db | |
let tasks = [] | |
try { | |
db = await connectDB() | |
tasks = await db.collection('tasks').findOne({ _id: ObjectID(_id) }) | |
} catch (error) { | |
console.log(error) | |
} | |
return tasks | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment