kazan-explore multy stub changes

This commit is contained in:
Kamila Nazirova 2025-01-24 22:39:25 +03:00
parent 5cc580c3c5
commit 335179ad26
3 changed files with 280 additions and 211 deletions

View File

@ -0,0 +1,3 @@
exports.KAZAN_EXPLORE_RESULTS_MODEL_NAME = 'KAZAN_EXPLORE_RESULTS'
exports.TOKEN_KEY = "KAZAN_EXPLORE_TOP_SECRET_TOKEN_KEY"

View File

@ -1,11 +1,50 @@
const router = require('express').Router();
const { ResultsModel } = require('./model/results')
router.get('/getQuizResults/:userId', async (request, response) => {
const { userId } = request.params;
try {
const results = await ResultsModel.findOne({ userId : userId }).exec();
if (!results) {
return response.status(404).send({ message: 'Quiz results not found' });
}
response.send(results.items);
} catch (error) {
response.status(500).send({ message: 'An error occurred while fetching quiz results' });
}
});
router.post('/addQuizResult', async (request, response) => {
const { userId, quizId, result } = request.body;
if (!userId || !quizId || !result) {
return response.status(400).send({ message: 'Invalid input data' });
}
try {
let userResults = await ResultsModel.findOne({ userId : userId }).exec();
if (!userResults) {
userResults = new ResultsModel({ userId, items: [] });
}
userResults.items.push({ quizId, result });
await userResults.save();
response.status(200).send({ message: 'Quiz result added successfully', data: userResults });
} catch (error) {
response.status(500).send({ message: 'An error occurred while adding quiz result' });
}
});
// First page
router.get('/getInfoAboutKazan', (request, response) => {
const lang = request.query.lang || 'ru'; // Получаем язык из параметров запроса
try {
const data = require('./json/first/info-about-kazan/success.json'); // Загружаем весь JSON
const data = require('../json/first/info-about-kazan/success.json'); // Загружаем весь JSON
const translatedData = data[lang] || data['ru']; // Выбираем перевод по языку или дефолтный
response.send(translatedData); // Отправляем перевод клиенту
} catch (error) {
@ -16,7 +55,7 @@ router.get('/getInfoAboutKazan', (request, response) => {
router.get('/getNews', (request, response) => {
const lang = request.query.lang || 'ru';
try {
const data = require(`./json/first/news/${lang}/success.json`);
const data = require(`../json/first/news/${lang}/success.json`);
response.send(data);
} catch (error) {
response.status(404).send({ message: 'Language not found' });
@ -27,7 +66,7 @@ router.get('/getNews', (request, response) => {
router.get('/getFirstText', (request, response) => {
const lang = request.query.lang || 'ru'; // Получаем язык из параметров
try {
const data = require('./json/sport/first-text/success.json'); // Загружаем JSON
const data = require('../json/sport/first-text/success.json'); // Загружаем JSON
const translatedData = data[lang] || data['ru']; // Берём перевод или дефолтный
response.send(translatedData);
} catch (error) {
@ -38,7 +77,7 @@ router.get('/getFirstText', (request, response) => {
router.get('/getSecondText', (request, response) => {
const lang = request.query.lang || 'ru';
try {
const data = require('./json/sport/second-text/success.json');
const data = require('../json/sport/second-text/success.json');
const translatedData = data[lang] || data['ru'];
response.send(translatedData);
} catch (error) {
@ -49,7 +88,7 @@ router.get('/getSecondText', (request, response) => {
router.get('/getSportData', (request, response) => {
const lang = request.query.lang || 'ru';
try {
const data = require(`./json/sport/sport-list/${lang}/success.json`);
const data = require(`../json/sport/sport-list/${lang}/success.json`);
response.send(data);
} catch (error) {
response.status(404).send({ message: 'Language not found' });
@ -59,7 +98,7 @@ router.get('/getSportData', (request, response) => {
router.get('/getSportQuiz', (request, response) => {
const lang = request.query.lang || 'ru';
try {
const data = require(`./json/sport/quiz/${lang}/success.json`);
const data = require(`../json/sport/quiz/${lang}/success.json`);
response.send(data);
} catch (error) {
response.status(404).send({ message: 'Language not found' });
@ -70,7 +109,7 @@ router.get('/getSportQuiz', (request, response) => {
router.get('/getPlacesData', (request, response) => {
const lang = request.query.lang || 'ru';
try {
const data = require(`./json/places/${lang}/success.json`);
const data = require(`../json/places/${lang}/success.json`);
response.send(data);
} catch (error) {
response.status(404).send({ message: 'Language not found' });
@ -81,7 +120,7 @@ router.get('/getPlacesData', (request, response) => {
router.get('/getInfoAboutTransportPage', (request, response) => {
const lang = request.query.lang || 'ru';
try {
const data = require('./json/transport/info-about-page/success.json');
const data = require('../json/transport/info-about-page/success.json');
const translatedData = data[lang] || data['ru'];
response.send(translatedData);
} catch (error) {
@ -90,21 +129,21 @@ router.get('/getInfoAboutTransportPage', (request, response) => {
})
router.get('/getBus', (request, response) => {
response.send(require('./json/transport/bus-numbers/success.json'))
response.send(require('../json/transport/bus-numbers/success.json'))
})
router.get('/getTral', (request, response) => {
response.send(require('./json/transport/tral-numbers/success.json'))
response.send(require('../json/transport/tral-numbers/success.json'))
})
router.get('/getEvents', (request, response) => {
response.send(require('./json/transport/events-calendar/success.json'))
response.send(require('../json/transport/events-calendar/success.json'))
})
router.get('/getTripSchedule', (request, response) => {
const lang = request.query.lang || 'ru';
try {
const data = require(`./json/transport/trip-schedule/${lang}/success.json`);
const data = require(`../json/transport/trip-schedule/${lang}/success.json`);
response.send(data);
} catch (error) {
response.status(404).send({ message: 'Language not found' });
@ -115,7 +154,7 @@ router.get('/getTripSchedule', (request, response) => {
router.get('/getHistoryText', (request, response) => {
const lang = request.query.lang || 'ru';
try {
const data = require(`./json/history/text/${lang}/success.json`);
const data = require(`../json/history/text/${lang}/success.json`);
response.send(data);
} catch (error) {
response.status(404).send({ message: 'Language not found' });
@ -124,7 +163,7 @@ router.get('/getHistoryText', (request, response) => {
router.get('/getHistoryList', (request, response) => {
const lang = request.query.lang || 'ru';
try {
const data = require(`./json/history/list/${lang}/success.json`);
const data = require(`../json/history/list/${lang}/success.json`);
response.send(data);
} catch (error) {
response.status(404).send({ message: 'Language not found' });
@ -135,7 +174,7 @@ router.get('/getHistoryList', (request, response) => {
router.get('/getInfoAboutEducation', (request, response) => {
const lang = request.query.lang || 'ru';
try {
const data = require('./json/education/text/success.json');
const data = require('../json/education/text/success.json');
const translatedData = data[lang] || data['ru'];
response.send(translatedData);
} catch (error) {
@ -145,7 +184,7 @@ router.get('/getInfoAboutEducation', (request, response) => {
router.get('/getEducationList', (request, response) => {
const lang = request.query.lang || 'ru';
try {
const data = require(`./json/education/cards/${lang}/success.json`);
const data = require(`../json/education/cards/${lang}/success.json`);
response.send(data);
} catch (error) {
response.status(404).send({ message: 'Language not found' });
@ -154,7 +193,7 @@ router.get('/getEducationList', (request, response) => {
router.get('/getInfoAboutKFU', (request, response) => {
const lang = request.query.lang || 'ru';
try {
const data = require('./json/education/kfu/success.json');
const data = require('../json/education/kfu/success.json');
const translatedData = data[lang] || data['ru'];
response.send(translatedData);
} catch (error) {
@ -168,7 +207,7 @@ router.post('/entrance', (request, response) => {
const { email, password } = request.body.entranceData;
try {
const users = require('./json/users-information/success.json');
const users = require('../json/users-information/success.json');
const user = users.data.find(user => user.email === email && user.password === password);
if (!user) {
@ -193,7 +232,7 @@ router.post('/registration', async (request, response) => {
if (password !== confirmPassword) {
return response.status(400).send('Пароли не совпадают!');
}
const users = require('./json/users-information/success.json');
const users = require('../json/users-information/success.json');
const existingUser = users.data.find(user => user.email === email);

View File

@ -0,0 +1,27 @@
const { Schema, model } = require('mongoose')
const { KAZAN_EXPLORE_RESULTS_MODEL_NAME } = require('../const')
const schema = new Schema({
userId: { type: String },
items: [
{
quizId: { type: String },
result: { type: Number }
}
]
})
schema.set('toJSON', {
virtuals: true,
versionKey: false,
transform: function (doc, ret) {
delete ret._id
}
})
schema.virtual('id').get(function () {
return this._id.toHexString()
})
exports.ResultsModel = model(KAZAN_EXPLORE_RESULTS_MODEL_NAME, schema)