Refactor file handling in BuyProduct and Request models; implement file schema for better structure. Update routes to handle file uploads and downloads with improved error handling and logging. Adjust MongoDB connection management across scripts and routes for consistency.

This commit is contained in:
innoavvlasov committed 2025-11-05 19:06:11 +03:00
1 parent 41b5cb6fae
commit 284be82e1e
15 files changed
+630 -184

No files matched your search

+30 -12
View File
@@ -1,5 +1,34 @@
const mongoose = require('mongoose');
// Явно определяем схему для файлов
const fileSchema = new mongoose.Schema({
id: {
type: String,
required: true
},
name: {
type: String,
required: true
},
url: {
type: String,
required: true
},
type: {
type: String,
required: true
},
size: {
type: Number,
required: true
},
storagePath: String,
uploadedAt: {
type: Date,
default: Date.now
}
}, { _id: false });
const buyProductSchema = new mongoose.Schema({
companyId: {
type: String,
@@ -24,18 +53,7 @@ const buyProductSchema = new mongoose.Schema({
type: String,
default: 'шт'
},
files: [{
id: String,
name: String,
url: String,
type: String,
size: Number,
storagePath: String,
uploadedAt: {
type: Date,
default: Date.now
}
}],
files: [fileSchema],
acceptedBy: [{
companyId: {
type: mongoose.Schema.Types.ObjectId,
+12 -12
View File
@@ -22,12 +22,12 @@ const requestSchema = new mongoose.Schema({
required: true
},
files: [{
id: String,
name: String,
url: String,
type: String,
size: Number,
storagePath: String,
id: { type: String },
name: { type: String },
url: { type: String },
type: { type: String },
size: { type: Number },
storagePath: { type: String },
uploadedAt: {
type: Date,
default: Date.now
@@ -47,12 +47,12 @@ const requestSchema = new mongoose.Schema({
default: null
},
responseFiles: [{
id: String,
name: String,
url: String,
type: String,
size: Number,
storagePath: String,
id: { type: String },
name: { type: String },
url: { type: String },
type: { type: String },
size: { type: Number },
storagePath: { type: String },
uploadedAt: {
type: Date,
default: Date.now