-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask.js
More file actions
44 lines (40 loc) · 902 Bytes
/
Copy pathTask.js
File metadata and controls
44 lines (40 loc) · 902 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const mongoose = require('mongoose');
const taskSchema = new mongoose.Schema(
{
title: {
type: String,
required: [true, 'Title is required'],
trim: true,
maxlength: [200, 'Title cannot exceed 200 characters'],
},
description: {
type: String,
trim: true,
default: '',
},
completed: {
type: Boolean,
default: false,
},
priority: {
type: String,
enum: ['low', 'medium', 'high'],
default: 'medium',
},
dueDate: {
type: Date,
default: null,
},
tags: {
type: [String],
default: [],
},
},
{ timestamps: true }
);
taskSchema.virtual('isOverdue').get(function () {
if (!this.dueDate || this.completed) return false;
return new Date() > this.dueDate;
});
taskSchema.set('toJSON', { virtuals: true });
module.exports = mongoose.model('Task', taskSchema);