add new back

This commit is contained in:
2025-10-27 18:58:38 +03:00
parent a6065dd95c
commit 6c190b80fb
16 changed files with 996 additions and 147 deletions

View File

@@ -35,6 +35,16 @@ const buyProductSchema = new mongoose.Schema({
default: Date.now
}
}],
acceptedBy: [{
companyId: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Company'
},
acceptedAt: {
type: Date,
default: Date.now
}
}],
status: {
type: String,
enum: ['draft', 'published'],

View File

@@ -0,0 +1,62 @@
const mongoose = require('mongoose');
const requestSchema = new mongoose.Schema({
senderCompanyId: {
type: String,
required: true,
index: true
},
recipientCompanyId: {
type: String,
required: true,
index: true
},
text: {
type: String,
required: true
},
files: [{
id: String,
name: String,
url: String,
type: String,
size: Number,
uploadedAt: {
type: Date,
default: Date.now
}
}],
productId: {
type: String,
ref: 'BuyProduct'
},
status: {
type: String,
enum: ['pending', 'accepted', 'rejected'],
default: 'pending'
},
response: {
type: String,
default: null
},
respondedAt: {
type: Date,
default: null
},
createdAt: {
type: Date,
default: Date.now,
index: true
},
updatedAt: {
type: Date,
default: Date.now
}
});
// Индексы для оптимизации поиска
requestSchema.index({ senderCompanyId: 1, createdAt: -1 });
requestSchema.index({ recipientCompanyId: 1, createdAt: -1 });
requestSchema.index({ senderCompanyId: 1, recipientCompanyId: 1 });
module.exports = mongoose.model('Request', requestSchema);