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:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user