1
0

Video 90: Resource Creation Endpoints: Part II

This commit is contained in:
JayWll 2020-02-23 15:09:38 -07:00
parent 97ae98972b
commit f550158865
3 changed files with 27 additions and 13 deletions

View File

@ -4,15 +4,3 @@ mongoose.connect('mongodb://localhost:27017/task-manager-api', {
useNewUrlParser: true,
useCreateIndex: true
})
const Task = mongoose.model('Task', {
description: {
type: String,
required: true,
trim: true
},
completed: {
type: Boolean,
default: false
}
})

View File

@ -1,6 +1,7 @@
const express = require('express')
require('./db/mongoose')
const User = require('./models/user')
const Task = require('./models/task')
const app = express()
const port = process.env.PORT || 4200
@ -11,7 +12,17 @@ app.post('/users', (req, res) => {
const user = new User(req.body)
user.save().then(() => {
res.send(user)
res.status(201).send(user)
}).catch((e) => {
res.status(400).send(e)
})
})
app.post('/tasks', (req, res) => {
const task = new Task(req.body)
task.save().then(() => {
res.status(201).send(task)
}).catch((e) => {
res.status(400).send(e)
})

View File

@ -0,0 +1,15 @@
const mongoose = require('mongoose')
const Task = mongoose.model('Task', {
description: {
type: String,
required: true,
trim: true
},
completed: {
type: Boolean,
default: false
}
})
module.exports = Task