Video 90: Resource Creation Endpoints: Part II
This commit is contained in:
parent
97ae98972b
commit
f550158865
@ -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
|
||||
}
|
||||
})
|
||||
|
@ -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)
|
||||
})
|
||||
|
15
task-manager/src/models/task.js
Normal file
15
task-manager/src/models/task.js
Normal 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
|
Loading…
Reference in New Issue
Block a user