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
Update Project Schema:
Remove the bids field from the project schema.
Create Bid Schema:
Define a new schema for bids with the following structure:
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
Proposed Changes
Update Project Schema:
Create Bid Schema:
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
Update the Project Schema:
Create the Bid Schema:
Update Application Logic:
Testing: