Skip to content

Commit

Permalink
implemented create and get task functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Djibba committed Mar 5, 2023
1 parent d2578d7 commit 6d1e8e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 10 additions & 4 deletions controllers/taskController.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
const mongoose = require('mongoose');
const Task = require('../models/taskModel')

const getAllTasks = (req, res, next) => {
res.send('all tasks');
const getAllTasks = async (req, res, next) => {
try {
const tasks = await Task.find({})
res.status(200).json({ tasks })
} catch (error) {
res.status(500).json( { msg: error })
}
};

const createTasks = async (req, res, next) => {

try {

const task = await Task.create(req.body)
res.status(201).json({ task })
} catch (error) {

res.status(500).json( { msg: error })
}

};
Expand Down
5 changes: 4 additions & 1 deletion models/taskModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ const mongoose = require('mongoose');
const taskSchema = mongoose.Schema({
name: {
type: String,
required: true
required: [true, 'must provide name'],
trim: true,
maxlength: [20, 'name cannot be more than 20 characters']
},
completed: {
type: Boolean,
default: false
}
})

Expand Down

0 comments on commit 6d1e8e8

Please sign in to comment.