// api/src/models/Item.js
const mongoose = require('mongoose');
const itemSchema = new mongoose.Schema({
name: {
type: String,
required: [true, 'Name is required'],
trim: true,
maxlength: [100, 'Name cannot exceed 100 characters']
},
description: {
type: String,
trim: true,
maxlength: [500, 'Description cannot exceed 500 characters']
},
completed: {
type: Boolean,
default: false
}
}, {
timestamps: true // Adds createdAt and updatedAt
});
// Index for common queries
itemSchema.index({ completed: 1, createdAt: -1 });
module.exports = mongoose.model('Item', itemSchema);