multy-stub/server/routers/old/kazan-explore/index.js

104 lines
3.2 KiB
JavaScript
Raw Normal View History

2024-06-01 19:53:28 +03:00
const router = require('express').Router();
//const loginMiddleware = require('../middleware/login-middleware');
2024-06-01 20:22:43 +03:00
// First page
router.get('/getInfoAboutKazan', (request, response) => {
2024-06-01 20:32:45 +03:00
response.send(require('./json/first/info-about-kazan/success.json'))
2024-06-01 20:22:43 +03:00
})
router.get('/getNews', (request, response) => {
2024-06-01 20:32:45 +03:00
response.send(require('./json/first/news/success.json'))
2024-06-01 20:22:43 +03:00
})
2024-06-01 19:53:28 +03:00
// Sport page
router.get('/getSportData', (request, response) => {
response.send(require('./json/sport/sport-data.json'))
})
// Places page
router.get('/getPlacesData', (request, response) => {
response.send(require('./json/places/places-data.json'))
})
// Transport page
router.get('/getInfoAboutTransportPage', (request, response) => {
response.send(require('./json/transport/info-about-page.json'))
})
router.get('/getBus', (request, response) => {
response.send(require('./json/transport/bus-numbers.json'))
})
router.get('/getTral', (request, response) => {
response.send(require('./json/transport/tral-numbers.json'))
})
router.get('/getEvents', (request, response) => {
response.send(require('./json/transport/events-calendar.json'))
})
router.get('/getTripSchedule', (request, response) => {
response.send(require('./json/transport/trip-schedule/success.json'))
})
2024-06-01 20:22:43 +03:00
router.get('/getInfoAboutInstitutions', (request, response) => {
2024-06-01 20:32:45 +03:00
response.send(require('./json/transport/info-about-institutions.json'))
2024-06-01 20:22:43 +03:00
})
2024-06-01 19:53:28 +03:00
// Education page
router.get('/getInfoAboutKFU', (request, response) => {
response.send(require('./json/education/info-about-kfu.json'))
})
// Login
router.post('/entrance', (request, response) => {
const { email, password } = request.body.entranceData;
try {
const users = require('../json/users-information/success.json');
const user = users.data.find(user => user.email === email && user.password === password);
if (!user) {
return response.status(401).send('Неверные учетные данные');
}
const responseObject = {
email: user.email,
}
if (user.cardId){
responseObject.cardId = user.cardId || "";
}
return response.json(responseObject);
} catch (error) {
console.error('Ошибка чтения файла:', error);
response.status(500).send('Внутренняя ошибка сервера');
}
})
router.post('/registration', async (request, response) => {
const { email, password, confirmPassword } = request.body.registerData;
try {
if (password !== confirmPassword) {
return response.status(400).send('Пароли не совпадают!');
}
const users = require('../json/users-information/success.json');
const existingUser = users.data.find(user => user.email === email);
if (existingUser) {
return response.status(400).send('Пользователь с такой почтой уже существует!');
}
return response.json({ email: email});
} catch (error) {
console.error('Ошибка регистрации пользователя:', error);
response.status(500).send('Внутренняя ошибка сервера');
}
});
module.exports = router;