Files
multy-stub/server/routers/assessment-tools/scripts/recreate-test-user.js
2025-11-21 16:19:47 +03:00

39 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Импортировать mongoose из общего модуля (подключение происходит в server/utils/mongoose.ts)
const mongoose = require('../../../utils/mongoose');
const { Event } = require('../models');
async function recreateTestUser() {
try {
// Ждем, пока подключение будет готово
if (mongoose.connection.readyState !== 1) {
await new Promise(resolve => {
mongoose.connection.once('connected', resolve);
});
}
console.log('Connected to MongoDB');
// Создаем тестовое мероприятие если его нет
let event = await Event.findOne();
if (!event) {
event = await Event.create({
name: 'Tatar san',
status: 'draft',
votingEnabled: false
});
console.log('Test event created:', event.name);
}
console.log('Database initialized successfully');
await mongoose.disconnect();
console.log('Disconnected from MongoDB');
} catch (error) {
console.error('Error:', error);
process.exit(1);
}
}
recreateTestUser();