fix mongo

This commit is contained in:
2025-11-04 19:46:39 +03:00
parent 69eddf47db
commit c4664edd7e
7 changed files with 60 additions and 153 deletions

View File

@@ -9,7 +9,6 @@ const Message = require('../models/Message');
const Review = require('../models/Review');
const mongoose = require('mongoose');
const { Types } = mongoose;
const connectDB = require('../config/db');
const PRESET_COMPANY_ID = new Types.ObjectId('68fe2ccda3526c303ca06796');
const PRESET_USER_EMAIL = 'admin@test-company.ru';
@@ -140,17 +139,15 @@ const waitForDatabaseConnection = async () => {
}
try {
const connection = await connectDB();
if (!connection) {
break;
// Ожидаем подключения (подключение происходит автоматически через server/utils/mongoose.ts)
await new Promise(resolve => setTimeout(resolve, 500));
if (mongoose.connection.readyState === 1) {
const authed = await verifyAuth();
if (authed) {
return;
}
}
const authed = await verifyAuth();
if (authed) {
return;
}
await mongoose.connection.close().catch(() => {});
} catch (error) {
if (!isAuthFailure(error)) {
throw error;
@@ -221,12 +218,8 @@ const initializeTestUser = async () => {
} catch (error) {
console.error('Error initializing test data:', error.message);
if (error?.code === 13 || /auth/i.test(error?.message || '')) {
try {
await connectDB();
} catch (connectError) {
if (process.env.DEV === 'true') {
console.error('Failed to re-connect after auth error:', connectError.message);
}
if (process.env.DEV === 'true') {
console.error('Auth error detected. Connection managed by server/utils/mongoose.ts');
}
}
}