233 lines
7.2 KiB
JavaScript
233 lines
7.2 KiB
JavaScript
/**
|
|
* Copy a quiz document into another account's event.
|
|
* Run: node scripts/copy-quiz-to-account.js
|
|
*/
|
|
const path = require('path');
|
|
require('dotenv').config({ path: path.join(__dirname, '..', '.env') });
|
|
const mongoose = require('mongoose');
|
|
const QuizPoll = require('../src/models/QuizPoll');
|
|
const Event = require('../src/models/Event');
|
|
const Session = require('../src/models/Session');
|
|
const User = require('../src/models/User');
|
|
const { syncQuizPollToFirebase } = require('../src/utils/quizPollFirebaseSync');
|
|
|
|
const TARGET_EMAIL = 'madhuragauri@crestindia.co.in';
|
|
|
|
/** Source quiz payload (Mongo export; ids stripped on insert). */
|
|
const SOURCE_QUIZ = {
|
|
title: 'COPD Basics',
|
|
type: 'quiz',
|
|
description: 'test',
|
|
questions: [
|
|
{
|
|
question:
|
|
'What spirometry value defines airflow limitation and confirms a COPD diagnosis after a bronchodilator is given?',
|
|
imageUrl:
|
|
'https://did94hhhcgq1d.cloudfront.net/eventbuzz/69b58b13aff81b3887b0026c/69ce3c91be56b4a3b09b2333/quiz-polls/1782468667817-Screenshot_2026-06-01_at_10.01.48_AM.png',
|
|
type: 'single',
|
|
options: [
|
|
{
|
|
text: 'FEV1/FVC greater than 0.80',
|
|
isCorrect: false,
|
|
imageUrl:
|
|
'https://did94hhhcgq1d.cloudfront.net/eventbuzz/69b58b13aff81b3887b0026c/69ce3c91be56b4a3b09b2333/quiz-polls/1782468677271-Screenshot_2026-05-21_at_7.56.07_PM.png',
|
|
},
|
|
{
|
|
text: 'FEV1/FVC less than 0.70',
|
|
isCorrect: true,
|
|
imageUrl:
|
|
'https://did94hhhcgq1d.cloudfront.net/eventbuzz/69b58b13aff81b3887b0026c/69ce3c91be56b4a3b09b2333/quiz-polls/1782468680923-Screenshot_2026-05-21_at_7.56.07_PM.png',
|
|
},
|
|
{ text: 'FVC less than 50% predicted', isCorrect: false, imageUrl: null },
|
|
{
|
|
text: 'FEV1 increases by 12%',
|
|
isCorrect: false,
|
|
imageUrl:
|
|
'https://did94hhhcgq1d.cloudfront.net/eventbuzz/69b58b13aff81b3887b0026c/69ce3c91be56b4a3b09b2333/quiz-polls/1782468683856-Screenshot_2026-05-21_at_7.48.20_PM.png',
|
|
},
|
|
],
|
|
points: 1,
|
|
required: true,
|
|
timeLimit: 30,
|
|
},
|
|
{
|
|
question:
|
|
'What structural lung change in emphysema leads to permanent air trapping and progressive shortness of breath?',
|
|
imageUrl: null,
|
|
type: 'single',
|
|
options: [
|
|
{ text: 'Reversible smooth muscle spasm', isCorrect: false, imageUrl: null },
|
|
{
|
|
text: 'Destruction of alveolar walls and loss of elastic recoil',
|
|
isCorrect: true,
|
|
imageUrl: null,
|
|
},
|
|
{ text: 'Fibrosis and narrowing of the upper airways', isCorrect: false, imageUrl: null },
|
|
{ text: 'Overproduction of mucus in the large bronchi', isCorrect: false, imageUrl: null },
|
|
],
|
|
points: 1,
|
|
required: true,
|
|
timeLimit: 30,
|
|
},
|
|
{
|
|
question: 'What is the globally recognized leading environmental cause of COPD?',
|
|
imageUrl: null,
|
|
type: 'single',
|
|
options: [
|
|
{ text: 'Alpha-1 antitrypsin deficiency', isCorrect: false, imageUrl: null },
|
|
{ text: 'Outdoor air pollution', isCorrect: false, imageUrl: null },
|
|
{ text: 'Cigarette smoking', isCorrect: true, imageUrl: null },
|
|
{ text: 'Occupational dust exposure', isCorrect: false, imageUrl: null },
|
|
],
|
|
points: 1,
|
|
required: true,
|
|
timeLimit: 30,
|
|
},
|
|
{
|
|
question:
|
|
'Which drug class is the baseline maintenance treatment for reducing daily COPD symptoms and preventing flare-ups?',
|
|
imageUrl: null,
|
|
type: 'single',
|
|
options: [
|
|
{ text: 'Short-acting beta-agonists (SABAs)', isCorrect: false, imageUrl: null },
|
|
{ text: 'Systemic corticosteroids', isCorrect: false, imageUrl: null },
|
|
{
|
|
text: 'Long-acting bronchodilators (LAMAs or LABAs)',
|
|
isCorrect: true,
|
|
imageUrl: null,
|
|
},
|
|
{ text: 'Mucolytics', isCorrect: false, imageUrl: null },
|
|
],
|
|
points: 1,
|
|
required: true,
|
|
timeLimit: 30,
|
|
},
|
|
{
|
|
question:
|
|
'What is the minimum number of hours per day that long-term oxygen therapy must be used to improve survival rates in severe resting hypoxemia?',
|
|
imageUrl: null,
|
|
type: 'single',
|
|
options: [
|
|
{ text: 'At least 5 hours per day', isCorrect: false, imageUrl: null },
|
|
{ text: 'At least 10 hours per day', isCorrect: false, imageUrl: null },
|
|
{ text: 'At least 15 hours per day', isCorrect: true, imageUrl: null },
|
|
{ text: 'Only during sleep', isCorrect: false, imageUrl: null },
|
|
],
|
|
points: 1,
|
|
required: true,
|
|
timeLimit: 30,
|
|
},
|
|
],
|
|
settings: {
|
|
status: 'active',
|
|
isLive: false,
|
|
displayMode: 'quiz_master',
|
|
startTime: null,
|
|
endTime: null,
|
|
showResults: true,
|
|
allowMultipleAttempts: false,
|
|
timeRestricted: true,
|
|
timeLimit: 150,
|
|
rewardRules: {
|
|
quizPollSubmitted: 0,
|
|
quizCorrectPerQuestion: 5,
|
|
},
|
|
liveQuestionId: null,
|
|
randomizeQuestions: false,
|
|
showCorrectAnswer: false,
|
|
},
|
|
};
|
|
|
|
async function run() {
|
|
const uri = process.env.MONGODB_URI;
|
|
if (!uri) {
|
|
console.error('MONGODB_URI is not set');
|
|
process.exit(1);
|
|
}
|
|
await mongoose.connect(uri);
|
|
|
|
const user = await User.findOne({ email: TARGET_EMAIL }).lean();
|
|
if (!user) {
|
|
console.error('User not found:', TARGET_EMAIL);
|
|
process.exit(1);
|
|
}
|
|
|
|
const event = await Event.findOne({ organization: user.organization, deletedAt: null })
|
|
.sort({ createdAt: -1 })
|
|
.lean();
|
|
if (!event) {
|
|
console.error('No event found for organization', user.organization);
|
|
process.exit(1);
|
|
}
|
|
|
|
const session = await Session.findOne({ event: event._id }).sort({ startTime: 1 }).lean();
|
|
if (!session) {
|
|
console.error('No session found for event', event._id);
|
|
process.exit(1);
|
|
}
|
|
|
|
const existing = await QuizPoll.findOne({
|
|
event: event._id,
|
|
title: SOURCE_QUIZ.title,
|
|
type: 'quiz',
|
|
deletedAt: null,
|
|
}).lean();
|
|
if (existing) {
|
|
console.log('Quiz already exists — skipping create');
|
|
console.log(
|
|
JSON.stringify(
|
|
{
|
|
quizId: String(existing._id),
|
|
eventId: String(event._id),
|
|
eventName: event.name,
|
|
sessionId: existing.session ? String(existing.session) : null,
|
|
title: existing.title,
|
|
},
|
|
null,
|
|
2,
|
|
),
|
|
);
|
|
await mongoose.disconnect();
|
|
return;
|
|
}
|
|
|
|
const payload = {
|
|
...SOURCE_QUIZ,
|
|
event: event._id,
|
|
session: session._id,
|
|
settings: {
|
|
...SOURCE_QUIZ.settings,
|
|
presentationToken: QuizPoll.generatePresentationToken(),
|
|
},
|
|
};
|
|
|
|
const item = await QuizPoll.create(payload);
|
|
await syncQuizPollToFirebase(item);
|
|
|
|
console.log('Quiz created successfully');
|
|
console.log(
|
|
JSON.stringify(
|
|
{
|
|
quizId: String(item._id),
|
|
title: item.title,
|
|
eventId: String(event._id),
|
|
eventName: event.name,
|
|
sessionId: String(session._id),
|
|
sessionTitle: session.title,
|
|
accountEmail: TARGET_EMAIL,
|
|
questionCount: item.questions?.length ?? 0,
|
|
presentationToken: item.settings?.presentationToken,
|
|
},
|
|
null,
|
|
2,
|
|
),
|
|
);
|
|
|
|
await mongoose.disconnect();
|
|
}
|
|
|
|
run().catch((err) => {
|
|
console.error(err);
|
|
process.exit(1);
|
|
});
|