Skip to content

[JITERA] Enhance Reader Model for Borrowed Books Management

chi le requested to merge feat/update-reader-model-1750785864 into main

Created by: chi-jitera

Overview

This pull request updates the existing Reader model to better manage the list of books that readers have borrowed. The enhancements include additional fields to track the borrowing status and due dates for each borrowed book.

Changes Made

  1. Added status Field:

    • This field tracks whether the book is currently borrowed or has been returned. It can have two values: borrowed or returned, with the default set to borrowed.
  2. Added dueDate Field:

    • This field specifies the date by which the book should be returned. It helps in managing overdue books and sending reminders to readers.

Updated Reader Model Code

const mongoose = require('../config/db');

const readerSchema = new mongoose.Schema({
    name: { type: String, required: true },
    contactInfo: { type: String, required: true },
    borrowedBooks: [{
        book: { type: mongoose.Schema.Types.ObjectId, ref: 'Book' },
        borrowDate: { type: Date, default: Date.now },
        returnDate: { type: Date },
        status: { type: String, enum: ['borrowed', 'returned'], default: 'borrowed' },
        dueDate: { type: Date }
    }]
});

module.exports = mongoose.model('Reader', readerSchema);

This update will allow for more effective management of borrowed books, ensuring that we can track their status and due dates efficiently.

Merge request reports