Video 118: Working with Timestamps
This commit is contained in:
parent
9108ef7561
commit
c2d465adc8
@ -6,37 +6,14 @@ const taskRouter = require('./routers/task')
|
|||||||
const app = express()
|
const app = express()
|
||||||
const port = process.env.PORT || 4200
|
const port = process.env.PORT || 4200
|
||||||
|
|
||||||
// app.use((req, res, next) => {
|
|
||||||
// if (req.method === 'GET') {
|
|
||||||
// res.send('GET requests are disabled')
|
|
||||||
// } else {
|
|
||||||
// next()
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
|
|
||||||
// app.use((req, res, next) => {
|
|
||||||
// res.status(503).send('Site is in maintenance mode').end()
|
|
||||||
// })
|
|
||||||
|
|
||||||
app.use(express.json())
|
app.use(express.json())
|
||||||
app.use(userRouter)
|
app.use(userRouter)
|
||||||
app.use(taskRouter)
|
app.use(taskRouter)
|
||||||
|
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
console.log('Server is up on port ' + port)
|
const now = new Date()
|
||||||
|
console.log('Server is up on port ' + port + ' at ' + now.toTimeString())
|
||||||
})
|
})
|
||||||
|
|
||||||
const Task = require('./models/task')
|
const Task = require('./models/task')
|
||||||
const User = require('./models/user')
|
const User = require('./models/user')
|
||||||
|
|
||||||
const main = async () => {
|
|
||||||
// const task = await Task.findById('5f0f845f55f3ad018f2305fc')
|
|
||||||
// await task.populate('owner').execPopulate()
|
|
||||||
// console.log(task.owner)
|
|
||||||
|
|
||||||
const user = await User.findById('5f0f838e040ee20177d799f3')
|
|
||||||
await user.populate('tasks').execPopulate()
|
|
||||||
console.log(user.tasks)
|
|
||||||
}
|
|
||||||
|
|
||||||
main()
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
const mongoose = require('mongoose')
|
const mongoose = require('mongoose')
|
||||||
|
|
||||||
const Task = mongoose.model('Task', {
|
const taskSchema = new mongoose.Schema({
|
||||||
description: {
|
description: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
@ -15,6 +15,10 @@ const Task = mongoose.model('Task', {
|
|||||||
required: true,
|
required: true,
|
||||||
ref: 'User'
|
ref: 'User'
|
||||||
}
|
}
|
||||||
|
}, {
|
||||||
|
timestamps: true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const Task = mongoose.model('Task', taskSchema)
|
||||||
|
|
||||||
module.exports = Task
|
module.exports = Task
|
||||||
|
@ -48,6 +48,8 @@ const userSchema = new mongoose.Schema({
|
|||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
|
}, {
|
||||||
|
timestamps: true
|
||||||
})
|
})
|
||||||
|
|
||||||
userSchema.virtual('tasks', {
|
userSchema.virtual('tasks', {
|
||||||
|
Loading…
Reference in New Issue
Block a user