Reformat code
This commit is contained in:
parent
137428ffa7
commit
123684da13
|
@ -33,15 +33,15 @@ betterzonRouter.use('/crawlingstatus', crawlingstatusRouter);
|
|||
|
||||
|
||||
betterzonRouter.get('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
res.status(200).send('Pluto Development Betterzon API Endpoint');
|
||||
} catch (e) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
try {
|
||||
res.status(200).send('Pluto Development Betterzon API Endpoint');
|
||||
} catch (e: any) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -21,50 +21,50 @@ export const categoriesRouter = express.Router();
|
|||
|
||||
// GET categories/
|
||||
categoriesRouter.get('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
const categories: Categories = await CategoryService.findAll();
|
||||
try {
|
||||
const categories: Categories = await CategoryService.findAll();
|
||||
|
||||
res.status(200).send(categories);
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
res.status(200).send(categories);
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// GET categories/:id
|
||||
categoriesRouter.get('/:id', async (req: Request, res: Response) => {
|
||||
const id: number = parseInt(req.params.id, 10);
|
||||
const id: number = parseInt(req.params.id, 10);
|
||||
|
||||
if (!id) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
if (!id) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const category: Category = await CategoryService.find(id);
|
||||
try {
|
||||
const category: Category = await CategoryService.find(id);
|
||||
|
||||
res.status(200).send(category);
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
res.status(200).send(category);
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// GET categories/search/:term
|
||||
categoriesRouter.get('/search/:term', async (req: Request, res: Response) => {
|
||||
const term: string = req.params.term;
|
||||
const term: string = req.params.term;
|
||||
|
||||
if (!term) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
if (!term) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const categories: Categories = await CategoryService.findBySearchTerm(term);
|
||||
try {
|
||||
const categories: Categories = await CategoryService.findBySearchTerm(term);
|
||||
|
||||
res.status(200).send(categories);
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
res.status(200).send(categories);
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -7,7 +7,6 @@ import * as ContactPersonService from './contact_persons.service';
|
|||
import {Contact_Person} from './contact_person.interface';
|
||||
import {Contact_Persons} from './contact_persons.interface';
|
||||
import * as UserService from '../users/users.service';
|
||||
import * as PriceService from '../prices/prices.service';
|
||||
|
||||
|
||||
/**
|
||||
|
@ -23,111 +22,111 @@ export const contactpersonsRouter = express.Router();
|
|||
|
||||
// GET contactpersons/
|
||||
contactpersonsRouter.get('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
const contacts: Contact_Persons = await ContactPersonService.findAll();
|
||||
try {
|
||||
const contacts: Contact_Persons = await ContactPersonService.findAll();
|
||||
|
||||
res.status(200).send(contacts);
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
res.status(200).send(contacts);
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// GET contactpersons/:id
|
||||
contactpersonsRouter.get('/:id', async (req: Request, res: Response) => {
|
||||
const id: number = parseInt(req.params.id, 10);
|
||||
const id: number = parseInt(req.params.id, 10);
|
||||
|
||||
if (!id) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
if (!id) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const contact: Contact_Person = await ContactPersonService.find(id);
|
||||
try {
|
||||
const contact: Contact_Person = await ContactPersonService.find(id);
|
||||
|
||||
res.status(200).send(contact);
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
res.status(200).send(contact);
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// GET contactpersons/byvendor/:id
|
||||
contactpersonsRouter.get('/byvendor/:id', async (req: Request, res: Response) => {
|
||||
const id: number = parseInt(req.params.id, 10);
|
||||
const id: number = parseInt(req.params.id, 10);
|
||||
|
||||
if (!id) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
if (!id) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const contacts: Contact_Persons = await ContactPersonService.findByVendor(id);
|
||||
try {
|
||||
const contacts: Contact_Persons = await ContactPersonService.findByVendor(id);
|
||||
|
||||
res.status(200).send(contacts);
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
res.status(200).send(contacts);
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// POST contactpersons/
|
||||
contactpersonsRouter.post('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = req.body.session_id;
|
||||
const session_key = req.body.session_key;
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = req.body.session_id;
|
||||
const session_key = req.body.session_key;
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
|
||||
// Get required parameters
|
||||
const vendor_id = req.body.vendor_id;
|
||||
const first_name = req.body.first_name;
|
||||
const last_name = req.body.last_name;
|
||||
const gender = req.body.gender;
|
||||
const email = req.body.email;
|
||||
const phone = req.body.phone;
|
||||
// Get required parameters
|
||||
const vendor_id = req.body.vendor_id;
|
||||
const first_name = req.body.first_name;
|
||||
const last_name = req.body.last_name;
|
||||
const gender = req.body.gender;
|
||||
const email = req.body.email;
|
||||
const phone = req.body.phone;
|
||||
|
||||
const success = await ContactPersonService.createContactEntry(user.user_id, vendor_id, first_name, last_name, gender, email, phone);
|
||||
const success = await ContactPersonService.createContactEntry(user.user_id, vendor_id, first_name, last_name, gender, email, phone);
|
||||
|
||||
if (success) {
|
||||
res.status(201).send({});
|
||||
} else {
|
||||
res.status(500).send({});
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
if (success) {
|
||||
res.status(201).send({});
|
||||
} else {
|
||||
res.status(500).send({});
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// PUT contactpersons/:id
|
||||
contactpersonsRouter.put('/:id', async (req: Request, res: Response) => {
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = req.body.session_id;
|
||||
const session_key = req.body.session_key;
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = req.body.session_id;
|
||||
const session_key = req.body.session_key;
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
|
||||
// Get required parameters
|
||||
const contact_person_id = parseInt(req.params.id, 10);
|
||||
const vendor_id = req.body.vendor_id;
|
||||
const first_name = req.body.first_name;
|
||||
const last_name = req.body.last_name;
|
||||
const gender = req.body.gender;
|
||||
const email = req.body.email;
|
||||
const phone = req.body.phone;
|
||||
// Get required parameters
|
||||
const contact_person_id = parseInt(req.params.id, 10);
|
||||
const vendor_id = req.body.vendor_id;
|
||||
const first_name = req.body.first_name;
|
||||
const last_name = req.body.last_name;
|
||||
const gender = req.body.gender;
|
||||
const email = req.body.email;
|
||||
const phone = req.body.phone;
|
||||
|
||||
const success = await ContactPersonService.updateContactEntry(user.user_id, contact_person_id, vendor_id, first_name, last_name, gender, email, phone);
|
||||
const success = await ContactPersonService.updateContactEntry(user.user_id, contact_person_id, vendor_id, first_name, last_name, gender, email, phone);
|
||||
|
||||
if (success) {
|
||||
res.status(200).send({});
|
||||
} else {
|
||||
res.status(500).send({});
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
if (success) {
|
||||
res.status(200).send({});
|
||||
} else {
|
||||
res.status(500).send({});
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
import express, {Request, Response} from 'express';
|
||||
import * as CrawlingStatusService from './crawling_status.service';
|
||||
import {Crawling_Status} from './crawling_status.interface';
|
||||
import {Crawling_Statuses} from './crawling_statuses.interface';
|
||||
import * as UserService from '../users/users.service';
|
||||
|
||||
|
||||
|
@ -22,23 +21,23 @@ export const crawlingstatusRouter = express.Router();
|
|||
|
||||
// GET crawlingstatus/
|
||||
crawlingstatusRouter.get('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = (req.query.session_id ?? '').toString();
|
||||
const session_key = (req.query.session_key ?? '').toString();
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = (req.query.session_id ?? '').toString();
|
||||
const session_key = (req.query.session_key ?? '').toString();
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
|
||||
if (!user.is_admin) {
|
||||
res.status(403).send({});
|
||||
return;
|
||||
}
|
||||
if (!user.is_admin) {
|
||||
res.status(403).send({});
|
||||
return;
|
||||
}
|
||||
|
||||
const status: Crawling_Status = await CrawlingStatusService.getCurrent();
|
||||
const status: Crawling_Status = await CrawlingStatusService.getCurrent();
|
||||
|
||||
res.status(200).send(status);
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
res.status(200).send(status);
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
|
||||
import express, {Request, Response} from 'express';
|
||||
import * as FavoriteShopsService from './favoriteshops.service';
|
||||
import {FavoriteShop} from './favoriteshop.interface';
|
||||
import {FavoriteShops} from './favoriteshops.interface';
|
||||
import * as UserService from '../users/users.service';
|
||||
|
||||
|
||||
|
@ -21,86 +19,86 @@ export const favoriteshopsRouter = express.Router();
|
|||
|
||||
//GET favoriteshops/
|
||||
favoriteshopsRouter.get('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = (req.query.session_id ?? '').toString();
|
||||
const session_key = (req.query.session_key ?? '').toString();
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = (req.query.session_id ?? '').toString();
|
||||
const session_key = (req.query.session_key ?? '').toString();
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
|
||||
const priceAlarms = await FavoriteShopsService.getFavoriteShops(user.user_id);
|
||||
const priceAlarms = await FavoriteShopsService.getFavoriteShops(user.user_id);
|
||||
|
||||
res.status(200).send(priceAlarms);
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
res.status(200).send(priceAlarms);
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// POST favoriteshops/
|
||||
favoriteshopsRouter.post('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = req.body.session_id;
|
||||
const session_key = req.body.session_key;
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = req.body.session_id;
|
||||
const session_key = req.body.session_key;
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
|
||||
// Get info for price alarm creation
|
||||
const vendor_id = req.body.vendor_id;
|
||||
// Get info for price alarm creation
|
||||
const vendor_id = req.body.vendor_id;
|
||||
|
||||
if (!vendor_id) {
|
||||
// Missing
|
||||
res.status(400).send(JSON.stringify({message: 'Missing parameters'}));
|
||||
return;
|
||||
}
|
||||
if (!vendor_id) {
|
||||
// Missing
|
||||
res.status(400).send(JSON.stringify({message: 'Missing parameters'}));
|
||||
return;
|
||||
}
|
||||
|
||||
// Create price alarm
|
||||
const success = await FavoriteShopsService.createFavoriteShop(user.user_id, vendor_id);
|
||||
// Create price alarm
|
||||
const success = await FavoriteShopsService.createFavoriteShop(user.user_id, vendor_id);
|
||||
|
||||
if (success) {
|
||||
res.status(201).send(JSON.stringify({success: true}));
|
||||
return;
|
||||
} else {
|
||||
res.status(500).send(JSON.stringify({success: false}));
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
if (success) {
|
||||
res.status(201).send(JSON.stringify({success: true}));
|
||||
return;
|
||||
} else {
|
||||
res.status(500).send(JSON.stringify({success: false}));
|
||||
return;
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// DELETE favoriteshops/
|
||||
favoriteshopsRouter.delete('/:id', async (req: Request, res: Response) => {
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = (req.query.session_id ?? '').toString();
|
||||
const session_key = (req.query.session_key ?? '').toString();
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = (req.query.session_id ?? '').toString();
|
||||
const session_key = (req.query.session_key ?? '').toString();
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
|
||||
// Get info for price alarm creation
|
||||
const favorite_id = parseInt(req.params.id, 10);
|
||||
// Get info for price alarm creation
|
||||
const favorite_id = parseInt(req.params.id, 10);
|
||||
|
||||
if (!favorite_id) {
|
||||
// Missing
|
||||
res.status(400).send(JSON.stringify({message: 'Missing parameters'}));
|
||||
return;
|
||||
}
|
||||
if (!favorite_id) {
|
||||
// Missing
|
||||
res.status(400).send(JSON.stringify({message: 'Missing parameters'}));
|
||||
return;
|
||||
}
|
||||
|
||||
// Create price alarm
|
||||
const success = await FavoriteShopsService.deleteFavoriteShop(user.user_id, favorite_id);
|
||||
// Create price alarm
|
||||
const success = await FavoriteShopsService.deleteFavoriteShop(user.user_id, favorite_id);
|
||||
|
||||
if (success) {
|
||||
res.status(201).send(JSON.stringify({success: true}));
|
||||
return;
|
||||
} else {
|
||||
res.status(500).send(JSON.stringify({success: false}));
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
if (success) {
|
||||
res.status(201).send(JSON.stringify({success: true}));
|
||||
return;
|
||||
} else {
|
||||
res.status(500).send(JSON.stringify({success: false}));
|
||||
return;
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -21,50 +21,50 @@ export const manufacturersRouter = express.Router();
|
|||
|
||||
// GET manufacturers/
|
||||
manufacturersRouter.get('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
const manufacturers: Manufacturers = await ManufacturerService.findAll();
|
||||
try {
|
||||
const manufacturers: Manufacturers = await ManufacturerService.findAll();
|
||||
|
||||
res.status(200).send(manufacturers);
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
res.status(200).send(manufacturers);
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// GET manufacturers/:id
|
||||
manufacturersRouter.get('/:id', async (req: Request, res: Response) => {
|
||||
const id: number = parseInt(req.params.id, 10);
|
||||
const id: number = parseInt(req.params.id, 10);
|
||||
|
||||
if (!id) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
if (!id) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const manufacturer: Manufacturer = await ManufacturerService.find(id);
|
||||
try {
|
||||
const manufacturer: Manufacturer = await ManufacturerService.find(id);
|
||||
|
||||
res.status(200).send(manufacturer);
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
res.status(200).send(manufacturer);
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// GET manufacturers/:term
|
||||
manufacturersRouter.get('/search/:term', async (req: Request, res: Response) => {
|
||||
const term: string = req.params.term;
|
||||
const term: string = req.params.term;
|
||||
|
||||
if (!term) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
if (!term) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const manufacturer: Manufacturers = await ManufacturerService.findBySearchTerm(term);
|
||||
try {
|
||||
const manufacturer: Manufacturers = await ManufacturerService.findBySearchTerm(term);
|
||||
|
||||
res.status(200).send(manufacturer);
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
res.status(200).send(manufacturer);
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
|
||||
import express, {Request, Response} from 'express';
|
||||
import * as PriceAlarmsService from './pricealarms.service';
|
||||
import {PriceAlarm} from './pricealarm.interface';
|
||||
import {PriceAlarms} from './pricealarms.interface';
|
||||
import * as UserService from '../users/users.service';
|
||||
|
||||
|
||||
|
@ -21,114 +19,114 @@ export const pricealarmsRouter = express.Router();
|
|||
|
||||
//GET pricealarms/
|
||||
pricealarmsRouter.get('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = (req.query.session_id ?? '').toString();
|
||||
const session_key = (req.query.session_key ?? '').toString();
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = (req.query.session_id ?? '').toString();
|
||||
const session_key = (req.query.session_key ?? '').toString();
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
|
||||
const priceAlarms = await PriceAlarmsService.getPriceAlarms(user.user_id);
|
||||
const priceAlarms = await PriceAlarmsService.getPriceAlarms(user.user_id);
|
||||
|
||||
res.status(200).send(priceAlarms);
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
res.status(200).send(priceAlarms);
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// POST pricealarms/
|
||||
pricealarmsRouter.post('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = req.body.session_id;
|
||||
const session_key = req.body.session_key;
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = req.body.session_id;
|
||||
const session_key = req.body.session_key;
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
|
||||
// Get info for price alarm creation
|
||||
const product_id = req.body.product_id;
|
||||
const defined_price = req.body.defined_price;
|
||||
// Get info for price alarm creation
|
||||
const product_id = req.body.product_id;
|
||||
const defined_price = req.body.defined_price;
|
||||
|
||||
if (!product_id || !defined_price) {
|
||||
// Missing
|
||||
res.status(400).send(JSON.stringify({message: 'Missing parameters'}));
|
||||
return;
|
||||
}
|
||||
if (!product_id || !defined_price) {
|
||||
// Missing
|
||||
res.status(400).send(JSON.stringify({message: 'Missing parameters'}));
|
||||
return;
|
||||
}
|
||||
|
||||
// Create price alarm
|
||||
const success = await PriceAlarmsService.createPriceAlarm(user.user_id, product_id, defined_price);
|
||||
// Create price alarm
|
||||
const success = await PriceAlarmsService.createPriceAlarm(user.user_id, product_id, defined_price);
|
||||
|
||||
if (success) {
|
||||
res.status(201).send(JSON.stringify({success: true}));
|
||||
return;
|
||||
} else {
|
||||
res.status(500).send(JSON.stringify({success: false}));
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
if (success) {
|
||||
res.status(201).send(JSON.stringify({success: true}));
|
||||
return;
|
||||
} else {
|
||||
res.status(500).send(JSON.stringify({success: false}));
|
||||
return;
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// PUT pricealarms/
|
||||
pricealarmsRouter.put('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = req.body.session_id;
|
||||
const session_key = req.body.session_key;
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = req.body.session_id;
|
||||
const session_key = req.body.session_key;
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
|
||||
// Get info for price alarm creation
|
||||
const alarm_id = req.body.alarm_id;
|
||||
const defined_price = req.body.defined_price;
|
||||
// Get info for price alarm creation
|
||||
const alarm_id = req.body.alarm_id;
|
||||
const defined_price = req.body.defined_price;
|
||||
|
||||
if (!alarm_id || !defined_price) {
|
||||
// Missing
|
||||
res.status(400).send(JSON.stringify({message: 'Missing parameters'}));
|
||||
return;
|
||||
}
|
||||
if (!alarm_id || !defined_price) {
|
||||
// Missing
|
||||
res.status(400).send(JSON.stringify({message: 'Missing parameters'}));
|
||||
return;
|
||||
}
|
||||
|
||||
// Update price alarm
|
||||
const success = await PriceAlarmsService.updatePriceAlarm(alarm_id, user.user_id, defined_price);
|
||||
// Update price alarm
|
||||
const success = await PriceAlarmsService.updatePriceAlarm(alarm_id, user.user_id, defined_price);
|
||||
|
||||
if (success) {
|
||||
res.status(200).send(JSON.stringify({success: true}));
|
||||
return;
|
||||
} else {
|
||||
res.status(500).send(JSON.stringify({success: false}));
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
if (success) {
|
||||
res.status(200).send(JSON.stringify({success: true}));
|
||||
return;
|
||||
} else {
|
||||
res.status(500).send(JSON.stringify({success: false}));
|
||||
return;
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// DELETE pricealarms/:id
|
||||
pricealarmsRouter.delete('/:id', async (req, res) => {
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = (req.query.session_id ?? '').toString();
|
||||
const session_key = (req.query.session_key ?? '').toString();
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = (req.query.session_id ?? '').toString();
|
||||
const session_key = (req.query.session_key ?? '').toString();
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
|
||||
const id: number = parseInt(req.params.id, 10);
|
||||
const id: number = parseInt(req.params.id, 10);
|
||||
|
||||
const success = await PriceAlarmsService.deletePriceAlarm(id, user.user_id);
|
||||
const success = await PriceAlarmsService.deletePriceAlarm(id, user.user_id);
|
||||
|
||||
if (success) {
|
||||
res.status(200).send(JSON.stringify({success: true}));
|
||||
return;
|
||||
} else {
|
||||
res.status(500).send(JSON.stringify({success: false}));
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
if (success) {
|
||||
res.status(200).send(JSON.stringify({success: true}));
|
||||
return;
|
||||
} else {
|
||||
res.status(500).send(JSON.stringify({success: false}));
|
||||
return;
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -22,109 +22,109 @@ export const pricesRouter = express.Router();
|
|||
|
||||
// GET prices/
|
||||
pricesRouter.get('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
let prices: Prices = [];
|
||||
const product = req.query.product;
|
||||
const vendor = req.query.vendor;
|
||||
const type = req.query.type;
|
||||
try {
|
||||
let prices: Prices = [];
|
||||
const product = req.query.product;
|
||||
const vendor = req.query.vendor;
|
||||
const type = req.query.type;
|
||||
|
||||
if (product) {
|
||||
if (vendor) {
|
||||
prices = await PriceService.findByVendor(<string> product, <string> vendor, <string> type);
|
||||
} else {
|
||||
prices = await PriceService.findByType(<string> product, <string> type);
|
||||
}
|
||||
} else {
|
||||
prices = await PriceService.findAll();
|
||||
}
|
||||
if (product) {
|
||||
if (vendor) {
|
||||
prices = await PriceService.findByVendor(<string>product, <string>vendor, <string>type);
|
||||
} else {
|
||||
prices = await PriceService.findByType(<string>product, <string>type);
|
||||
}
|
||||
} else {
|
||||
prices = await PriceService.findAll();
|
||||
}
|
||||
|
||||
res.status(200).send(prices);
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
res.status(200).send(prices);
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// GET prices/:id
|
||||
pricesRouter.get('/:id', async (req: Request, res: Response) => {
|
||||
const id: number = parseInt(req.params.id, 10);
|
||||
const id: number = parseInt(req.params.id, 10);
|
||||
|
||||
if (!id) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
if (!id) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const price: Price = await PriceService.find(id);
|
||||
try {
|
||||
const price: Price = await PriceService.find(id);
|
||||
|
||||
res.status(200).send(price);
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
res.status(200).send(price);
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// GET prices/bestDeals
|
||||
pricesRouter.get('/bestDeals/:amount', async (req: Request, res: Response) => {
|
||||
const amount: number = parseInt(req.params.amount, 10);
|
||||
const amount: number = parseInt(req.params.amount, 10);
|
||||
|
||||
if (!amount) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
if (!amount) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const prices: Prices = await PriceService.getBestDeals(amount);
|
||||
try {
|
||||
const prices: Prices = await PriceService.getBestDeals(amount);
|
||||
|
||||
res.status(200).send(prices);
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
res.status(200).send(prices);
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// GET prices/byProduct/list/[]
|
||||
pricesRouter.get('/byProduct/list/:ids', async (req: Request, res: Response) => {
|
||||
const productIds: [number] = JSON.parse(req.params.ids);
|
||||
const productIds: [number] = JSON.parse(req.params.ids);
|
||||
|
||||
if (!productIds) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
if (!productIds) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const prices: Prices = await PriceService.findListByProducts(productIds);
|
||||
try {
|
||||
const prices: Prices = await PriceService.findListByProducts(productIds);
|
||||
|
||||
res.status(200).send(prices);
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
res.status(200).send(prices);
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// POST prices/
|
||||
pricesRouter.post('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = req.body.session_id;
|
||||
const session_key = req.body.session_key;
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = req.body.session_id;
|
||||
const session_key = req.body.session_key;
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
|
||||
// Get required parameters
|
||||
const vendor_id = req.body.vendor_id;
|
||||
const product_id = req.body.product_id;
|
||||
const price_in_cents = req.body.price_in_cents;
|
||||
// Get required parameters
|
||||
const vendor_id = req.body.vendor_id;
|
||||
const product_id = req.body.product_id;
|
||||
const price_in_cents = req.body.price_in_cents;
|
||||
|
||||
const success = await PriceService.createPriceEntry(user.user_id, vendor_id, product_id, price_in_cents);
|
||||
const success = await PriceService.createPriceEntry(user.user_id, vendor_id, product_id, price_in_cents);
|
||||
|
||||
if (success) {
|
||||
res.status(201).send({});
|
||||
} else {
|
||||
res.status(500).send({});
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
if (success) {
|
||||
res.status(201).send({});
|
||||
} else {
|
||||
res.status(500).send({});
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -21,111 +21,111 @@ export const productsRouter = express.Router();
|
|||
|
||||
// GET products/
|
||||
productsRouter.get('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
const products: Products = await ProductService.findAll();
|
||||
try {
|
||||
const products: Products = await ProductService.findAll();
|
||||
|
||||
res.status(200).send(products);
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
res.status(200).send(products);
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// GET products/:id
|
||||
productsRouter.get('/:id', async (req: Request, res: Response) => {
|
||||
const id: number = parseInt(req.params.id, 10);
|
||||
const id: number = parseInt(req.params.id, 10);
|
||||
|
||||
if (!id) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
if (!id) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const product: Product = await ProductService.find(id);
|
||||
try {
|
||||
const product: Product = await ProductService.find(id);
|
||||
|
||||
res.status(200).send(product);
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
res.status(200).send(product);
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// GET products/search/:term
|
||||
productsRouter.get('/search/:term', async (req: Request, res: Response) => {
|
||||
const term: string = req.params.term;
|
||||
const term: string = req.params.term;
|
||||
|
||||
if (!term) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
if (!term) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const products: Products = await ProductService.findBySearchTerm(term);
|
||||
try {
|
||||
const products: Products = await ProductService.findBySearchTerm(term);
|
||||
|
||||
res.status(200).send(products);
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
res.status(200).send(products);
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// GET products/list/[1,2,3]
|
||||
productsRouter.get('/list/:ids', async (req: Request, res: Response) => {
|
||||
const ids: [number] = JSON.parse(req.params.ids);
|
||||
const ids: [number] = JSON.parse(req.params.ids);
|
||||
|
||||
if (!ids) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
if (!ids) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const products: Products = await ProductService.findList(ids);
|
||||
try {
|
||||
const products: Products = await ProductService.findList(ids);
|
||||
|
||||
res.status(200).send(products);
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
res.status(200).send(products);
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// GET products/vendor/:id
|
||||
productsRouter.get('/vendor/:id', async (req: Request, res: Response) => {
|
||||
const id: number = parseInt(req.params.id, 10);
|
||||
const id: number = parseInt(req.params.id, 10);
|
||||
|
||||
if (!id) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
if (!id) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const products: Products = await ProductService.findByVendor(id);
|
||||
try {
|
||||
const products: Products = await ProductService.findByVendor(id);
|
||||
|
||||
res.status(200).send(products);
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
res.status(200).send(products);
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// POST products/
|
||||
productsRouter.post('/', async (req: Request, res: Response) => {
|
||||
const asin: string = req.body.asin;
|
||||
const asin: string = req.body.asin;
|
||||
|
||||
if (!asin) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
if (!asin) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const result: boolean = await ProductService.addNewProduct(asin);
|
||||
try {
|
||||
const result: boolean = await ProductService.addNewProduct(asin);
|
||||
|
||||
if (result) {
|
||||
res.status(201).send({});
|
||||
} else {
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
if (result) {
|
||||
res.status(201).send({});
|
||||
} else {
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
import express, {Request, Response} from 'express';
|
||||
import * as UserService from './users.service';
|
||||
import {User} from './user.interface';
|
||||
import {Users} from './users.interface';
|
||||
import {Session} from './session.interface';
|
||||
|
||||
|
||||
|
@ -22,100 +21,100 @@ export const usersRouter = express.Router();
|
|||
|
||||
// POST users/register
|
||||
usersRouter.post('/register', async (req: Request, res: Response) => {
|
||||
try {
|
||||
const username: string = req.body.username;
|
||||
const password: string = req.body.password;
|
||||
const email: string = req.body.email;
|
||||
const ip: string = req.connection.remoteAddress ?? '';
|
||||
try {
|
||||
const username: string = req.body.username;
|
||||
const password: string = req.body.password;
|
||||
const email: string = req.body.email;
|
||||
const ip: string = req.connection.remoteAddress ?? '';
|
||||
|
||||
if (!username || !password || !email) {
|
||||
// Missing
|
||||
res.status(400).send(JSON.stringify({message: 'Missing parameters'}));
|
||||
return;
|
||||
}
|
||||
if (!username || !password || !email) {
|
||||
// Missing
|
||||
res.status(400).send(JSON.stringify({message: 'Missing parameters'}));
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if username and / or email are already used
|
||||
const status = await UserService.checkUsernameAndEmail(username, email);
|
||||
// Check if username and / or email are already used
|
||||
const status = await UserService.checkUsernameAndEmail(username, email);
|
||||
|
||||
if (status.hasProblems) {
|
||||
// Username and/or email are duplicates, return error
|
||||
res.status(400).send(JSON.stringify({messages: status.messages, codes: status.codes}));
|
||||
return;
|
||||
}
|
||||
if (status.hasProblems) {
|
||||
// Username and/or email are duplicates, return error
|
||||
res.status(400).send(JSON.stringify({messages: status.messages, codes: status.codes}));
|
||||
return;
|
||||
}
|
||||
|
||||
// Create the user and a session
|
||||
const session: Session = await UserService.createUser(username, password, email, ip);
|
||||
// Create the user and a session
|
||||
const session: Session = await UserService.createUser(username, password, email, ip);
|
||||
|
||||
// Send the session details back to the user
|
||||
res.status(201).send({
|
||||
session_id: session.session_id,
|
||||
session_key: session.session_key
|
||||
});
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
// Send the session details back to the user
|
||||
res.status(201).send({
|
||||
session_id: session.session_id,
|
||||
session_key: session.session_key
|
||||
});
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// POST users/login
|
||||
usersRouter.post('/login', async (req: Request, res: Response) => {
|
||||
try {
|
||||
const username: string = req.body.username;
|
||||
const password: string = req.body.password;
|
||||
const ip: string = req.connection.remoteAddress ?? '';
|
||||
try {
|
||||
const username: string = req.body.username;
|
||||
const password: string = req.body.password;
|
||||
const ip: string = req.connection.remoteAddress ?? '';
|
||||
|
||||
if (!username || !password) {
|
||||
// Missing
|
||||
res.status(400).send(JSON.stringify({message: 'Missing parameters'}));
|
||||
return;
|
||||
}
|
||||
if (!username || !password) {
|
||||
// Missing
|
||||
res.status(400).send(JSON.stringify({message: 'Missing parameters'}));
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the user entry and create a session
|
||||
const session: Session = await UserService.login(username, password, ip);
|
||||
// Update the user entry and create a session
|
||||
const session: Session = await UserService.login(username, password, ip);
|
||||
|
||||
if (!session.session_id) {
|
||||
// Error logging in, probably wrong username / password
|
||||
res.status(401).send(JSON.stringify({messages: ['Wrong username and / or password'], codes: [1, 4]}));
|
||||
return;
|
||||
}
|
||||
if (!session.session_id) {
|
||||
// Error logging in, probably wrong username / password
|
||||
res.status(401).send(JSON.stringify({messages: ['Wrong username and / or password'], codes: [1, 4]}));
|
||||
return;
|
||||
}
|
||||
|
||||
// Send the session details back to the user
|
||||
res.status(200).send({
|
||||
session_id: session.session_id,
|
||||
session_key: session.session_key
|
||||
});
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
// Send the session details back to the user
|
||||
res.status(200).send({
|
||||
session_id: session.session_id,
|
||||
session_key: session.session_key
|
||||
});
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// POST users/checkSessionValid
|
||||
usersRouter.post('/checkSessionValid', async (req: Request, res: Response) => {
|
||||
try {
|
||||
const ip: string = req.connection.remoteAddress ?? '';
|
||||
const session_id = req.body.session_id;
|
||||
const session_key = req.body.session_key;
|
||||
try {
|
||||
const ip: string = req.connection.remoteAddress ?? '';
|
||||
const session_id = req.body.session_id;
|
||||
const session_key = req.body.session_key;
|
||||
|
||||
if(!session_id || !session_key) {
|
||||
// Error logging in, probably wrong username / password
|
||||
res.status(401).send(JSON.stringify({messages: ['No session detected'], codes: [5]}));
|
||||
return;
|
||||
}
|
||||
if (!session_id || !session_key) {
|
||||
// Error logging in, probably wrong username / password
|
||||
res.status(401).send(JSON.stringify({messages: ['No session detected'], codes: [5]}));
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the user entry and create a session
|
||||
const user: User = await UserService.checkSession(session_id, session_key, ip);
|
||||
// Update the user entry and create a session
|
||||
const user: User = await UserService.checkSession(session_id, session_key, ip);
|
||||
|
||||
if (!user.user_id) {
|
||||
// Error logging in, probably wrong username / password
|
||||
res.status(401).send(JSON.stringify({messages: ['Invalid session'], codes: [5]}));
|
||||
return;
|
||||
}
|
||||
if (!user.user_id) {
|
||||
// Error logging in, probably wrong username / password
|
||||
res.status(401).send(JSON.stringify({messages: ['Invalid session'], codes: [5]}));
|
||||
return;
|
||||
}
|
||||
|
||||
// Send the session details back to the user
|
||||
res.status(200).send(user);
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
// Send the session details back to the user
|
||||
res.status(200).send(user);
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
|
196
src/models/betterzon/vendors/vendors.router.ts
vendored
196
src/models/betterzon/vendors/vendors.router.ts
vendored
|
@ -22,144 +22,144 @@ export const vendorsRouter = express.Router();
|
|||
|
||||
// GET vendors/
|
||||
vendorsRouter.get('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
const vendors: Vendors = await VendorService.findAll();
|
||||
try {
|
||||
const vendors: Vendors = await VendorService.findAll();
|
||||
|
||||
res.status(200).send(vendors);
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
res.status(200).send(vendors);
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// GET vendors/managed
|
||||
vendorsRouter.get('/managed', async (req: Request, res: Response) => {
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = (req.query.session_id ?? '').toString();
|
||||
const session_key = (req.query.session_key ?? '').toString();
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = (req.query.session_id ?? '').toString();
|
||||
const session_key = (req.query.session_key ?? '').toString();
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
|
||||
const vendors = await VendorService.getManagedShops(user.user_id);
|
||||
const vendors = await VendorService.getManagedShops(user.user_id);
|
||||
|
||||
res.status(200).send(vendors);
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
res.status(200).send(vendors);
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// GET vendors/:id
|
||||
vendorsRouter.get('/:id', async (req: Request, res: Response) => {
|
||||
const id: number = parseInt(req.params.id, 10);
|
||||
const id: number = parseInt(req.params.id, 10);
|
||||
|
||||
if (!id) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
if (!id) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const vendor: Vendor = await VendorService.find(id);
|
||||
try {
|
||||
const vendor: Vendor = await VendorService.find(id);
|
||||
|
||||
res.status(200).send(vendor);
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
res.status(200).send(vendor);
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// GET vendors/search/:term
|
||||
vendorsRouter.get('/search/:term', async (req: Request, res: Response) => {
|
||||
const term: string = req.params.term;
|
||||
const term: string = req.params.term;
|
||||
|
||||
if (!term) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
if (!term) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const vendors: Vendors = await VendorService.findBySearchTerm(term);
|
||||
try {
|
||||
const vendors: Vendors = await VendorService.findBySearchTerm(term);
|
||||
|
||||
res.status(200).send(vendors);
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
res.status(200).send(vendors);
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// PUT vendors/manage/deactivatelisting
|
||||
vendorsRouter.put('/manage/deactivatelisting', async (req: Request, res: Response) => {
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = req.body.session_id;
|
||||
const session_key = req.body.session_key;
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = req.body.session_id;
|
||||
const session_key = req.body.session_key;
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
|
||||
// Get required parameters
|
||||
const vendor_id = req.body.vendor_id;
|
||||
const product_id = req.body.product_id;
|
||||
// Get required parameters
|
||||
const vendor_id = req.body.vendor_id;
|
||||
const product_id = req.body.product_id;
|
||||
|
||||
const success = await VendorService.deactivateListing(user.user_id, vendor_id, product_id);
|
||||
const success = await VendorService.deactivateListing(user.user_id, vendor_id, product_id);
|
||||
|
||||
if (success) {
|
||||
res.status(200).send({});
|
||||
} else {
|
||||
res.status(500).send({});
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
if (success) {
|
||||
res.status(200).send({});
|
||||
} else {
|
||||
res.status(500).send({});
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// PUT vendors/manage/shop/deactivate/:id
|
||||
vendorsRouter.put('/manage/shop/deactivate/:id', async (req: Request, res: Response) => {
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = req.body.session_id;
|
||||
const session_key = req.body.session_key;
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = req.body.session_id;
|
||||
const session_key = req.body.session_key;
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
|
||||
// Get required parameters
|
||||
const vendor_id = parseInt(req.params.id, 10);
|
||||
// Get required parameters
|
||||
const vendor_id = parseInt(req.params.id, 10);
|
||||
|
||||
const success = await VendorService.setShopStatus(user.user_id, vendor_id, false);
|
||||
const success = await VendorService.setShopStatus(user.user_id, vendor_id, false);
|
||||
|
||||
if (success) {
|
||||
res.status(200).send({});
|
||||
} else {
|
||||
res.status(500).send({});
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
if (success) {
|
||||
res.status(200).send({});
|
||||
} else {
|
||||
res.status(500).send({});
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
||||
// PUT vendors/manage/shop/activate/:id
|
||||
vendorsRouter.put('/manage/shop/activate/:id', async (req: Request, res: Response) => {
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = req.body.session_id;
|
||||
const session_key = req.body.session_key;
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
try {
|
||||
// Authenticate user
|
||||
const user_ip = req.connection.remoteAddress ?? '';
|
||||
const session_id = req.body.session_id;
|
||||
const session_key = req.body.session_key;
|
||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||
|
||||
// Get required parameters
|
||||
const vendor_id = parseInt(req.params.id, 10);
|
||||
// Get required parameters
|
||||
const vendor_id = parseInt(req.params.id, 10);
|
||||
|
||||
const success = await VendorService.setShopStatus(user.user_id, vendor_id, true);
|
||||
const success = await VendorService.setShopStatus(user.user_id, vendor_id, true);
|
||||
|
||||
if (success) {
|
||||
res.status(200).send({});
|
||||
} else {
|
||||
res.status(500).send({});
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
if (success) {
|
||||
res.status(200).send({});
|
||||
} else {
|
||||
res.status(500).send({});
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.log('Error handling a request: ' + e.message);
|
||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -21,15 +21,15 @@ crrRouter.use('/comments', routeCommentsRouter);
|
|||
crrRouter.use('/ratings', routeRatingsRouter);
|
||||
|
||||
crrRouter.get('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
res.status(200).send('Pluto Development Climbing Route Rating API Endpoint');
|
||||
} catch (e) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
try {
|
||||
res.status(200).send('Pluto Development Climbing Route Rating API Endpoint');
|
||||
} catch (e: any) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -51,19 +51,19 @@ export const climbingGymRouter = express.Router();
|
|||
* description: A server error occurred. Please try again. If this issue persists, contact the admin.
|
||||
*/
|
||||
climbingGymRouter.get('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
const gyms: ClimbingGym[] = await GymService.findAll();
|
||||
try {
|
||||
const gyms: ClimbingGym[] = await GymService.findAll();
|
||||
|
||||
res.status(200).send(gyms);
|
||||
} catch (e) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
res.status(200).send(gyms);
|
||||
} catch (e: any) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -116,37 +116,37 @@ climbingGymRouter.get('/', async (req: Request, res: Response) => {
|
|||
* example: P0_ey[...]bVu
|
||||
*/
|
||||
climbingGymRouter.post('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
let name = req.query.name as string;
|
||||
let city = req.query.city as string;
|
||||
let captcha_token = req.query['hcaptcha_response'] as string;
|
||||
try {
|
||||
let name = req.query.name as string;
|
||||
let city = req.query.city as string;
|
||||
let captcha_token = req.query['hcaptcha_response'] as string;
|
||||
|
||||
if (!name || !city || !captcha_token) {
|
||||
res.status(400).send({'message': 'Missing parameters'});
|
||||
return;
|
||||
}
|
||||
if (!name || !city || !captcha_token) {
|
||||
res.status(400).send({'message': 'Missing parameters'});
|
||||
return;
|
||||
}
|
||||
|
||||
// Verify captcha
|
||||
let success = await verifyCaptcha(captcha_token);
|
||||
if (!success) {
|
||||
res.status(403).send({'message': 'Invalid Captcha. Please try again.'});
|
||||
return;
|
||||
}
|
||||
// Verify captcha
|
||||
let success = await verifyCaptcha(captcha_token);
|
||||
if (!success) {
|
||||
res.status(403).send({'message': 'Invalid Captcha. Please try again.'});
|
||||
return;
|
||||
}
|
||||
|
||||
let result = await GymService.createGym(name, city);
|
||||
let result = await GymService.createGym(name, city);
|
||||
|
||||
if (result) {
|
||||
res.status(201).send({'gym_id': result});
|
||||
} else {
|
||||
res.status(500).send({});
|
||||
}
|
||||
} catch (e) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
if (result) {
|
||||
res.status(201).send({'gym_id': result});
|
||||
} else {
|
||||
res.status(500).send({});
|
||||
}
|
||||
} catch (e: any) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -55,19 +55,19 @@ export const climbingRoutesRouter = express.Router();
|
|||
* description: A server error occurred. Please try again. If this issue persists, contact the admin.
|
||||
*/
|
||||
climbingRoutesRouter.get('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
const routes: ClimbingRoute[] = await RouteService.findAll();
|
||||
try {
|
||||
const routes: ClimbingRoute[] = await RouteService.findAll();
|
||||
|
||||
res.status(200).send(routes);
|
||||
} catch (e) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
res.status(200).send(routes);
|
||||
} catch (e: any) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -120,21 +120,21 @@ climbingRoutesRouter.get('/', async (req: Request, res: Response) => {
|
|||
* example: duck-score-guide
|
||||
*/
|
||||
climbingRoutesRouter.get('/:id', async (req: Request, res: Response) => {
|
||||
try {
|
||||
let route_id = req.params.id;
|
||||
try {
|
||||
let route_id = req.params.id;
|
||||
|
||||
const route: ClimbingRoute = await RouteService.findById(route_id);
|
||||
const route: ClimbingRoute = await RouteService.findById(route_id);
|
||||
|
||||
res.status(200).send(route);
|
||||
} catch (e) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
res.status(200).send(route);
|
||||
} catch (e: any) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -194,33 +194,33 @@ climbingRoutesRouter.get('/:id', async (req: Request, res: Response) => {
|
|||
* example: P0_ey[...]bVu
|
||||
*/
|
||||
climbingRoutesRouter.post('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
let gym_id = Number(req.query.gym_id);
|
||||
let name = req.query.name as string;
|
||||
let difficulty = req.query.difficulty as string;
|
||||
let captcha_token = req.query['hcaptcha_response'] as string;
|
||||
try {
|
||||
let gym_id = Number(req.query.gym_id);
|
||||
let name = req.query.name as string;
|
||||
let difficulty = req.query.difficulty as string;
|
||||
let captcha_token = req.query['hcaptcha_response'] as string;
|
||||
|
||||
if (isNaN(gym_id) || !name || !difficulty || !captcha_token) {
|
||||
res.status(400).send({'message': 'Missing parameters'});
|
||||
return;
|
||||
}
|
||||
if (isNaN(gym_id) || !name || !difficulty || !captcha_token) {
|
||||
res.status(400).send({'message': 'Missing parameters'});
|
||||
return;
|
||||
}
|
||||
|
||||
// Verify captcha
|
||||
if (!await verifyCaptcha(captcha_token)) {
|
||||
res.status(403).send({'message': 'Invalid Captcha. Please try again.'});
|
||||
return;
|
||||
}
|
||||
// Verify captcha
|
||||
if (!await verifyCaptcha(captcha_token)) {
|
||||
res.status(403).send({'message': 'Invalid Captcha. Please try again.'});
|
||||
return;
|
||||
}
|
||||
|
||||
let route_id = await RouteService.createRoute(gym_id, name, difficulty);
|
||||
let route_id = await RouteService.createRoute(gym_id, name, difficulty);
|
||||
|
||||
res.status(201).send({'route_id': route_id});
|
||||
} catch (e) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
res.status(201).send({'route_id': route_id});
|
||||
} catch (e: any) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -53,21 +53,21 @@ export const routeCommentsRouter = express.Router();
|
|||
* example: duck-score-guide
|
||||
*/
|
||||
routeCommentsRouter.get('/by/route/:id', async (req: Request, res: Response) => {
|
||||
try {
|
||||
let route_id = req.params.id;
|
||||
try {
|
||||
let route_id = req.params.id;
|
||||
|
||||
const comments: RouteComment[] = await CommentService.findByRoute(route_id);
|
||||
const comments: RouteComment[] = await CommentService.findByRoute(route_id);
|
||||
|
||||
res.status(200).send(comments);
|
||||
} catch (e) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
res.status(200).send(comments);
|
||||
} catch (e: any) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -120,36 +120,36 @@ routeCommentsRouter.get('/by/route/:id', async (req: Request, res: Response) =>
|
|||
* example: P0_ey[...]bVu
|
||||
*/
|
||||
routeCommentsRouter.post('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
let route_id = req.query.route_id as string;
|
||||
let comment = req.query.comment as string;
|
||||
let captcha_token = req.query['hcaptcha_response'] as string;
|
||||
try {
|
||||
let route_id = req.query.route_id as string;
|
||||
let comment = req.query.comment as string;
|
||||
let captcha_token = req.query['hcaptcha_response'] as string;
|
||||
|
||||
if (!route_id || !comment || !captcha_token) {
|
||||
res.status(400).send({'message': 'Missing parameters'});
|
||||
return;
|
||||
}
|
||||
if (!route_id || !comment || !captcha_token) {
|
||||
res.status(400).send({'message': 'Missing parameters'});
|
||||
return;
|
||||
}
|
||||
|
||||
// Verify captcha
|
||||
if (!await verifyCaptcha(captcha_token)) {
|
||||
res.status(403).send({'message': 'Invalid Captcha. Please try again.'});
|
||||
return;
|
||||
}
|
||||
// Verify captcha
|
||||
if (!await verifyCaptcha(captcha_token)) {
|
||||
res.status(403).send({'message': 'Invalid Captcha. Please try again.'});
|
||||
return;
|
||||
}
|
||||
|
||||
let result = await CommentService.createComment(route_id, comment);
|
||||
let result = await CommentService.createComment(route_id, comment);
|
||||
|
||||
if (result) {
|
||||
res.status(201).send({'comment_id': result});
|
||||
} else {
|
||||
res.status(500).send({});
|
||||
}
|
||||
} catch (e) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
if (result) {
|
||||
res.status(201).send({'comment_id': result});
|
||||
} else {
|
||||
res.status(500).send({});
|
||||
}
|
||||
} catch (e: any) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -38,21 +38,21 @@ export const routeRatingsRouter = express.Router();
|
|||
* example: duck-score-guide
|
||||
*/
|
||||
routeRatingsRouter.get('/by/route/:id', async (req: Request, res: Response) => {
|
||||
try {
|
||||
let route_id = req.params.id;
|
||||
try {
|
||||
let route_id = req.params.id;
|
||||
|
||||
let rating = await RatingService.getStarsForRoute(route_id);
|
||||
let rating = await RatingService.getStarsForRoute(route_id);
|
||||
|
||||
res.status(200).send({'rating': rating});
|
||||
} catch (e) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
res.status(200).send({'rating': rating});
|
||||
} catch (e: any) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -105,36 +105,36 @@ routeRatingsRouter.get('/by/route/:id', async (req: Request, res: Response) => {
|
|||
* example: P0_ey[...]bVu
|
||||
*/
|
||||
routeRatingsRouter.post('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
let route_id = req.query.route_id as string;
|
||||
let stars = Number(req.query.stars);
|
||||
let captcha_token = req.query['hcaptcha_response'] as string;
|
||||
try {
|
||||
let route_id = req.query.route_id as string;
|
||||
let stars = Number(req.query.stars);
|
||||
let captcha_token = req.query['hcaptcha_response'] as string;
|
||||
|
||||
if (!route_id || isNaN(stars) || !captcha_token) {
|
||||
res.status(400).send({'message': 'Missing parameters'});
|
||||
return;
|
||||
}
|
||||
if (!route_id || isNaN(stars) || !captcha_token) {
|
||||
res.status(400).send({'message': 'Missing parameters'});
|
||||
return;
|
||||
}
|
||||
|
||||
// Verify captcha
|
||||
if (!await verifyCaptcha(captcha_token)) {
|
||||
res.status(403).send({'message': 'Invalid Captcha. Please try again.'});
|
||||
return;
|
||||
}
|
||||
// Verify captcha
|
||||
if (!await verifyCaptcha(captcha_token)) {
|
||||
res.status(403).send({'message': 'Invalid Captcha. Please try again.'});
|
||||
return;
|
||||
}
|
||||
|
||||
let result = await RatingService.createRating(route_id, stars);
|
||||
let result = await RatingService.createRating(route_id, stars);
|
||||
|
||||
if (result) {
|
||||
res.status(201).send({'rating_id': result});
|
||||
} else {
|
||||
res.status(500).send({});
|
||||
}
|
||||
} catch (e) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
if (result) {
|
||||
res.status(201).send({'rating_id': result});
|
||||
} else {
|
||||
res.status(500).send({});
|
||||
}
|
||||
} catch (e: any) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -12,37 +12,37 @@ import * as ChangeService from './changes/changes.service';
|
|||
export const dhbwRaPlaChangesRouter = express.Router();
|
||||
|
||||
dhbwRaPlaChangesRouter.get('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
let week = (req.query.week ?? '').toString();
|
||||
try {
|
||||
let week = (req.query.week ?? '').toString();
|
||||
|
||||
let changes = await ChangeService.getChanges('TINF19B4', week);
|
||||
let changes = await ChangeService.getChanges('TINF19B4', week);
|
||||
|
||||
res.status(200).send(changes);
|
||||
} catch (e) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
res.status(200).send(changes);
|
||||
} catch (e: any) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
dhbwRaPlaChangesRouter.get('/:id', async (req: Request, res: Response) => {
|
||||
try {
|
||||
let id: string = (req.params.id ?? '').toString();
|
||||
try {
|
||||
let id: string = (req.params.id ?? '').toString();
|
||||
|
||||
let changes = await ChangeService.getEventById('TINF19B4', id);
|
||||
let changes = await ChangeService.getEventById('TINF19B4', id);
|
||||
|
||||
res.status(200).send(changes);
|
||||
} catch (e) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
res.status(200).send(changes);
|
||||
} catch (e: any) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -15,15 +15,15 @@ export const dhbwServiceRouter = express.Router();
|
|||
dhbwServiceRouter.use('/generalInfo', generalInfoRouter);
|
||||
|
||||
dhbwServiceRouter.get('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
res.status(200).send('Pluto Development DHBW Service App API Endpoint');
|
||||
} catch (e) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
try {
|
||||
res.status(200).send('Pluto Development DHBW Service App API Endpoint');
|
||||
} catch (e: any) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -11,29 +11,29 @@ import {Guid} from 'guid-typescript';
|
|||
export const generalInfoRouter = express.Router();
|
||||
|
||||
generalInfoRouter.get('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
res.status(200).send('GET generalInfo v2.1');
|
||||
} catch (e) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
try {
|
||||
res.status(200).send('GET generalInfo v2.1');
|
||||
} catch (e: any) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
generalInfoRouter.post('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
res.status(200).send('POST generalInfo v2.1');
|
||||
} catch (e) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
try {
|
||||
res.status(200).send('POST generalInfo v2.1');
|
||||
} catch (e: any) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -27,15 +27,15 @@ partyPlanerRouter.use('/session', sessionRouter);
|
|||
partyPlanerRouter.use('/user', userRouter);
|
||||
|
||||
partyPlanerRouter.get('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
res.status(200).send('Pluto Development PartyPlaner API Endpoint V2');
|
||||
} catch (e) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
try {
|
||||
res.status(200).send('Pluto Development PartyPlaner API Endpoint V2');
|
||||
} catch (e: any) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -13,39 +13,39 @@ import {Guid} from 'guid-typescript';
|
|||
export const eventRouter = express.Router();
|
||||
|
||||
eventRouter.get('/:isDevCall', async (req: Request, res: Response) => {
|
||||
try {
|
||||
throw new Error('Test');
|
||||
let userId = (req.query.userId ?? '').toString();
|
||||
let sessionId = (req.query.sessionId ?? '').toString();
|
||||
let sessionKey = (req.query.sessionKey ?? '').toString();
|
||||
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
||||
try {
|
||||
throw new Error('Test');
|
||||
let userId = (req.query.userId ?? '').toString();
|
||||
let sessionId = (req.query.sessionId ?? '').toString();
|
||||
let sessionKey = (req.query.sessionKey ?? '').toString();
|
||||
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
||||
|
||||
if (userId === '' || sessionId === '' || sessionKey === '') {
|
||||
res.status(400).send({
|
||||
'status': 'WRONG_PARAMS',
|
||||
'message': 'Missing or wrong parameters'
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (userId === '' || sessionId === '' || sessionKey === '') {
|
||||
res.status(400).send({
|
||||
'status': 'WRONG_PARAMS',
|
||||
'message': 'Missing or wrong parameters'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!await UserService.checkSession(useDev, userId, sessionId, sessionKey)) {
|
||||
res.status(403).send({
|
||||
'status': 'INVALID_SESSION',
|
||||
'message': 'The user or session could not be found or the session is invalid'
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!await UserService.checkSession(useDev, userId, sessionId, sessionKey)) {
|
||||
res.status(403).send({
|
||||
'status': 'INVALID_SESSION',
|
||||
'message': 'The user or session could not be found or the session is invalid'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
let data = await EventService.getEventData(useDev, userId);
|
||||
let data = await EventService.getEventData(useDev, userId);
|
||||
|
||||
res.status(200).send(data);
|
||||
} catch (e) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
res.status(200).send(data);
|
||||
} catch (e: any) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -13,38 +13,38 @@ import {Guid} from 'guid-typescript';
|
|||
export const friendshipRouter = express.Router();
|
||||
|
||||
friendshipRouter.get('/:isDevCall', async (req: Request, res: Response) => {
|
||||
try {
|
||||
let userId = (req.query.userId ?? '').toString();
|
||||
let sessionId = (req.query.sessionId ?? '').toString();
|
||||
let sessionKey = (req.query.sessionKey ?? '').toString();
|
||||
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
||||
try {
|
||||
let userId = (req.query.userId ?? '').toString();
|
||||
let sessionId = (req.query.sessionId ?? '').toString();
|
||||
let sessionKey = (req.query.sessionKey ?? '').toString();
|
||||
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
||||
|
||||
if (userId === '' || sessionId === '' || sessionKey === '') {
|
||||
res.status(400).send({
|
||||
'status': 'WRONG_PARAMS',
|
||||
'message': 'Missing or wrong parameters'
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (userId === '' || sessionId === '' || sessionKey === '') {
|
||||
res.status(400).send({
|
||||
'status': 'WRONG_PARAMS',
|
||||
'message': 'Missing or wrong parameters'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!await UserService.checkSession(useDev, userId, sessionId, sessionKey)) {
|
||||
res.status(403).send({
|
||||
'status': 'INVALID_SESSION',
|
||||
'message': 'The user or session could not be found or the session is invalid'
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!await UserService.checkSession(useDev, userId, sessionId, sessionKey)) {
|
||||
res.status(403).send({
|
||||
'status': 'INVALID_SESSION',
|
||||
'message': 'The user or session could not be found or the session is invalid'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
let data = await FriendshipService.getFriendshipData(useDev, userId);
|
||||
let data = await FriendshipService.getFriendshipData(useDev, userId);
|
||||
|
||||
res.status(200).send(data);
|
||||
} catch (e) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
res.status(200).send(data);
|
||||
} catch (e: any) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -13,38 +13,38 @@ import {Guid} from 'guid-typescript';
|
|||
export const inviteRouter = express.Router();
|
||||
|
||||
inviteRouter.get('/:isDevCall', async (req: Request, res: Response) => {
|
||||
try {
|
||||
let userId = (req.query.userId ?? '').toString();
|
||||
let sessionId = (req.query.sessionId ?? '').toString();
|
||||
let sessionKey = (req.query.sessionKey ?? '').toString();
|
||||
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
||||
try {
|
||||
let userId = (req.query.userId ?? '').toString();
|
||||
let sessionId = (req.query.sessionId ?? '').toString();
|
||||
let sessionKey = (req.query.sessionKey ?? '').toString();
|
||||
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
||||
|
||||
if (userId === '' || sessionId === '' || sessionKey === '') {
|
||||
res.status(400).send({
|
||||
'status': 'WRONG_PARAMS',
|
||||
'message': 'Missing or wrong parameters'
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (userId === '' || sessionId === '' || sessionKey === '') {
|
||||
res.status(400).send({
|
||||
'status': 'WRONG_PARAMS',
|
||||
'message': 'Missing or wrong parameters'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!await UserService.checkSession(useDev, userId, sessionId, sessionKey)) {
|
||||
res.status(403).send({
|
||||
'status': 'INVALID_SESSION',
|
||||
'message': 'The user or session could not be found or the session is invalid'
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!await UserService.checkSession(useDev, userId, sessionId, sessionKey)) {
|
||||
res.status(403).send({
|
||||
'status': 'INVALID_SESSION',
|
||||
'message': 'The user or session could not be found or the session is invalid'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
let data = await InviteService.getInvitesData(useDev, userId);
|
||||
let data = await InviteService.getInvitesData(useDev, userId);
|
||||
|
||||
res.status(200).send(data);
|
||||
} catch (e) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
res.status(200).send(data);
|
||||
} catch (e: any) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -12,59 +12,59 @@ import {Guid} from 'guid-typescript';
|
|||
export const loginRouter = express.Router();
|
||||
|
||||
loginRouter.post('/:isDevCall', async (req: Request, res: Response) => {
|
||||
try {
|
||||
let username: string = '';
|
||||
let email: string = '';
|
||||
let password: string = '';
|
||||
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
||||
try {
|
||||
let username: string = '';
|
||||
let email: string = '';
|
||||
let password: string = '';
|
||||
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
||||
|
||||
// Send error when content-type header is missing
|
||||
if (!req.headers['content-type']) {
|
||||
res.status(400).send({
|
||||
'status': 'MISSING_CONTENT_TYPE',
|
||||
'message': 'Please set the content-type header field'
|
||||
});
|
||||
return;
|
||||
}
|
||||
// Send error when content-type header is missing
|
||||
if (!req.headers['content-type']) {
|
||||
res.status(400).send({
|
||||
'status': 'MISSING_CONTENT_TYPE',
|
||||
'message': 'Please set the content-type header field'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// API accepts both JSON in body and HTTP parameters
|
||||
if (req.headers['content-type'] === 'application/json') {
|
||||
username = req.body.username;
|
||||
email = req.body.email;
|
||||
password = req.body.password;
|
||||
} else if (req.headers['content-type'] === 'application/x-www-form-urlencoded') {
|
||||
username = (req.query.username ?? '').toString();
|
||||
email = (req.query.email ?? '').toString();
|
||||
password = (req.query.password ?? '').toString();
|
||||
} else {
|
||||
res.status(400).send({
|
||||
'status': 'WRONG_CONTENT_TYPE',
|
||||
'message': 'The transmitted content-type is not supported'
|
||||
});
|
||||
return;
|
||||
}
|
||||
let userIP = req.socket.remoteAddress ?? '';
|
||||
let deviceInfo = req.headers['user-agent'] ?? '';
|
||||
// API accepts both JSON in body and HTTP parameters
|
||||
if (req.headers['content-type'] === 'application/json') {
|
||||
username = req.body.username;
|
||||
email = req.body.email;
|
||||
password = req.body.password;
|
||||
} else if (req.headers['content-type'] === 'application/x-www-form-urlencoded') {
|
||||
username = (req.query.username ?? '').toString();
|
||||
email = (req.query.email ?? '').toString();
|
||||
password = (req.query.password ?? '').toString();
|
||||
} else {
|
||||
res.status(400).send({
|
||||
'status': 'WRONG_CONTENT_TYPE',
|
||||
'message': 'The transmitted content-type is not supported'
|
||||
});
|
||||
return;
|
||||
}
|
||||
let userIP = req.socket.remoteAddress ?? '';
|
||||
let deviceInfo = req.headers['user-agent'] ?? '';
|
||||
|
||||
if ((username === '' && email === '') || password === '') {
|
||||
res.status(400).send({
|
||||
'status': 'WRONG_PARAMS',
|
||||
'message': 'Missing or wrong parameters'
|
||||
});
|
||||
return;
|
||||
}
|
||||
if ((username === '' && email === '') || password === '') {
|
||||
res.status(400).send({
|
||||
'status': 'WRONG_PARAMS',
|
||||
'message': 'Missing or wrong parameters'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Check password and create session
|
||||
let session = await UserService.loginUser(useDev, username, email, password, userIP, deviceInfo);
|
||||
// Check password and create session
|
||||
let session = await UserService.loginUser(useDev, username, email, password, userIP, deviceInfo);
|
||||
|
||||
res.status(200).send(session);
|
||||
} catch (e) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
res.status(200).send(session);
|
||||
} catch (e: any) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -12,78 +12,78 @@ import {Guid} from 'guid-typescript';
|
|||
export const registerRouter = express.Router();
|
||||
|
||||
registerRouter.post('/:isDevCall', async (req: Request, res: Response) => {
|
||||
try {
|
||||
let username: string = '';
|
||||
let email: string = '';
|
||||
let firstName: string = '';
|
||||
let lastName: string = '';
|
||||
let password: string = '';
|
||||
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
||||
try {
|
||||
let username: string = '';
|
||||
let email: string = '';
|
||||
let firstName: string = '';
|
||||
let lastName: string = '';
|
||||
let password: string = '';
|
||||
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
||||
|
||||
// Send error when content-type header is missing
|
||||
if (!req.headers['content-type']) {
|
||||
res.status(400).send({
|
||||
'status': 'MISSING_CONTENT_TYPE',
|
||||
'message': 'Please set the content-type header field'
|
||||
});
|
||||
return;
|
||||
}
|
||||
// Send error when content-type header is missing
|
||||
if (!req.headers['content-type']) {
|
||||
res.status(400).send({
|
||||
'status': 'MISSING_CONTENT_TYPE',
|
||||
'message': 'Please set the content-type header field'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// API accepts both JSON in body and HTTP parameters
|
||||
if (req.headers['content-type'] === 'application/json') {
|
||||
username = req.body.username;
|
||||
email = req.body.email;
|
||||
firstName = req.body.firstName;
|
||||
lastName = req.body.lastName;
|
||||
password = req.body.password;
|
||||
} else if (req.headers['content-type'] === 'application/x-www-form-urlencoded') {
|
||||
username = (req.query.username ?? '').toString();
|
||||
email = (req.query.email ?? '').toString();
|
||||
firstName = (req.query.firstName ?? '').toString();
|
||||
lastName = (req.query.lastName ?? '').toString();
|
||||
password = (req.query.password ?? '').toString();
|
||||
} else {
|
||||
res.status(400).send({
|
||||
'status': 'WRONG_CONTENT_TYPE',
|
||||
'message': 'The transmitted content-type is not supported'
|
||||
});
|
||||
return;
|
||||
}
|
||||
let userIP = req.socket.remoteAddress ?? '';
|
||||
let deviceInfo = req.headers['user-agent'] ?? '';
|
||||
// API accepts both JSON in body and HTTP parameters
|
||||
if (req.headers['content-type'] === 'application/json') {
|
||||
username = req.body.username;
|
||||
email = req.body.email;
|
||||
firstName = req.body.firstName;
|
||||
lastName = req.body.lastName;
|
||||
password = req.body.password;
|
||||
} else if (req.headers['content-type'] === 'application/x-www-form-urlencoded') {
|
||||
username = (req.query.username ?? '').toString();
|
||||
email = (req.query.email ?? '').toString();
|
||||
firstName = (req.query.firstName ?? '').toString();
|
||||
lastName = (req.query.lastName ?? '').toString();
|
||||
password = (req.query.password ?? '').toString();
|
||||
} else {
|
||||
res.status(400).send({
|
||||
'status': 'WRONG_CONTENT_TYPE',
|
||||
'message': 'The transmitted content-type is not supported'
|
||||
});
|
||||
return;
|
||||
}
|
||||
let userIP = req.socket.remoteAddress ?? '';
|
||||
let deviceInfo = req.headers['user-agent'] ?? '';
|
||||
|
||||
if (username === '' || email === '' || firstName === '' || lastName === '' || password === '') {
|
||||
res.status(400).send({
|
||||
'status': 'WRONG_PARAMS',
|
||||
'message': 'Missing or wrong parameters'
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (username === '' || email === '' || firstName === '' || lastName === '' || password === '') {
|
||||
res.status(400).send({
|
||||
'status': 'WRONG_PARAMS',
|
||||
'message': 'Missing or wrong parameters'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for invalid username / email
|
||||
const status = await UserService.checkUsernameAndEmail(useDev, username, email);
|
||||
if (status.hasProblems) {
|
||||
// Username and/or email are duplicates, return error
|
||||
res.status(400).send({
|
||||
'message': status.messages[0],
|
||||
'status': status.status[0],
|
||||
'additionalMessages': status.messages.slice(1),
|
||||
'additionalStatus': status.status.slice(1)
|
||||
});
|
||||
return;
|
||||
}
|
||||
// Check for invalid username / email
|
||||
const status = await UserService.checkUsernameAndEmail(useDev, username, email);
|
||||
if (status.hasProblems) {
|
||||
// Username and/or email are duplicates, return error
|
||||
res.status(400).send({
|
||||
'message': status.messages[0],
|
||||
'status': status.status[0],
|
||||
'additionalMessages': status.messages.slice(1),
|
||||
'additionalStatus': status.status.slice(1)
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Create user
|
||||
let session = await UserService.registerUser(useDev, username, email, firstName, lastName, password, userIP, deviceInfo);
|
||||
// Create user
|
||||
let session = await UserService.registerUser(useDev, username, email, firstName, lastName, password, userIP, deviceInfo);
|
||||
|
||||
res.status(201).send(session);
|
||||
} catch (e) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
res.status(201).send(session);
|
||||
} catch (e: any) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -13,38 +13,38 @@ import {Guid} from 'guid-typescript';
|
|||
export const sessionRouter = express.Router();
|
||||
|
||||
sessionRouter.get('/:isDevCall', async (req: Request, res: Response) => {
|
||||
try {
|
||||
let userId = (req.query.userId ?? '').toString();
|
||||
let sessionId = (req.query.sessionId ?? '').toString();
|
||||
let sessionKey = (req.query.sessionKey ?? '').toString();
|
||||
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
||||
try {
|
||||
let userId = (req.query.userId ?? '').toString();
|
||||
let sessionId = (req.query.sessionId ?? '').toString();
|
||||
let sessionKey = (req.query.sessionKey ?? '').toString();
|
||||
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
||||
|
||||
if (userId === '' || sessionId === '' || sessionKey === '') {
|
||||
res.status(400).send({
|
||||
'status': 'WRONG_PARAMS',
|
||||
'message': 'Missing or wrong parameters'
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (userId === '' || sessionId === '' || sessionKey === '') {
|
||||
res.status(400).send({
|
||||
'status': 'WRONG_PARAMS',
|
||||
'message': 'Missing or wrong parameters'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!await UserService.checkSession(useDev, userId, sessionId, sessionKey)) {
|
||||
res.status(403).send({
|
||||
'status': 'INVALID_SESSION',
|
||||
'message': 'The user or session could not be found or the session is invalid'
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!await UserService.checkSession(useDev, userId, sessionId, sessionKey)) {
|
||||
res.status(403).send({
|
||||
'status': 'INVALID_SESSION',
|
||||
'message': 'The user or session could not be found or the session is invalid'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
let data = await SessionService.getSessionData(useDev, userId);
|
||||
let data = await SessionService.getSessionData(useDev, userId);
|
||||
|
||||
res.status(200).send(data);
|
||||
} catch (e) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
res.status(200).send(data);
|
||||
} catch (e: any) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -12,38 +12,38 @@ import {Guid} from 'guid-typescript';
|
|||
export const userRouter = express.Router();
|
||||
|
||||
userRouter.get('/:isDevCall', async (req: Request, res: Response) => {
|
||||
try {
|
||||
let userId = (req.query.userId ?? '').toString();
|
||||
let sessionId = (req.query.sessionId ?? '').toString();
|
||||
let sessionKey = (req.query.sessionKey ?? '').toString();
|
||||
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
||||
try {
|
||||
let userId = (req.query.userId ?? '').toString();
|
||||
let sessionId = (req.query.sessionId ?? '').toString();
|
||||
let sessionKey = (req.query.sessionKey ?? '').toString();
|
||||
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
||||
|
||||
if (userId === '' || sessionId === '' || sessionKey === '') {
|
||||
res.status(400).send({
|
||||
'status': 'WRONG_PARAMS',
|
||||
'message': 'Missing or wrong parameters'
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (userId === '' || sessionId === '' || sessionKey === '') {
|
||||
res.status(400).send({
|
||||
'status': 'WRONG_PARAMS',
|
||||
'message': 'Missing or wrong parameters'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!await UserService.checkSession(useDev, userId, sessionId, sessionKey)) {
|
||||
res.status(403).send({
|
||||
'status': 'INVALID_SESSION',
|
||||
'message': 'The user or session could not be found or the session is invalid'
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!await UserService.checkSession(useDev, userId, sessionId, sessionKey)) {
|
||||
res.status(403).send({
|
||||
'status': 'INVALID_SESSION',
|
||||
'message': 'The user or session could not be found or the session is invalid'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
let data = await UserService.getUserData(useDev, userId);
|
||||
let data = await UserService.getUserData(useDev, userId);
|
||||
|
||||
res.status(200).send(data);
|
||||
} catch (e) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
res.status(200).send(data);
|
||||
} catch (e: any) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -65,34 +65,34 @@ export const raPlaMiddlewareRouter = express.Router();
|
|||
* example: 2
|
||||
*/
|
||||
raPlaMiddlewareRouter.get('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
let user = (req.query.user ?? '').toString();
|
||||
let file = (req.query.file ?? '').toString();
|
||||
let blockers = (req.query.blockers ?? '').toString() === '1';
|
||||
let wahl = (req.query.wahl ?? '').toString();
|
||||
let pflicht = (req.query.pflicht ?? '').toString();
|
||||
try {
|
||||
let user = (req.query.user ?? '').toString();
|
||||
let file = (req.query.file ?? '').toString();
|
||||
let blockers = (req.query.blockers ?? '').toString() === '1';
|
||||
let wahl = (req.query.wahl ?? '').toString();
|
||||
let pflicht = (req.query.pflicht ?? '').toString();
|
||||
|
||||
const allowedCharsRegex: RegExp = /^[a-zA-Z0-9]+$/;
|
||||
const allowedCharsRegex: RegExp = /^[a-zA-Z0-9]+$/;
|
||||
|
||||
if (user === '' || file === '') {
|
||||
res.status(400).send('Please at least provide user and file for RaPla!');
|
||||
return;
|
||||
} else if (!allowedCharsRegex.test(user) || !allowedCharsRegex.test(file)) {
|
||||
res.status(400).send('Please provide a valid user and file!');
|
||||
return;
|
||||
}
|
||||
if (user === '' || file === '') {
|
||||
res.status(400).send('Please at least provide user and file for RaPla!');
|
||||
return;
|
||||
} else if (!allowedCharsRegex.test(user) || !allowedCharsRegex.test(file)) {
|
||||
res.status(400).send('Please provide a valid user and file!');
|
||||
return;
|
||||
}
|
||||
|
||||
let resultingFile = await icalgenerator.getiCalFile(user, file, blockers, wahl, pflicht);
|
||||
let resultingFile = await icalgenerator.getiCalFile(user, file, blockers, wahl, pflicht);
|
||||
|
||||
res.set({'Content-Disposition': 'attachment; filename=' + file + '.ics'});
|
||||
res.status(200).send(resultingFile);
|
||||
} catch (e) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
res.set({'Content-Disposition': 'attachment; filename=' + file + '.ics'});
|
||||
res.status(200).send(resultingFile);
|
||||
} catch (e: any) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -14,15 +14,15 @@ export const highlightMarkerRouter = express.Router();
|
|||
highlightMarkerRouter.use('/addHighlight', addHighlightRouter);
|
||||
|
||||
highlightMarkerRouter.get('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
res.status(200).send('Pluto Development Twitch Highlight Marker API Endpoint');
|
||||
} catch (e) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
try {
|
||||
res.status(200).send('Pluto Development Twitch Highlight Marker API Endpoint');
|
||||
} catch (e: any) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -12,46 +12,46 @@ import {Guid} from 'guid-typescript';
|
|||
export const addHighlightRouter = express.Router();
|
||||
|
||||
addHighlightRouter.get('/', (req: Request, res: Response) => {
|
||||
try {
|
||||
res.status(200).send('GET endpoint not defined.');
|
||||
} catch (e) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
try {
|
||||
res.status(200).send('GET endpoint not defined.');
|
||||
} catch (e: any) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
addHighlightRouter.post('/', (req: Request, res: Response) => {
|
||||
try {
|
||||
// Check input params
|
||||
const body = req.body;
|
||||
try {
|
||||
// Check input params
|
||||
const body = req.body;
|
||||
|
||||
if (body.access_key !== process.env.TWITCH_HIGHLIGHTS_ACCESS_KEY) {
|
||||
// Unauthorized, return error
|
||||
res.type('application/json');
|
||||
res.status(403).send({'status': 'error', 'description': 'Unauthorized.'});
|
||||
} else if (!body.streamer || !body.stream_id || !body.stream_game || !body.timestamp || !body.description || !body.username) {
|
||||
// Missing params, return error
|
||||
res.type('application/json');
|
||||
res.status(400).send({'status': 'error', 'description': 'Missing parameters.'});
|
||||
} else {
|
||||
// Everything fine, return success
|
||||
AddHighlightService.createHighlightEntry(body);
|
||||
if (body.access_key !== process.env.TWITCH_HIGHLIGHTS_ACCESS_KEY) {
|
||||
// Unauthorized, return error
|
||||
res.type('application/json');
|
||||
res.status(403).send({'status': 'error', 'description': 'Unauthorized.'});
|
||||
} else if (!body.streamer || !body.stream_id || !body.stream_game || !body.timestamp || !body.description || !body.username) {
|
||||
// Missing params, return error
|
||||
res.type('application/json');
|
||||
res.status(400).send({'status': 'error', 'description': 'Missing parameters.'});
|
||||
} else {
|
||||
// Everything fine, return success
|
||||
AddHighlightService.createHighlightEntry(body);
|
||||
|
||||
res.type('application/json');
|
||||
res.status(200).send({'status': 'success', 'description': ''});
|
||||
}
|
||||
} catch (e) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
res.type('application/json');
|
||||
res.status(200).send({'status': 'success', 'description': ''});
|
||||
}
|
||||
} catch (e: any) {
|
||||
let errorGuid = Guid.create().toString();
|
||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||
res.status(500).send({
|
||||
'status': 'PROCESSING_ERROR',
|
||||
'message': 'Internal Server Error. Try again later.',
|
||||
'reference': errorGuid
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user