diff --git a/task-manager/src/index.js b/task-manager/src/index.js index 720a61a..daba8d3 100644 --- a/task-manager/src/index.js +++ b/task-manager/src/index.js @@ -6,37 +6,14 @@ const taskRouter = require('./routers/task') const app = express() 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(userRouter) app.use(taskRouter) 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 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() diff --git a/task-manager/src/models/task.js b/task-manager/src/models/task.js index f87dfe4..29e6efb 100644 --- a/task-manager/src/models/task.js +++ b/task-manager/src/models/task.js @@ -1,6 +1,6 @@ const mongoose = require('mongoose') -const Task = mongoose.model('Task', { +const taskSchema = new mongoose.Schema({ description: { type: String, required: true, @@ -15,6 +15,10 @@ const Task = mongoose.model('Task', { required: true, ref: 'User' } +}, { + timestamps: true }) +const Task = mongoose.model('Task', taskSchema) + module.exports = Task diff --git a/task-manager/src/models/user.js b/task-manager/src/models/user.js index c80840a..27a9274 100644 --- a/task-manager/src/models/user.js +++ b/task-manager/src/models/user.js @@ -48,6 +48,8 @@ const userSchema = new mongoose.Schema({ required: true } }] +}, { + timestamps: true }) userSchema.virtual('tasks', {