ankitbisen28 / Atelier

Letest web app for custom clothing, Using React vite and Nodejs
https://atelier-client.vercel.app/
0 stars 1 forks source link

Feature Request: Update Project Schema and Create Separate Bid Schema #13

Closed ankitbisen28 closed 2 weeks ago

ankitbisen28 commented 2 weeks ago

Description

Update the existing project schema by removing the bids field and creating a separate schema for bids. This will help to better organize the data and improve scalability.

Current Project Schema

const mongoose = require('mongoose');

const projectSchema = mongoose.Schema({
    "title": String,
    "description": String,
    "requirements": String,
    "budget": Number,
    "deadline": Date,
    "consumerId": String, // Reference to the user who posted the project
    "category": String,
    "images": [
        {
            "url": String, // URL of the image stored in an external service
            "description": String, // Optional description of the image
            "uploadedAt": Date // Timestamp when the image was uploaded
        }
    ],
    "bids": [
        {
            "bidderId": String, // Reference to the user who placed the bid
            "amount": Number,
            "message": String,
            "createdAt": Date
        }
    ],
    "selectedBidder": String, // Reference to the selected bidder (if any)
    "status": String, // "open", "closed", "in progress", "completed"
    "createdAt": Date,
    "updatedAt": Date
});

projectSchema.virtual('id').get(function () {
    return this._id.toHexString();
});

projectSchema.set('toJSON', {
    virtuals: true,
});

module.exports = mongoose.model('project', projectSchema);

Proposed Changes

  1. Update Project Schema:

    • Remove the bids field from the project schema.
  2. Create Bid Schema:

    • Define a new schema for bids with the following structure:
      
      const mongoose = require('mongoose');

    const bidSchema = mongoose.Schema({ "project_id": { type: mongoose.Schema.Types.ObjectId, ref: 'project' }, "maker_id": { type: mongoose.Schema.Types.ObjectId, ref: 'user' }, "bid_amount": Number, "proposal_text": String, "status": { type: String, enum: ['Pending', 'Accepted', 'Rejected'], default: 'Pending' }, "created_at": { type: Date, default: Date.now }, "updated_at": { type: Date, default: Date.now } });

    bidSchema.virtual('id').get(function () { return this._id.toHexString(); });

    bidSchema.set('toJSON', { virtuals: true, });

    module.exports = mongoose.model('bid', bidSchema);

Acceptance Criteria

Tasks

  1. Update the Project Schema:

    • Remove the bids field from the project schema.
    const mongoose = require('mongoose');
    
    const projectSchema = mongoose.Schema({
        "title": String,
        "description": String,
        "requirements": String,
        "budget": Number,
        "deadline": Date,
        "consumerId": String, // Reference to the user who posted the project
        "category": String,
        "images": [
            {
                "url": String, // URL of the image stored in an external service
                "description": String, // Optional description of the image
                "uploadedAt": Date // Timestamp when the image was uploaded
            }
        ],
        "selectedBidder": String, // Reference to the selected bidder (if any)
        "status": String, // "open", "closed", "in progress", "completed"
        "createdAt": Date,
        "updatedAt": Date
    });
    
    projectSchema.virtual('id').get(function () {
        return this._id.toHexString();
    });
    
    projectSchema.set('toJSON', {
        virtuals: true,
    });
    
    module.exports = mongoose.model('project', projectSchema);
  2. Create the Bid Schema:

    • Define the new bid schema as specified above.
  3. Update Application Logic:

    • Update any existing functionality that interacts with bids to use the new bid schema.
    • Ensure that creating, reading, updating, and deleting bids works as expected with the new schema.
  4. Testing:

    • Thoroughly test the new bid schema and the updated project schema.
    • Ensure that all existing tests pass and add new tests as necessary to cover the new schema.