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,18 +1,18 @@
|
||||
const mongoose = require('mongoose');
|
||||
const mongoose = require('../../../utils/mongoose');
|
||||
const { ObjectId } = mongoose.Types;
|
||||
const Message = require('../models/Message');
|
||||
require('dotenv').config({ path: '../../.env' });
|
||||
|
||||
const mongoUrl = process.env.MONGODB_URI || 'mongodb://localhost:27017/procurement_db';
|
||||
require('dotenv').config();
|
||||
|
||||
async function migrateMessages() {
|
||||
try {
|
||||
console.log('[Migration] Connecting to MongoDB...');
|
||||
await mongoose.connect(mongoUrl, {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
serverSelectionTimeoutMS: 5000,
|
||||
connectTimeoutMS: 5000,
|
||||
});
|
||||
// Подключение к MongoDB происходит через server/utils/mongoose.ts
|
||||
console.log('[Migration] Checking MongoDB connection...');
|
||||
if (mongoose.connection.readyState !== 1) {
|
||||
console.log('[Migration] Waiting for MongoDB connection...');
|
||||
await new Promise((resolve) => {
|
||||
mongoose.connection.once('connected', resolve);
|
||||
});
|
||||
}
|
||||
console.log('[Migration] Connected to MongoDB');
|
||||
|
||||
// Найти все сообщения
|
||||
@@ -54,7 +54,6 @@ async function migrateMessages() {
|
||||
console.log(' Expected:', expectedRecipient);
|
||||
|
||||
// Конвертируем в ObjectId если нужно
|
||||
const { ObjectId } = require('mongoose').Types;
|
||||
let recipientObjectId = expectedRecipient;
|
||||
try {
|
||||
if (typeof expectedRecipient === 'string' && ObjectId.isValid(expectedRecipient)) {
|
||||
|
||||
Reference in New Issue
Block a user