Compare commits
No commits in common. "123684da13f1a1f4f85d859ff138ec2cf758ca56" and "a9ad5e8f879495e26b08e8788ce5c6865c13e3f3" have entirely different histories.
123684da13
...
a9ad5e8f87
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -8,5 +8,3 @@ dist/
|
||||||
logs/
|
logs/
|
||||||
node_modules/
|
node_modules/
|
||||||
public/
|
public/
|
||||||
coverage/
|
|
||||||
testResults/
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
|
|
||||||
module.exports = {
|
|
||||||
preset: 'ts-jest',
|
|
||||||
testEnvironment: 'node',
|
|
||||||
};
|
|
8947
package-lock.json
generated
8947
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
12
package.json
12
package.json
|
@ -7,7 +7,7 @@
|
||||||
"start": "tsc && node ./dist/app.js",
|
"start": "tsc && node ./dist/app.js",
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"debug": "export DEBUG=* && npm run start",
|
"debug": "export DEBUG=* && npm run start",
|
||||||
"test": "jest --coverage --testResultsProcessor ./node_modules/jest-sonar-reporter/index.js"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
|
@ -32,22 +32,12 @@
|
||||||
"@types/bcrypt": "^3.0.1",
|
"@types/bcrypt": "^3.0.1",
|
||||||
"@types/debug": "^4.1.5",
|
"@types/debug": "^4.1.5",
|
||||||
"@types/express": "^4.17.11",
|
"@types/express": "^4.17.11",
|
||||||
"@types/jest": "^28.1.3",
|
|
||||||
"@types/random-words": "^1.1.2",
|
"@types/random-words": "^1.1.2",
|
||||||
"@types/swagger-jsdoc": "^6.0.1",
|
"@types/swagger-jsdoc": "^6.0.1",
|
||||||
"@types/swagger-ui-express": "^4.1.3",
|
"@types/swagger-ui-express": "^4.1.3",
|
||||||
"@types/winston": "^2.4.4",
|
"@types/winston": "^2.4.4",
|
||||||
"jest": "^28.1.1",
|
|
||||||
"jest-sonar-reporter": "^2.0.0",
|
|
||||||
"source-map-support": "^0.5.19",
|
"source-map-support": "^0.5.19",
|
||||||
"ts-jest": "^28.0.5",
|
|
||||||
"tslint": "^6.1.3",
|
"tslint": "^6.1.3",
|
||||||
"typescript": "^4.1.5"
|
"typescript": "^4.1.5"
|
||||||
},
|
|
||||||
"jestSonar": {
|
|
||||||
"sonar56x": true,
|
|
||||||
"reportPath": "testResults",
|
|
||||||
"reportFile": "sonar-report.xml",
|
|
||||||
"indent": 4
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1 @@
|
||||||
sonar.projectKey=pd-api
|
sonar.projectKey=pd-api
|
||||||
sonar.sources=src
|
|
||||||
sonar.tests=test
|
|
||||||
sonar.language=ts
|
|
||||||
sonar.javascript.lcov.reportPaths=coverage/lcov.info
|
|
||||||
sonar.testExecutionReportPaths=testResults/sonar-report.xml
|
|
||||||
|
|
|
@ -33,15 +33,15 @@ betterzonRouter.use('/crawlingstatus', crawlingstatusRouter);
|
||||||
|
|
||||||
|
|
||||||
betterzonRouter.get('/', async (req: Request, res: Response) => {
|
betterzonRouter.get('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
res.status(200).send('Pluto Development Betterzon API Endpoint');
|
res.status(200).send('Pluto Development Betterzon API Endpoint');
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
let errorGuid = Guid.create().toString();
|
let errorGuid = Guid.create().toString();
|
||||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
'status': 'PROCESSING_ERROR',
|
'status': 'PROCESSING_ERROR',
|
||||||
'message': 'Internal Server Error. Try again later.',
|
'message': 'Internal Server Error. Try again later.',
|
||||||
'reference': errorGuid
|
'reference': errorGuid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -21,50 +21,50 @@ export const categoriesRouter = express.Router();
|
||||||
|
|
||||||
// GET categories/
|
// GET categories/
|
||||||
categoriesRouter.get('/', async (req: Request, res: Response) => {
|
categoriesRouter.get('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
const categories: Categories = await CategoryService.findAll();
|
const categories: Categories = await CategoryService.findAll();
|
||||||
|
|
||||||
res.status(200).send(categories);
|
res.status(200).send(categories);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// GET categories/:id
|
// GET categories/:id
|
||||||
categoriesRouter.get('/:id', async (req: Request, res: Response) => {
|
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) {
|
if (!id) {
|
||||||
res.status(400).send('Missing parameters.');
|
res.status(400).send('Missing parameters.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const category: Category = await CategoryService.find(id);
|
const category: Category = await CategoryService.find(id);
|
||||||
|
|
||||||
res.status(200).send(category);
|
res.status(200).send(category);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// GET categories/search/:term
|
// GET categories/search/:term
|
||||||
categoriesRouter.get('/search/:term', async (req: Request, res: Response) => {
|
categoriesRouter.get('/search/:term', async (req: Request, res: Response) => {
|
||||||
const term: string = req.params.term;
|
const term: string = req.params.term;
|
||||||
|
|
||||||
if (!term) {
|
if (!term) {
|
||||||
res.status(400).send('Missing parameters.');
|
res.status(400).send('Missing parameters.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const categories: Categories = await CategoryService.findBySearchTerm(term);
|
const categories: Categories = await CategoryService.findBySearchTerm(term);
|
||||||
|
|
||||||
res.status(200).send(categories);
|
res.status(200).send(categories);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,6 +7,7 @@ import * as ContactPersonService from './contact_persons.service';
|
||||||
import {Contact_Person} from './contact_person.interface';
|
import {Contact_Person} from './contact_person.interface';
|
||||||
import {Contact_Persons} from './contact_persons.interface';
|
import {Contact_Persons} from './contact_persons.interface';
|
||||||
import * as UserService from '../users/users.service';
|
import * as UserService from '../users/users.service';
|
||||||
|
import * as PriceService from '../prices/prices.service';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,111 +23,111 @@ export const contactpersonsRouter = express.Router();
|
||||||
|
|
||||||
// GET contactpersons/
|
// GET contactpersons/
|
||||||
contactpersonsRouter.get('/', async (req: Request, res: Response) => {
|
contactpersonsRouter.get('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
const contacts: Contact_Persons = await ContactPersonService.findAll();
|
const contacts: Contact_Persons = await ContactPersonService.findAll();
|
||||||
|
|
||||||
res.status(200).send(contacts);
|
res.status(200).send(contacts);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// GET contactpersons/:id
|
// GET contactpersons/:id
|
||||||
contactpersonsRouter.get('/:id', async (req: Request, res: Response) => {
|
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) {
|
if (!id) {
|
||||||
res.status(400).send('Missing parameters.');
|
res.status(400).send('Missing parameters.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const contact: Contact_Person = await ContactPersonService.find(id);
|
const contact: Contact_Person = await ContactPersonService.find(id);
|
||||||
|
|
||||||
res.status(200).send(contact);
|
res.status(200).send(contact);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// GET contactpersons/byvendor/:id
|
// GET contactpersons/byvendor/:id
|
||||||
contactpersonsRouter.get('/byvendor/:id', async (req: Request, res: Response) => {
|
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) {
|
if (!id) {
|
||||||
res.status(400).send('Missing parameters.');
|
res.status(400).send('Missing parameters.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const contacts: Contact_Persons = await ContactPersonService.findByVendor(id);
|
const contacts: Contact_Persons = await ContactPersonService.findByVendor(id);
|
||||||
|
|
||||||
res.status(200).send(contacts);
|
res.status(200).send(contacts);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// POST contactpersons/
|
// POST contactpersons/
|
||||||
contactpersonsRouter.post('/', async (req: Request, res: Response) => {
|
contactpersonsRouter.post('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
// Authenticate user
|
// Authenticate user
|
||||||
const user_ip = req.connection.remoteAddress ?? '';
|
const user_ip = req.connection.remoteAddress ?? '';
|
||||||
const session_id = req.body.session_id;
|
const session_id = req.body.session_id;
|
||||||
const session_key = req.body.session_key;
|
const session_key = req.body.session_key;
|
||||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||||
|
|
||||||
// Get required parameters
|
// Get required parameters
|
||||||
const vendor_id = req.body.vendor_id;
|
const vendor_id = req.body.vendor_id;
|
||||||
const first_name = req.body.first_name;
|
const first_name = req.body.first_name;
|
||||||
const last_name = req.body.last_name;
|
const last_name = req.body.last_name;
|
||||||
const gender = req.body.gender;
|
const gender = req.body.gender;
|
||||||
const email = req.body.email;
|
const email = req.body.email;
|
||||||
const phone = req.body.phone;
|
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) {
|
if (success) {
|
||||||
res.status(201).send({});
|
res.status(201).send({});
|
||||||
} else {
|
} else {
|
||||||
res.status(500).send({});
|
res.status(500).send({});
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// PUT contactpersons/:id
|
// PUT contactpersons/:id
|
||||||
contactpersonsRouter.put('/:id', async (req: Request, res: Response) => {
|
contactpersonsRouter.put('/:id', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
// Authenticate user
|
// Authenticate user
|
||||||
const user_ip = req.connection.remoteAddress ?? '';
|
const user_ip = req.connection.remoteAddress ?? '';
|
||||||
const session_id = req.body.session_id;
|
const session_id = req.body.session_id;
|
||||||
const session_key = req.body.session_key;
|
const session_key = req.body.session_key;
|
||||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||||
|
|
||||||
// Get required parameters
|
// Get required parameters
|
||||||
const contact_person_id = parseInt(req.params.id, 10);
|
const contact_person_id = parseInt(req.params.id, 10);
|
||||||
const vendor_id = req.body.vendor_id;
|
const vendor_id = req.body.vendor_id;
|
||||||
const first_name = req.body.first_name;
|
const first_name = req.body.first_name;
|
||||||
const last_name = req.body.last_name;
|
const last_name = req.body.last_name;
|
||||||
const gender = req.body.gender;
|
const gender = req.body.gender;
|
||||||
const email = req.body.email;
|
const email = req.body.email;
|
||||||
const phone = req.body.phone;
|
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) {
|
if (success) {
|
||||||
res.status(200).send({});
|
res.status(200).send({});
|
||||||
} else {
|
} else {
|
||||||
res.status(500).send({});
|
res.status(500).send({});
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
import express, {Request, Response} from 'express';
|
import express, {Request, Response} from 'express';
|
||||||
import * as CrawlingStatusService from './crawling_status.service';
|
import * as CrawlingStatusService from './crawling_status.service';
|
||||||
import {Crawling_Status} from './crawling_status.interface';
|
import {Crawling_Status} from './crawling_status.interface';
|
||||||
|
import {Crawling_Statuses} from './crawling_statuses.interface';
|
||||||
import * as UserService from '../users/users.service';
|
import * as UserService from '../users/users.service';
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,23 +22,23 @@ export const crawlingstatusRouter = express.Router();
|
||||||
|
|
||||||
// GET crawlingstatus/
|
// GET crawlingstatus/
|
||||||
crawlingstatusRouter.get('/', async (req: Request, res: Response) => {
|
crawlingstatusRouter.get('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
// Authenticate user
|
// Authenticate user
|
||||||
const user_ip = req.connection.remoteAddress ?? '';
|
const user_ip = req.connection.remoteAddress ?? '';
|
||||||
const session_id = (req.query.session_id ?? '').toString();
|
const session_id = (req.query.session_id ?? '').toString();
|
||||||
const session_key = (req.query.session_key ?? '').toString();
|
const session_key = (req.query.session_key ?? '').toString();
|
||||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||||
|
|
||||||
if (!user.is_admin) {
|
if (!user.is_admin) {
|
||||||
res.status(403).send({});
|
res.status(403).send({});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const status: Crawling_Status = await CrawlingStatusService.getCurrent();
|
const status: Crawling_Status = await CrawlingStatusService.getCurrent();
|
||||||
|
|
||||||
res.status(200).send(status);
|
res.status(200).send(status);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
import express, {Request, Response} from 'express';
|
import express, {Request, Response} from 'express';
|
||||||
import * as FavoriteShopsService from './favoriteshops.service';
|
import * as FavoriteShopsService from './favoriteshops.service';
|
||||||
|
import {FavoriteShop} from './favoriteshop.interface';
|
||||||
|
import {FavoriteShops} from './favoriteshops.interface';
|
||||||
import * as UserService from '../users/users.service';
|
import * as UserService from '../users/users.service';
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,86 +21,86 @@ export const favoriteshopsRouter = express.Router();
|
||||||
|
|
||||||
//GET favoriteshops/
|
//GET favoriteshops/
|
||||||
favoriteshopsRouter.get('/', async (req: Request, res: Response) => {
|
favoriteshopsRouter.get('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
// Authenticate user
|
// Authenticate user
|
||||||
const user_ip = req.connection.remoteAddress ?? '';
|
const user_ip = req.connection.remoteAddress ?? '';
|
||||||
const session_id = (req.query.session_id ?? '').toString();
|
const session_id = (req.query.session_id ?? '').toString();
|
||||||
const session_key = (req.query.session_key ?? '').toString();
|
const session_key = (req.query.session_key ?? '').toString();
|
||||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
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);
|
res.status(200).send(priceAlarms);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// POST favoriteshops/
|
// POST favoriteshops/
|
||||||
favoriteshopsRouter.post('/', async (req: Request, res: Response) => {
|
favoriteshopsRouter.post('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
// Authenticate user
|
// Authenticate user
|
||||||
const user_ip = req.connection.remoteAddress ?? '';
|
const user_ip = req.connection.remoteAddress ?? '';
|
||||||
const session_id = req.body.session_id;
|
const session_id = req.body.session_id;
|
||||||
const session_key = req.body.session_key;
|
const session_key = req.body.session_key;
|
||||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||||
|
|
||||||
// Get info for price alarm creation
|
// Get info for price alarm creation
|
||||||
const vendor_id = req.body.vendor_id;
|
const vendor_id = req.body.vendor_id;
|
||||||
|
|
||||||
if (!vendor_id) {
|
if (!vendor_id) {
|
||||||
// Missing
|
// Missing
|
||||||
res.status(400).send(JSON.stringify({message: 'Missing parameters'}));
|
res.status(400).send(JSON.stringify({message: 'Missing parameters'}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create price alarm
|
// Create price alarm
|
||||||
const success = await FavoriteShopsService.createFavoriteShop(user.user_id, vendor_id);
|
const success = await FavoriteShopsService.createFavoriteShop(user.user_id, vendor_id);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
res.status(201).send(JSON.stringify({success: true}));
|
res.status(201).send(JSON.stringify({success: true}));
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
res.status(500).send(JSON.stringify({success: false}));
|
res.status(500).send(JSON.stringify({success: false}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// DELETE favoriteshops/
|
// DELETE favoriteshops/
|
||||||
favoriteshopsRouter.delete('/:id', async (req: Request, res: Response) => {
|
favoriteshopsRouter.delete('/:id', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
// Authenticate user
|
// Authenticate user
|
||||||
const user_ip = req.connection.remoteAddress ?? '';
|
const user_ip = req.connection.remoteAddress ?? '';
|
||||||
const session_id = (req.query.session_id ?? '').toString();
|
const session_id = (req.query.session_id ?? '').toString();
|
||||||
const session_key = (req.query.session_key ?? '').toString();
|
const session_key = (req.query.session_key ?? '').toString();
|
||||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||||
|
|
||||||
// Get info for price alarm creation
|
// Get info for price alarm creation
|
||||||
const favorite_id = parseInt(req.params.id, 10);
|
const favorite_id = parseInt(req.params.id, 10);
|
||||||
|
|
||||||
if (!favorite_id) {
|
if (!favorite_id) {
|
||||||
// Missing
|
// Missing
|
||||||
res.status(400).send(JSON.stringify({message: 'Missing parameters'}));
|
res.status(400).send(JSON.stringify({message: 'Missing parameters'}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create price alarm
|
// Create price alarm
|
||||||
const success = await FavoriteShopsService.deleteFavoriteShop(user.user_id, favorite_id);
|
const success = await FavoriteShopsService.deleteFavoriteShop(user.user_id, favorite_id);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
res.status(201).send(JSON.stringify({success: true}));
|
res.status(201).send(JSON.stringify({success: true}));
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
res.status(500).send(JSON.stringify({success: false}));
|
res.status(500).send(JSON.stringify({success: false}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -21,50 +21,50 @@ export const manufacturersRouter = express.Router();
|
||||||
|
|
||||||
// GET manufacturers/
|
// GET manufacturers/
|
||||||
manufacturersRouter.get('/', async (req: Request, res: Response) => {
|
manufacturersRouter.get('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
const manufacturers: Manufacturers = await ManufacturerService.findAll();
|
const manufacturers: Manufacturers = await ManufacturerService.findAll();
|
||||||
|
|
||||||
res.status(200).send(manufacturers);
|
res.status(200).send(manufacturers);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// GET manufacturers/:id
|
// GET manufacturers/:id
|
||||||
manufacturersRouter.get('/:id', async (req: Request, res: Response) => {
|
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) {
|
if (!id) {
|
||||||
res.status(400).send('Missing parameters.');
|
res.status(400).send('Missing parameters.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const manufacturer: Manufacturer = await ManufacturerService.find(id);
|
const manufacturer: Manufacturer = await ManufacturerService.find(id);
|
||||||
|
|
||||||
res.status(200).send(manufacturer);
|
res.status(200).send(manufacturer);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// GET manufacturers/:term
|
// GET manufacturers/:term
|
||||||
manufacturersRouter.get('/search/:term', async (req: Request, res: Response) => {
|
manufacturersRouter.get('/search/:term', async (req: Request, res: Response) => {
|
||||||
const term: string = req.params.term;
|
const term: string = req.params.term;
|
||||||
|
|
||||||
if (!term) {
|
if (!term) {
|
||||||
res.status(400).send('Missing parameters.');
|
res.status(400).send('Missing parameters.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const manufacturer: Manufacturers = await ManufacturerService.findBySearchTerm(term);
|
const manufacturer: Manufacturers = await ManufacturerService.findBySearchTerm(term);
|
||||||
|
|
||||||
res.status(200).send(manufacturer);
|
res.status(200).send(manufacturer);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
import express, {Request, Response} from 'express';
|
import express, {Request, Response} from 'express';
|
||||||
import * as PriceAlarmsService from './pricealarms.service';
|
import * as PriceAlarmsService from './pricealarms.service';
|
||||||
|
import {PriceAlarm} from './pricealarm.interface';
|
||||||
|
import {PriceAlarms} from './pricealarms.interface';
|
||||||
import * as UserService from '../users/users.service';
|
import * as UserService from '../users/users.service';
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,114 +21,114 @@ export const pricealarmsRouter = express.Router();
|
||||||
|
|
||||||
//GET pricealarms/
|
//GET pricealarms/
|
||||||
pricealarmsRouter.get('/', async (req: Request, res: Response) => {
|
pricealarmsRouter.get('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
// Authenticate user
|
// Authenticate user
|
||||||
const user_ip = req.connection.remoteAddress ?? '';
|
const user_ip = req.connection.remoteAddress ?? '';
|
||||||
const session_id = (req.query.session_id ?? '').toString();
|
const session_id = (req.query.session_id ?? '').toString();
|
||||||
const session_key = (req.query.session_key ?? '').toString();
|
const session_key = (req.query.session_key ?? '').toString();
|
||||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
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);
|
res.status(200).send(priceAlarms);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// POST pricealarms/
|
// POST pricealarms/
|
||||||
pricealarmsRouter.post('/', async (req: Request, res: Response) => {
|
pricealarmsRouter.post('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
// Authenticate user
|
// Authenticate user
|
||||||
const user_ip = req.connection.remoteAddress ?? '';
|
const user_ip = req.connection.remoteAddress ?? '';
|
||||||
const session_id = req.body.session_id;
|
const session_id = req.body.session_id;
|
||||||
const session_key = req.body.session_key;
|
const session_key = req.body.session_key;
|
||||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||||
|
|
||||||
// Get info for price alarm creation
|
// Get info for price alarm creation
|
||||||
const product_id = req.body.product_id;
|
const product_id = req.body.product_id;
|
||||||
const defined_price = req.body.defined_price;
|
const defined_price = req.body.defined_price;
|
||||||
|
|
||||||
if (!product_id || !defined_price) {
|
if (!product_id || !defined_price) {
|
||||||
// Missing
|
// Missing
|
||||||
res.status(400).send(JSON.stringify({message: 'Missing parameters'}));
|
res.status(400).send(JSON.stringify({message: 'Missing parameters'}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create price alarm
|
// Create price alarm
|
||||||
const success = await PriceAlarmsService.createPriceAlarm(user.user_id, product_id, defined_price);
|
const success = await PriceAlarmsService.createPriceAlarm(user.user_id, product_id, defined_price);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
res.status(201).send(JSON.stringify({success: true}));
|
res.status(201).send(JSON.stringify({success: true}));
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
res.status(500).send(JSON.stringify({success: false}));
|
res.status(500).send(JSON.stringify({success: false}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// PUT pricealarms/
|
// PUT pricealarms/
|
||||||
pricealarmsRouter.put('/', async (req: Request, res: Response) => {
|
pricealarmsRouter.put('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
// Authenticate user
|
// Authenticate user
|
||||||
const user_ip = req.connection.remoteAddress ?? '';
|
const user_ip = req.connection.remoteAddress ?? '';
|
||||||
const session_id = req.body.session_id;
|
const session_id = req.body.session_id;
|
||||||
const session_key = req.body.session_key;
|
const session_key = req.body.session_key;
|
||||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||||
|
|
||||||
// Get info for price alarm creation
|
// Get info for price alarm creation
|
||||||
const alarm_id = req.body.alarm_id;
|
const alarm_id = req.body.alarm_id;
|
||||||
const defined_price = req.body.defined_price;
|
const defined_price = req.body.defined_price;
|
||||||
|
|
||||||
if (!alarm_id || !defined_price) {
|
if (!alarm_id || !defined_price) {
|
||||||
// Missing
|
// Missing
|
||||||
res.status(400).send(JSON.stringify({message: 'Missing parameters'}));
|
res.status(400).send(JSON.stringify({message: 'Missing parameters'}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update price alarm
|
// Update price alarm
|
||||||
const success = await PriceAlarmsService.updatePriceAlarm(alarm_id, user.user_id, defined_price);
|
const success = await PriceAlarmsService.updatePriceAlarm(alarm_id, user.user_id, defined_price);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
res.status(200).send(JSON.stringify({success: true}));
|
res.status(200).send(JSON.stringify({success: true}));
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
res.status(500).send(JSON.stringify({success: false}));
|
res.status(500).send(JSON.stringify({success: false}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// DELETE pricealarms/:id
|
// DELETE pricealarms/:id
|
||||||
pricealarmsRouter.delete('/:id', async (req, res) => {
|
pricealarmsRouter.delete('/:id', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
// Authenticate user
|
// Authenticate user
|
||||||
const user_ip = req.connection.remoteAddress ?? '';
|
const user_ip = req.connection.remoteAddress ?? '';
|
||||||
const session_id = (req.query.session_id ?? '').toString();
|
const session_id = (req.query.session_id ?? '').toString();
|
||||||
const session_key = (req.query.session_key ?? '').toString();
|
const session_key = (req.query.session_key ?? '').toString();
|
||||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
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) {
|
if (success) {
|
||||||
res.status(200).send(JSON.stringify({success: true}));
|
res.status(200).send(JSON.stringify({success: true}));
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
res.status(500).send(JSON.stringify({success: false}));
|
res.status(500).send(JSON.stringify({success: false}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,109 +22,109 @@ export const pricesRouter = express.Router();
|
||||||
|
|
||||||
// GET prices/
|
// GET prices/
|
||||||
pricesRouter.get('/', async (req: Request, res: Response) => {
|
pricesRouter.get('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
let prices: Prices = [];
|
let prices: Prices = [];
|
||||||
const product = req.query.product;
|
const product = req.query.product;
|
||||||
const vendor = req.query.vendor;
|
const vendor = req.query.vendor;
|
||||||
const type = req.query.type;
|
const type = req.query.type;
|
||||||
|
|
||||||
if (product) {
|
if (product) {
|
||||||
if (vendor) {
|
if (vendor) {
|
||||||
prices = await PriceService.findByVendor(<string>product, <string>vendor, <string>type);
|
prices = await PriceService.findByVendor(<string> product, <string> vendor, <string> type);
|
||||||
} else {
|
} else {
|
||||||
prices = await PriceService.findByType(<string>product, <string>type);
|
prices = await PriceService.findByType(<string> product, <string> type);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
prices = await PriceService.findAll();
|
prices = await PriceService.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
res.status(200).send(prices);
|
res.status(200).send(prices);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// GET prices/:id
|
// GET prices/:id
|
||||||
pricesRouter.get('/:id', async (req: Request, res: Response) => {
|
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) {
|
if (!id) {
|
||||||
res.status(400).send('Missing parameters.');
|
res.status(400).send('Missing parameters.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const price: Price = await PriceService.find(id);
|
const price: Price = await PriceService.find(id);
|
||||||
|
|
||||||
res.status(200).send(price);
|
res.status(200).send(price);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// GET prices/bestDeals
|
// GET prices/bestDeals
|
||||||
pricesRouter.get('/bestDeals/:amount', async (req: Request, res: Response) => {
|
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) {
|
if (!amount) {
|
||||||
res.status(400).send('Missing parameters.');
|
res.status(400).send('Missing parameters.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const prices: Prices = await PriceService.getBestDeals(amount);
|
const prices: Prices = await PriceService.getBestDeals(amount);
|
||||||
|
|
||||||
res.status(200).send(prices);
|
res.status(200).send(prices);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// GET prices/byProduct/list/[]
|
// GET prices/byProduct/list/[]
|
||||||
pricesRouter.get('/byProduct/list/:ids', async (req: Request, res: Response) => {
|
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) {
|
if (!productIds) {
|
||||||
res.status(400).send('Missing parameters.');
|
res.status(400).send('Missing parameters.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const prices: Prices = await PriceService.findListByProducts(productIds);
|
const prices: Prices = await PriceService.findListByProducts(productIds);
|
||||||
|
|
||||||
res.status(200).send(prices);
|
res.status(200).send(prices);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// POST prices/
|
// POST prices/
|
||||||
pricesRouter.post('/', async (req: Request, res: Response) => {
|
pricesRouter.post('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
// Authenticate user
|
// Authenticate user
|
||||||
const user_ip = req.connection.remoteAddress ?? '';
|
const user_ip = req.connection.remoteAddress ?? '';
|
||||||
const session_id = req.body.session_id;
|
const session_id = req.body.session_id;
|
||||||
const session_key = req.body.session_key;
|
const session_key = req.body.session_key;
|
||||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||||
|
|
||||||
// Get required parameters
|
// Get required parameters
|
||||||
const vendor_id = req.body.vendor_id;
|
const vendor_id = req.body.vendor_id;
|
||||||
const product_id = req.body.product_id;
|
const product_id = req.body.product_id;
|
||||||
const price_in_cents = req.body.price_in_cents;
|
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) {
|
if (success) {
|
||||||
res.status(201).send({});
|
res.status(201).send({});
|
||||||
} else {
|
} else {
|
||||||
res.status(500).send({});
|
res.status(500).send({});
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -21,111 +21,111 @@ export const productsRouter = express.Router();
|
||||||
|
|
||||||
// GET products/
|
// GET products/
|
||||||
productsRouter.get('/', async (req: Request, res: Response) => {
|
productsRouter.get('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
const products: Products = await ProductService.findAll();
|
const products: Products = await ProductService.findAll();
|
||||||
|
|
||||||
res.status(200).send(products);
|
res.status(200).send(products);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// GET products/:id
|
// GET products/:id
|
||||||
productsRouter.get('/:id', async (req: Request, res: Response) => {
|
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) {
|
if (!id) {
|
||||||
res.status(400).send('Missing parameters.');
|
res.status(400).send('Missing parameters.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const product: Product = await ProductService.find(id);
|
const product: Product = await ProductService.find(id);
|
||||||
|
|
||||||
res.status(200).send(product);
|
res.status(200).send(product);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// GET products/search/:term
|
// GET products/search/:term
|
||||||
productsRouter.get('/search/:term', async (req: Request, res: Response) => {
|
productsRouter.get('/search/:term', async (req: Request, res: Response) => {
|
||||||
const term: string = req.params.term;
|
const term: string = req.params.term;
|
||||||
|
|
||||||
if (!term) {
|
if (!term) {
|
||||||
res.status(400).send('Missing parameters.');
|
res.status(400).send('Missing parameters.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const products: Products = await ProductService.findBySearchTerm(term);
|
const products: Products = await ProductService.findBySearchTerm(term);
|
||||||
|
|
||||||
res.status(200).send(products);
|
res.status(200).send(products);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// GET products/list/[1,2,3]
|
// GET products/list/[1,2,3]
|
||||||
productsRouter.get('/list/:ids', async (req: Request, res: Response) => {
|
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) {
|
if (!ids) {
|
||||||
res.status(400).send('Missing parameters.');
|
res.status(400).send('Missing parameters.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const products: Products = await ProductService.findList(ids);
|
const products: Products = await ProductService.findList(ids);
|
||||||
|
|
||||||
res.status(200).send(products);
|
res.status(200).send(products);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// GET products/vendor/:id
|
// GET products/vendor/:id
|
||||||
productsRouter.get('/vendor/:id', async (req: Request, res: Response) => {
|
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) {
|
if (!id) {
|
||||||
res.status(400).send('Missing parameters.');
|
res.status(400).send('Missing parameters.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const products: Products = await ProductService.findByVendor(id);
|
const products: Products = await ProductService.findByVendor(id);
|
||||||
|
|
||||||
res.status(200).send(products);
|
res.status(200).send(products);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// POST products/
|
// POST products/
|
||||||
productsRouter.post('/', async (req: Request, res: Response) => {
|
productsRouter.post('/', async (req: Request, res: Response) => {
|
||||||
const asin: string = req.body.asin;
|
const asin: string = req.body.asin;
|
||||||
|
|
||||||
if (!asin) {
|
if (!asin) {
|
||||||
res.status(400).send('Missing parameters.');
|
res.status(400).send('Missing parameters.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result: boolean = await ProductService.addNewProduct(asin);
|
const result: boolean = await ProductService.addNewProduct(asin);
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
res.status(201).send({});
|
res.status(201).send({});
|
||||||
} else {
|
} else {
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
import express, {Request, Response} from 'express';
|
import express, {Request, Response} from 'express';
|
||||||
import * as UserService from './users.service';
|
import * as UserService from './users.service';
|
||||||
import {User} from './user.interface';
|
import {User} from './user.interface';
|
||||||
|
import {Users} from './users.interface';
|
||||||
import {Session} from './session.interface';
|
import {Session} from './session.interface';
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,100 +22,100 @@ export const usersRouter = express.Router();
|
||||||
|
|
||||||
// POST users/register
|
// POST users/register
|
||||||
usersRouter.post('/register', async (req: Request, res: Response) => {
|
usersRouter.post('/register', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
const username: string = req.body.username;
|
const username: string = req.body.username;
|
||||||
const password: string = req.body.password;
|
const password: string = req.body.password;
|
||||||
const email: string = req.body.email;
|
const email: string = req.body.email;
|
||||||
const ip: string = req.connection.remoteAddress ?? '';
|
const ip: string = req.connection.remoteAddress ?? '';
|
||||||
|
|
||||||
if (!username || !password || !email) {
|
if (!username || !password || !email) {
|
||||||
// Missing
|
// Missing
|
||||||
res.status(400).send(JSON.stringify({message: 'Missing parameters'}));
|
res.status(400).send(JSON.stringify({message: 'Missing parameters'}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if username and / or email are already used
|
// Check if username and / or email are already used
|
||||||
const status = await UserService.checkUsernameAndEmail(username, email);
|
const status = await UserService.checkUsernameAndEmail(username, email);
|
||||||
|
|
||||||
if (status.hasProblems) {
|
if (status.hasProblems) {
|
||||||
// Username and/or email are duplicates, return error
|
// Username and/or email are duplicates, return error
|
||||||
res.status(400).send(JSON.stringify({messages: status.messages, codes: status.codes}));
|
res.status(400).send(JSON.stringify({messages: status.messages, codes: status.codes}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the user and a session
|
// Create the user and a session
|
||||||
const session: Session = await UserService.createUser(username, password, email, ip);
|
const session: Session = await UserService.createUser(username, password, email, ip);
|
||||||
|
|
||||||
// Send the session details back to the user
|
// Send the session details back to the user
|
||||||
res.status(201).send({
|
res.status(201).send({
|
||||||
session_id: session.session_id,
|
session_id: session.session_id,
|
||||||
session_key: session.session_key
|
session_key: session.session_key
|
||||||
});
|
});
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// POST users/login
|
// POST users/login
|
||||||
usersRouter.post('/login', async (req: Request, res: Response) => {
|
usersRouter.post('/login', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
const username: string = req.body.username;
|
const username: string = req.body.username;
|
||||||
const password: string = req.body.password;
|
const password: string = req.body.password;
|
||||||
const ip: string = req.connection.remoteAddress ?? '';
|
const ip: string = req.connection.remoteAddress ?? '';
|
||||||
|
|
||||||
if (!username || !password) {
|
if (!username || !password) {
|
||||||
// Missing
|
// Missing
|
||||||
res.status(400).send(JSON.stringify({message: 'Missing parameters'}));
|
res.status(400).send(JSON.stringify({message: 'Missing parameters'}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the user entry and create a session
|
// Update the user entry and create a session
|
||||||
const session: Session = await UserService.login(username, password, ip);
|
const session: Session = await UserService.login(username, password, ip);
|
||||||
|
|
||||||
if (!session.session_id) {
|
if (!session.session_id) {
|
||||||
// Error logging in, probably wrong username / password
|
// Error logging in, probably wrong username / password
|
||||||
res.status(401).send(JSON.stringify({messages: ['Wrong username and / or password'], codes: [1, 4]}));
|
res.status(401).send(JSON.stringify({messages: ['Wrong username and / or password'], codes: [1, 4]}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the session details back to the user
|
// Send the session details back to the user
|
||||||
res.status(200).send({
|
res.status(200).send({
|
||||||
session_id: session.session_id,
|
session_id: session.session_id,
|
||||||
session_key: session.session_key
|
session_key: session.session_key
|
||||||
});
|
});
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// POST users/checkSessionValid
|
// POST users/checkSessionValid
|
||||||
usersRouter.post('/checkSessionValid', async (req: Request, res: Response) => {
|
usersRouter.post('/checkSessionValid', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
const ip: string = req.connection.remoteAddress ?? '';
|
const ip: string = req.connection.remoteAddress ?? '';
|
||||||
const session_id = req.body.session_id;
|
const session_id = req.body.session_id;
|
||||||
const session_key = req.body.session_key;
|
const session_key = req.body.session_key;
|
||||||
|
|
||||||
if (!session_id || !session_key) {
|
if(!session_id || !session_key) {
|
||||||
// Error logging in, probably wrong username / password
|
// Error logging in, probably wrong username / password
|
||||||
res.status(401).send(JSON.stringify({messages: ['No session detected'], codes: [5]}));
|
res.status(401).send(JSON.stringify({messages: ['No session detected'], codes: [5]}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the user entry and create a session
|
// Update the user entry and create a session
|
||||||
const user: User = await UserService.checkSession(session_id, session_key, ip);
|
const user: User = await UserService.checkSession(session_id, session_key, ip);
|
||||||
|
|
||||||
if (!user.user_id) {
|
if (!user.user_id) {
|
||||||
// Error logging in, probably wrong username / password
|
// Error logging in, probably wrong username / password
|
||||||
res.status(401).send(JSON.stringify({messages: ['Invalid session'], codes: [5]}));
|
res.status(401).send(JSON.stringify({messages: ['Invalid session'], codes: [5]}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the session details back to the user
|
// Send the session details back to the user
|
||||||
res.status(200).send(user);
|
res.status(200).send(user);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
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/
|
// GET vendors/
|
||||||
vendorsRouter.get('/', async (req: Request, res: Response) => {
|
vendorsRouter.get('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
const vendors: Vendors = await VendorService.findAll();
|
const vendors: Vendors = await VendorService.findAll();
|
||||||
|
|
||||||
res.status(200).send(vendors);
|
res.status(200).send(vendors);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// GET vendors/managed
|
// GET vendors/managed
|
||||||
vendorsRouter.get('/managed', async (req: Request, res: Response) => {
|
vendorsRouter.get('/managed', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
// Authenticate user
|
// Authenticate user
|
||||||
const user_ip = req.connection.remoteAddress ?? '';
|
const user_ip = req.connection.remoteAddress ?? '';
|
||||||
const session_id = (req.query.session_id ?? '').toString();
|
const session_id = (req.query.session_id ?? '').toString();
|
||||||
const session_key = (req.query.session_key ?? '').toString();
|
const session_key = (req.query.session_key ?? '').toString();
|
||||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
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);
|
res.status(200).send(vendors);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// GET vendors/:id
|
// GET vendors/:id
|
||||||
vendorsRouter.get('/:id', async (req: Request, res: Response) => {
|
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) {
|
if (!id) {
|
||||||
res.status(400).send('Missing parameters.');
|
res.status(400).send('Missing parameters.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const vendor: Vendor = await VendorService.find(id);
|
const vendor: Vendor = await VendorService.find(id);
|
||||||
|
|
||||||
res.status(200).send(vendor);
|
res.status(200).send(vendor);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// GET vendors/search/:term
|
// GET vendors/search/:term
|
||||||
vendorsRouter.get('/search/:term', async (req: Request, res: Response) => {
|
vendorsRouter.get('/search/:term', async (req: Request, res: Response) => {
|
||||||
const term: string = req.params.term;
|
const term: string = req.params.term;
|
||||||
|
|
||||||
if (!term) {
|
if (!term) {
|
||||||
res.status(400).send('Missing parameters.');
|
res.status(400).send('Missing parameters.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const vendors: Vendors = await VendorService.findBySearchTerm(term);
|
const vendors: Vendors = await VendorService.findBySearchTerm(term);
|
||||||
|
|
||||||
res.status(200).send(vendors);
|
res.status(200).send(vendors);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// PUT vendors/manage/deactivatelisting
|
// PUT vendors/manage/deactivatelisting
|
||||||
vendorsRouter.put('/manage/deactivatelisting', async (req: Request, res: Response) => {
|
vendorsRouter.put('/manage/deactivatelisting', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
// Authenticate user
|
// Authenticate user
|
||||||
const user_ip = req.connection.remoteAddress ?? '';
|
const user_ip = req.connection.remoteAddress ?? '';
|
||||||
const session_id = req.body.session_id;
|
const session_id = req.body.session_id;
|
||||||
const session_key = req.body.session_key;
|
const session_key = req.body.session_key;
|
||||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||||
|
|
||||||
// Get required parameters
|
// Get required parameters
|
||||||
const vendor_id = req.body.vendor_id;
|
const vendor_id = req.body.vendor_id;
|
||||||
const product_id = req.body.product_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) {
|
if (success) {
|
||||||
res.status(200).send({});
|
res.status(200).send({});
|
||||||
} else {
|
} else {
|
||||||
res.status(500).send({});
|
res.status(500).send({});
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// PUT vendors/manage/shop/deactivate/:id
|
// PUT vendors/manage/shop/deactivate/:id
|
||||||
vendorsRouter.put('/manage/shop/deactivate/:id', async (req: Request, res: Response) => {
|
vendorsRouter.put('/manage/shop/deactivate/:id', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
// Authenticate user
|
// Authenticate user
|
||||||
const user_ip = req.connection.remoteAddress ?? '';
|
const user_ip = req.connection.remoteAddress ?? '';
|
||||||
const session_id = req.body.session_id;
|
const session_id = req.body.session_id;
|
||||||
const session_key = req.body.session_key;
|
const session_key = req.body.session_key;
|
||||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||||
|
|
||||||
// Get required parameters
|
// Get required parameters
|
||||||
const vendor_id = parseInt(req.params.id, 10);
|
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) {
|
if (success) {
|
||||||
res.status(200).send({});
|
res.status(200).send({});
|
||||||
} else {
|
} else {
|
||||||
res.status(500).send({});
|
res.status(500).send({});
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// PUT vendors/manage/shop/activate/:id
|
// PUT vendors/manage/shop/activate/:id
|
||||||
vendorsRouter.put('/manage/shop/activate/:id', async (req: Request, res: Response) => {
|
vendorsRouter.put('/manage/shop/activate/:id', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
// Authenticate user
|
// Authenticate user
|
||||||
const user_ip = req.connection.remoteAddress ?? '';
|
const user_ip = req.connection.remoteAddress ?? '';
|
||||||
const session_id = req.body.session_id;
|
const session_id = req.body.session_id;
|
||||||
const session_key = req.body.session_key;
|
const session_key = req.body.session_key;
|
||||||
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
const user = await UserService.checkSession(session_id, session_key, user_ip);
|
||||||
|
|
||||||
// Get required parameters
|
// Get required parameters
|
||||||
const vendor_id = parseInt(req.params.id, 10);
|
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) {
|
if (success) {
|
||||||
res.status(200).send({});
|
res.status(200).send({});
|
||||||
} else {
|
} else {
|
||||||
res.status(500).send({});
|
res.status(500).send({});
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
console.log('Error handling a request: ' + e.message);
|
console.log('Error handling a request: ' + e.message);
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
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.use('/ratings', routeRatingsRouter);
|
||||||
|
|
||||||
crrRouter.get('/', async (req: Request, res: Response) => {
|
crrRouter.get('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
res.status(200).send('Pluto Development Climbing Route Rating API Endpoint');
|
res.status(200).send('Pluto Development Climbing Route Rating API Endpoint');
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
let errorGuid = Guid.create().toString();
|
let errorGuid = Guid.create().toString();
|
||||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
'status': 'PROCESSING_ERROR',
|
'status': 'PROCESSING_ERROR',
|
||||||
'message': 'Internal Server Error. Try again later.',
|
'message': 'Internal Server Error. Try again later.',
|
||||||
'reference': errorGuid
|
'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.
|
* description: A server error occurred. Please try again. If this issue persists, contact the admin.
|
||||||
*/
|
*/
|
||||||
climbingGymRouter.get('/', async (req: Request, res: Response) => {
|
climbingGymRouter.get('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
const gyms: ClimbingGym[] = await GymService.findAll();
|
const gyms: ClimbingGym[] = await GymService.findAll();
|
||||||
|
|
||||||
res.status(200).send(gyms);
|
res.status(200).send(gyms);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
let errorGuid = Guid.create().toString();
|
let errorGuid = Guid.create().toString();
|
||||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
'status': 'PROCESSING_ERROR',
|
'status': 'PROCESSING_ERROR',
|
||||||
'message': 'Internal Server Error. Try again later.',
|
'message': 'Internal Server Error. Try again later.',
|
||||||
'reference': errorGuid
|
'reference': errorGuid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -116,37 +116,37 @@ climbingGymRouter.get('/', async (req: Request, res: Response) => {
|
||||||
* example: P0_ey[...]bVu
|
* example: P0_ey[...]bVu
|
||||||
*/
|
*/
|
||||||
climbingGymRouter.post('/', async (req: Request, res: Response) => {
|
climbingGymRouter.post('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
let name = req.query.name as string;
|
let name = req.query.name as string;
|
||||||
let city = req.query.city as string;
|
let city = req.query.city as string;
|
||||||
let captcha_token = req.query['hcaptcha_response'] as string;
|
let captcha_token = req.query['hcaptcha_response'] as string;
|
||||||
|
|
||||||
if (!name || !city || !captcha_token) {
|
if (!name || !city || !captcha_token) {
|
||||||
res.status(400).send({'message': 'Missing parameters'});
|
res.status(400).send({'message': 'Missing parameters'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify captcha
|
// Verify captcha
|
||||||
let success = await verifyCaptcha(captcha_token);
|
let success = await verifyCaptcha(captcha_token);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
res.status(403).send({'message': 'Invalid Captcha. Please try again.'});
|
res.status(403).send({'message': 'Invalid Captcha. Please try again.'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = await GymService.createGym(name, city);
|
let result = await GymService.createGym(name, city);
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
res.status(201).send({'gym_id': result});
|
res.status(201).send({'gym_id': result});
|
||||||
} else {
|
} else {
|
||||||
res.status(500).send({});
|
res.status(500).send({});
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
let errorGuid = Guid.create().toString();
|
let errorGuid = Guid.create().toString();
|
||||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
'status': 'PROCESSING_ERROR',
|
'status': 'PROCESSING_ERROR',
|
||||||
'message': 'Internal Server Error. Try again later.',
|
'message': 'Internal Server Error. Try again later.',
|
||||||
'reference': errorGuid
|
'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.
|
* description: A server error occurred. Please try again. If this issue persists, contact the admin.
|
||||||
*/
|
*/
|
||||||
climbingRoutesRouter.get('/', async (req: Request, res: Response) => {
|
climbingRoutesRouter.get('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
const routes: ClimbingRoute[] = await RouteService.findAll();
|
const routes: ClimbingRoute[] = await RouteService.findAll();
|
||||||
|
|
||||||
res.status(200).send(routes);
|
res.status(200).send(routes);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
let errorGuid = Guid.create().toString();
|
let errorGuid = Guid.create().toString();
|
||||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
'status': 'PROCESSING_ERROR',
|
'status': 'PROCESSING_ERROR',
|
||||||
'message': 'Internal Server Error. Try again later.',
|
'message': 'Internal Server Error. Try again later.',
|
||||||
'reference': errorGuid
|
'reference': errorGuid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -120,21 +120,21 @@ climbingRoutesRouter.get('/', async (req: Request, res: Response) => {
|
||||||
* example: duck-score-guide
|
* example: duck-score-guide
|
||||||
*/
|
*/
|
||||||
climbingRoutesRouter.get('/:id', async (req: Request, res: Response) => {
|
climbingRoutesRouter.get('/:id', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
let route_id = req.params.id;
|
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);
|
res.status(200).send(route);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
let errorGuid = Guid.create().toString();
|
let errorGuid = Guid.create().toString();
|
||||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
'status': 'PROCESSING_ERROR',
|
'status': 'PROCESSING_ERROR',
|
||||||
'message': 'Internal Server Error. Try again later.',
|
'message': 'Internal Server Error. Try again later.',
|
||||||
'reference': errorGuid
|
'reference': errorGuid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -194,33 +194,33 @@ climbingRoutesRouter.get('/:id', async (req: Request, res: Response) => {
|
||||||
* example: P0_ey[...]bVu
|
* example: P0_ey[...]bVu
|
||||||
*/
|
*/
|
||||||
climbingRoutesRouter.post('/', async (req: Request, res: Response) => {
|
climbingRoutesRouter.post('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
let gym_id = Number(req.query.gym_id);
|
let gym_id = Number(req.query.gym_id);
|
||||||
let name = req.query.name as string;
|
let name = req.query.name as string;
|
||||||
let difficulty = req.query.difficulty as string;
|
let difficulty = req.query.difficulty as string;
|
||||||
let captcha_token = req.query['hcaptcha_response'] as string;
|
let captcha_token = req.query['hcaptcha_response'] as string;
|
||||||
|
|
||||||
if (isNaN(gym_id) || !name || !difficulty || !captcha_token) {
|
if (isNaN(gym_id) || !name || !difficulty || !captcha_token) {
|
||||||
res.status(400).send({'message': 'Missing parameters'});
|
res.status(400).send({'message': 'Missing parameters'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify captcha
|
// Verify captcha
|
||||||
if (!await verifyCaptcha(captcha_token)) {
|
if (!await verifyCaptcha(captcha_token)) {
|
||||||
res.status(403).send({'message': 'Invalid Captcha. Please try again.'});
|
res.status(403).send({'message': 'Invalid Captcha. Please try again.'});
|
||||||
return;
|
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});
|
res.status(201).send({'route_id': route_id});
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
let errorGuid = Guid.create().toString();
|
let errorGuid = Guid.create().toString();
|
||||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
'status': 'PROCESSING_ERROR',
|
'status': 'PROCESSING_ERROR',
|
||||||
'message': 'Internal Server Error. Try again later.',
|
'message': 'Internal Server Error. Try again later.',
|
||||||
'reference': errorGuid
|
'reference': errorGuid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -53,21 +53,21 @@ export const routeCommentsRouter = express.Router();
|
||||||
* example: duck-score-guide
|
* example: duck-score-guide
|
||||||
*/
|
*/
|
||||||
routeCommentsRouter.get('/by/route/:id', async (req: Request, res: Response) => {
|
routeCommentsRouter.get('/by/route/:id', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
let route_id = req.params.id;
|
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);
|
res.status(200).send(comments);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
let errorGuid = Guid.create().toString();
|
let errorGuid = Guid.create().toString();
|
||||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
'status': 'PROCESSING_ERROR',
|
'status': 'PROCESSING_ERROR',
|
||||||
'message': 'Internal Server Error. Try again later.',
|
'message': 'Internal Server Error. Try again later.',
|
||||||
'reference': errorGuid
|
'reference': errorGuid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -120,36 +120,36 @@ routeCommentsRouter.get('/by/route/:id', async (req: Request, res: Response) =>
|
||||||
* example: P0_ey[...]bVu
|
* example: P0_ey[...]bVu
|
||||||
*/
|
*/
|
||||||
routeCommentsRouter.post('/', async (req: Request, res: Response) => {
|
routeCommentsRouter.post('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
let route_id = req.query.route_id as string;
|
let route_id = req.query.route_id as string;
|
||||||
let comment = req.query.comment as string;
|
let comment = req.query.comment as string;
|
||||||
let captcha_token = req.query['hcaptcha_response'] as string;
|
let captcha_token = req.query['hcaptcha_response'] as string;
|
||||||
|
|
||||||
if (!route_id || !comment || !captcha_token) {
|
if (!route_id || !comment || !captcha_token) {
|
||||||
res.status(400).send({'message': 'Missing parameters'});
|
res.status(400).send({'message': 'Missing parameters'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify captcha
|
// Verify captcha
|
||||||
if (!await verifyCaptcha(captcha_token)) {
|
if (!await verifyCaptcha(captcha_token)) {
|
||||||
res.status(403).send({'message': 'Invalid Captcha. Please try again.'});
|
res.status(403).send({'message': 'Invalid Captcha. Please try again.'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = await CommentService.createComment(route_id, comment);
|
let result = await CommentService.createComment(route_id, comment);
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
res.status(201).send({'comment_id': result});
|
res.status(201).send({'comment_id': result});
|
||||||
} else {
|
} else {
|
||||||
res.status(500).send({});
|
res.status(500).send({});
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
let errorGuid = Guid.create().toString();
|
let errorGuid = Guid.create().toString();
|
||||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
'status': 'PROCESSING_ERROR',
|
'status': 'PROCESSING_ERROR',
|
||||||
'message': 'Internal Server Error. Try again later.',
|
'message': 'Internal Server Error. Try again later.',
|
||||||
'reference': errorGuid
|
'reference': errorGuid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -38,21 +38,21 @@ export const routeRatingsRouter = express.Router();
|
||||||
* example: duck-score-guide
|
* example: duck-score-guide
|
||||||
*/
|
*/
|
||||||
routeRatingsRouter.get('/by/route/:id', async (req: Request, res: Response) => {
|
routeRatingsRouter.get('/by/route/:id', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
let route_id = req.params.id;
|
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});
|
res.status(200).send({'rating': rating});
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
let errorGuid = Guid.create().toString();
|
let errorGuid = Guid.create().toString();
|
||||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
'status': 'PROCESSING_ERROR',
|
'status': 'PROCESSING_ERROR',
|
||||||
'message': 'Internal Server Error. Try again later.',
|
'message': 'Internal Server Error. Try again later.',
|
||||||
'reference': errorGuid
|
'reference': errorGuid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -105,36 +105,36 @@ routeRatingsRouter.get('/by/route/:id', async (req: Request, res: Response) => {
|
||||||
* example: P0_ey[...]bVu
|
* example: P0_ey[...]bVu
|
||||||
*/
|
*/
|
||||||
routeRatingsRouter.post('/', async (req: Request, res: Response) => {
|
routeRatingsRouter.post('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
let route_id = req.query.route_id as string;
|
let route_id = req.query.route_id as string;
|
||||||
let stars = Number(req.query.stars);
|
let stars = Number(req.query.stars);
|
||||||
let captcha_token = req.query['hcaptcha_response'] as string;
|
let captcha_token = req.query['hcaptcha_response'] as string;
|
||||||
|
|
||||||
if (!route_id || isNaN(stars) || !captcha_token) {
|
if (!route_id || isNaN(stars) || !captcha_token) {
|
||||||
res.status(400).send({'message': 'Missing parameters'});
|
res.status(400).send({'message': 'Missing parameters'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify captcha
|
// Verify captcha
|
||||||
if (!await verifyCaptcha(captcha_token)) {
|
if (!await verifyCaptcha(captcha_token)) {
|
||||||
res.status(403).send({'message': 'Invalid Captcha. Please try again.'});
|
res.status(403).send({'message': 'Invalid Captcha. Please try again.'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = await RatingService.createRating(route_id, stars);
|
let result = await RatingService.createRating(route_id, stars);
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
res.status(201).send({'rating_id': result});
|
res.status(201).send({'rating_id': result});
|
||||||
} else {
|
} else {
|
||||||
res.status(500).send({});
|
res.status(500).send({});
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
let errorGuid = Guid.create().toString();
|
let errorGuid = Guid.create().toString();
|
||||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
'status': 'PROCESSING_ERROR',
|
'status': 'PROCESSING_ERROR',
|
||||||
'message': 'Internal Server Error. Try again later.',
|
'message': 'Internal Server Error. Try again later.',
|
||||||
'reference': errorGuid
|
'reference': errorGuid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -12,37 +12,37 @@ import * as ChangeService from './changes/changes.service';
|
||||||
export const dhbwRaPlaChangesRouter = express.Router();
|
export const dhbwRaPlaChangesRouter = express.Router();
|
||||||
|
|
||||||
dhbwRaPlaChangesRouter.get('/', async (req: Request, res: Response) => {
|
dhbwRaPlaChangesRouter.get('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
let week = (req.query.week ?? '').toString();
|
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);
|
res.status(200).send(changes);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
let errorGuid = Guid.create().toString();
|
let errorGuid = Guid.create().toString();
|
||||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
'status': 'PROCESSING_ERROR',
|
'status': 'PROCESSING_ERROR',
|
||||||
'message': 'Internal Server Error. Try again later.',
|
'message': 'Internal Server Error. Try again later.',
|
||||||
'reference': errorGuid
|
'reference': errorGuid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
dhbwRaPlaChangesRouter.get('/:id', async (req: Request, res: Response) => {
|
dhbwRaPlaChangesRouter.get('/:id', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
let id: string = (req.params.id ?? '').toString();
|
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);
|
res.status(200).send(changes);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
let errorGuid = Guid.create().toString();
|
let errorGuid = Guid.create().toString();
|
||||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
'status': 'PROCESSING_ERROR',
|
'status': 'PROCESSING_ERROR',
|
||||||
'message': 'Internal Server Error. Try again later.',
|
'message': 'Internal Server Error. Try again later.',
|
||||||
'reference': errorGuid
|
'reference': errorGuid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -15,15 +15,15 @@ export const dhbwServiceRouter = express.Router();
|
||||||
dhbwServiceRouter.use('/generalInfo', generalInfoRouter);
|
dhbwServiceRouter.use('/generalInfo', generalInfoRouter);
|
||||||
|
|
||||||
dhbwServiceRouter.get('/', async (req: Request, res: Response) => {
|
dhbwServiceRouter.get('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
res.status(200).send('Pluto Development DHBW Service App API Endpoint');
|
res.status(200).send('Pluto Development DHBW Service App API Endpoint');
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
let errorGuid = Guid.create().toString();
|
let errorGuid = Guid.create().toString();
|
||||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
'status': 'PROCESSING_ERROR',
|
'status': 'PROCESSING_ERROR',
|
||||||
'message': 'Internal Server Error. Try again later.',
|
'message': 'Internal Server Error. Try again later.',
|
||||||
'reference': errorGuid
|
'reference': errorGuid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -11,29 +11,29 @@ import {Guid} from 'guid-typescript';
|
||||||
export const generalInfoRouter = express.Router();
|
export const generalInfoRouter = express.Router();
|
||||||
|
|
||||||
generalInfoRouter.get('/', async (req: Request, res: Response) => {
|
generalInfoRouter.get('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
res.status(200).send('GET generalInfo v2.1');
|
res.status(200).send('GET generalInfo v2.1');
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
let errorGuid = Guid.create().toString();
|
let errorGuid = Guid.create().toString();
|
||||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
'status': 'PROCESSING_ERROR',
|
'status': 'PROCESSING_ERROR',
|
||||||
'message': 'Internal Server Error. Try again later.',
|
'message': 'Internal Server Error. Try again later.',
|
||||||
'reference': errorGuid
|
'reference': errorGuid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
generalInfoRouter.post('/', async (req: Request, res: Response) => {
|
generalInfoRouter.post('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
res.status(200).send('POST generalInfo v2.1');
|
res.status(200).send('POST generalInfo v2.1');
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
let errorGuid = Guid.create().toString();
|
let errorGuid = Guid.create().toString();
|
||||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
'status': 'PROCESSING_ERROR',
|
'status': 'PROCESSING_ERROR',
|
||||||
'message': 'Internal Server Error. Try again later.',
|
'message': 'Internal Server Error. Try again later.',
|
||||||
'reference': errorGuid
|
'reference': errorGuid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -27,15 +27,15 @@ partyPlanerRouter.use('/session', sessionRouter);
|
||||||
partyPlanerRouter.use('/user', userRouter);
|
partyPlanerRouter.use('/user', userRouter);
|
||||||
|
|
||||||
partyPlanerRouter.get('/', async (req: Request, res: Response) => {
|
partyPlanerRouter.get('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
res.status(200).send('Pluto Development PartyPlaner API Endpoint V2');
|
res.status(200).send('Pluto Development PartyPlaner API Endpoint V2');
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
let errorGuid = Guid.create().toString();
|
let errorGuid = Guid.create().toString();
|
||||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
'status': 'PROCESSING_ERROR',
|
'status': 'PROCESSING_ERROR',
|
||||||
'message': 'Internal Server Error. Try again later.',
|
'message': 'Internal Server Error. Try again later.',
|
||||||
'reference': errorGuid
|
'reference': errorGuid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -13,39 +13,39 @@ import {Guid} from 'guid-typescript';
|
||||||
export const eventRouter = express.Router();
|
export const eventRouter = express.Router();
|
||||||
|
|
||||||
eventRouter.get('/:isDevCall', async (req: Request, res: Response) => {
|
eventRouter.get('/:isDevCall', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
throw new Error('Test');
|
throw new Error('Test');
|
||||||
let userId = (req.query.userId ?? '').toString();
|
let userId = (req.query.userId ?? '').toString();
|
||||||
let sessionId = (req.query.sessionId ?? '').toString();
|
let sessionId = (req.query.sessionId ?? '').toString();
|
||||||
let sessionKey = (req.query.sessionKey ?? '').toString();
|
let sessionKey = (req.query.sessionKey ?? '').toString();
|
||||||
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
||||||
|
|
||||||
if (userId === '' || sessionId === '' || sessionKey === '') {
|
if (userId === '' || sessionId === '' || sessionKey === '') {
|
||||||
res.status(400).send({
|
res.status(400).send({
|
||||||
'status': 'WRONG_PARAMS',
|
'status': 'WRONG_PARAMS',
|
||||||
'message': 'Missing or wrong parameters'
|
'message': 'Missing or wrong parameters'
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!await UserService.checkSession(useDev, userId, sessionId, sessionKey)) {
|
if (!await UserService.checkSession(useDev, userId, sessionId, sessionKey)) {
|
||||||
res.status(403).send({
|
res.status(403).send({
|
||||||
'status': 'INVALID_SESSION',
|
'status': 'INVALID_SESSION',
|
||||||
'message': 'The user or session could not be found or the session is invalid'
|
'message': 'The user or session could not be found or the session is invalid'
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let data = await EventService.getEventData(useDev, userId);
|
let data = await EventService.getEventData(useDev, userId);
|
||||||
|
|
||||||
res.status(200).send(data);
|
res.status(200).send(data);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
let errorGuid = Guid.create().toString();
|
let errorGuid = Guid.create().toString();
|
||||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
'status': 'PROCESSING_ERROR',
|
'status': 'PROCESSING_ERROR',
|
||||||
'message': 'Internal Server Error. Try again later.',
|
'message': 'Internal Server Error. Try again later.',
|
||||||
'reference': errorGuid
|
'reference': errorGuid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -13,38 +13,38 @@ import {Guid} from 'guid-typescript';
|
||||||
export const friendshipRouter = express.Router();
|
export const friendshipRouter = express.Router();
|
||||||
|
|
||||||
friendshipRouter.get('/:isDevCall', async (req: Request, res: Response) => {
|
friendshipRouter.get('/:isDevCall', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
let userId = (req.query.userId ?? '').toString();
|
let userId = (req.query.userId ?? '').toString();
|
||||||
let sessionId = (req.query.sessionId ?? '').toString();
|
let sessionId = (req.query.sessionId ?? '').toString();
|
||||||
let sessionKey = (req.query.sessionKey ?? '').toString();
|
let sessionKey = (req.query.sessionKey ?? '').toString();
|
||||||
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
||||||
|
|
||||||
if (userId === '' || sessionId === '' || sessionKey === '') {
|
if (userId === '' || sessionId === '' || sessionKey === '') {
|
||||||
res.status(400).send({
|
res.status(400).send({
|
||||||
'status': 'WRONG_PARAMS',
|
'status': 'WRONG_PARAMS',
|
||||||
'message': 'Missing or wrong parameters'
|
'message': 'Missing or wrong parameters'
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!await UserService.checkSession(useDev, userId, sessionId, sessionKey)) {
|
if (!await UserService.checkSession(useDev, userId, sessionId, sessionKey)) {
|
||||||
res.status(403).send({
|
res.status(403).send({
|
||||||
'status': 'INVALID_SESSION',
|
'status': 'INVALID_SESSION',
|
||||||
'message': 'The user or session could not be found or the session is invalid'
|
'message': 'The user or session could not be found or the session is invalid'
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let data = await FriendshipService.getFriendshipData(useDev, userId);
|
let data = await FriendshipService.getFriendshipData(useDev, userId);
|
||||||
|
|
||||||
res.status(200).send(data);
|
res.status(200).send(data);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
let errorGuid = Guid.create().toString();
|
let errorGuid = Guid.create().toString();
|
||||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
'status': 'PROCESSING_ERROR',
|
'status': 'PROCESSING_ERROR',
|
||||||
'message': 'Internal Server Error. Try again later.',
|
'message': 'Internal Server Error. Try again later.',
|
||||||
'reference': errorGuid
|
'reference': errorGuid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -13,38 +13,38 @@ import {Guid} from 'guid-typescript';
|
||||||
export const inviteRouter = express.Router();
|
export const inviteRouter = express.Router();
|
||||||
|
|
||||||
inviteRouter.get('/:isDevCall', async (req: Request, res: Response) => {
|
inviteRouter.get('/:isDevCall', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
let userId = (req.query.userId ?? '').toString();
|
let userId = (req.query.userId ?? '').toString();
|
||||||
let sessionId = (req.query.sessionId ?? '').toString();
|
let sessionId = (req.query.sessionId ?? '').toString();
|
||||||
let sessionKey = (req.query.sessionKey ?? '').toString();
|
let sessionKey = (req.query.sessionKey ?? '').toString();
|
||||||
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
||||||
|
|
||||||
if (userId === '' || sessionId === '' || sessionKey === '') {
|
if (userId === '' || sessionId === '' || sessionKey === '') {
|
||||||
res.status(400).send({
|
res.status(400).send({
|
||||||
'status': 'WRONG_PARAMS',
|
'status': 'WRONG_PARAMS',
|
||||||
'message': 'Missing or wrong parameters'
|
'message': 'Missing or wrong parameters'
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!await UserService.checkSession(useDev, userId, sessionId, sessionKey)) {
|
if (!await UserService.checkSession(useDev, userId, sessionId, sessionKey)) {
|
||||||
res.status(403).send({
|
res.status(403).send({
|
||||||
'status': 'INVALID_SESSION',
|
'status': 'INVALID_SESSION',
|
||||||
'message': 'The user or session could not be found or the session is invalid'
|
'message': 'The user or session could not be found or the session is invalid'
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let data = await InviteService.getInvitesData(useDev, userId);
|
let data = await InviteService.getInvitesData(useDev, userId);
|
||||||
|
|
||||||
res.status(200).send(data);
|
res.status(200).send(data);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
let errorGuid = Guid.create().toString();
|
let errorGuid = Guid.create().toString();
|
||||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
'status': 'PROCESSING_ERROR',
|
'status': 'PROCESSING_ERROR',
|
||||||
'message': 'Internal Server Error. Try again later.',
|
'message': 'Internal Server Error. Try again later.',
|
||||||
'reference': errorGuid
|
'reference': errorGuid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -12,59 +12,59 @@ import {Guid} from 'guid-typescript';
|
||||||
export const loginRouter = express.Router();
|
export const loginRouter = express.Router();
|
||||||
|
|
||||||
loginRouter.post('/:isDevCall', async (req: Request, res: Response) => {
|
loginRouter.post('/:isDevCall', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
let username: string = '';
|
let username: string = '';
|
||||||
let email: string = '';
|
let email: string = '';
|
||||||
let password: string = '';
|
let password: string = '';
|
||||||
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
||||||
|
|
||||||
// Send error when content-type header is missing
|
// Send error when content-type header is missing
|
||||||
if (!req.headers['content-type']) {
|
if (!req.headers['content-type']) {
|
||||||
res.status(400).send({
|
res.status(400).send({
|
||||||
'status': 'MISSING_CONTENT_TYPE',
|
'status': 'MISSING_CONTENT_TYPE',
|
||||||
'message': 'Please set the content-type header field'
|
'message': 'Please set the content-type header field'
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// API accepts both JSON in body and HTTP parameters
|
// API accepts both JSON in body and HTTP parameters
|
||||||
if (req.headers['content-type'] === 'application/json') {
|
if (req.headers['content-type'] === 'application/json') {
|
||||||
username = req.body.username;
|
username = req.body.username;
|
||||||
email = req.body.email;
|
email = req.body.email;
|
||||||
password = req.body.password;
|
password = req.body.password;
|
||||||
} else if (req.headers['content-type'] === 'application/x-www-form-urlencoded') {
|
} else if (req.headers['content-type'] === 'application/x-www-form-urlencoded') {
|
||||||
username = (req.query.username ?? '').toString();
|
username = (req.query.username ?? '').toString();
|
||||||
email = (req.query.email ?? '').toString();
|
email = (req.query.email ?? '').toString();
|
||||||
password = (req.query.password ?? '').toString();
|
password = (req.query.password ?? '').toString();
|
||||||
} else {
|
} else {
|
||||||
res.status(400).send({
|
res.status(400).send({
|
||||||
'status': 'WRONG_CONTENT_TYPE',
|
'status': 'WRONG_CONTENT_TYPE',
|
||||||
'message': 'The transmitted content-type is not supported'
|
'message': 'The transmitted content-type is not supported'
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let userIP = req.socket.remoteAddress ?? '';
|
let userIP = req.socket.remoteAddress ?? '';
|
||||||
let deviceInfo = req.headers['user-agent'] ?? '';
|
let deviceInfo = req.headers['user-agent'] ?? '';
|
||||||
|
|
||||||
if ((username === '' && email === '') || password === '') {
|
if ((username === '' && email === '') || password === '') {
|
||||||
res.status(400).send({
|
res.status(400).send({
|
||||||
'status': 'WRONG_PARAMS',
|
'status': 'WRONG_PARAMS',
|
||||||
'message': 'Missing or wrong parameters'
|
'message': 'Missing or wrong parameters'
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check password and create session
|
// Check password and create session
|
||||||
let session = await UserService.loginUser(useDev, username, email, password, userIP, deviceInfo);
|
let session = await UserService.loginUser(useDev, username, email, password, userIP, deviceInfo);
|
||||||
|
|
||||||
res.status(200).send(session);
|
res.status(200).send(session);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
let errorGuid = Guid.create().toString();
|
let errorGuid = Guid.create().toString();
|
||||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
'status': 'PROCESSING_ERROR',
|
'status': 'PROCESSING_ERROR',
|
||||||
'message': 'Internal Server Error. Try again later.',
|
'message': 'Internal Server Error. Try again later.',
|
||||||
'reference': errorGuid
|
'reference': errorGuid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -12,78 +12,78 @@ import {Guid} from 'guid-typescript';
|
||||||
export const registerRouter = express.Router();
|
export const registerRouter = express.Router();
|
||||||
|
|
||||||
registerRouter.post('/:isDevCall', async (req: Request, res: Response) => {
|
registerRouter.post('/:isDevCall', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
let username: string = '';
|
let username: string = '';
|
||||||
let email: string = '';
|
let email: string = '';
|
||||||
let firstName: string = '';
|
let firstName: string = '';
|
||||||
let lastName: string = '';
|
let lastName: string = '';
|
||||||
let password: string = '';
|
let password: string = '';
|
||||||
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
||||||
|
|
||||||
// Send error when content-type header is missing
|
// Send error when content-type header is missing
|
||||||
if (!req.headers['content-type']) {
|
if (!req.headers['content-type']) {
|
||||||
res.status(400).send({
|
res.status(400).send({
|
||||||
'status': 'MISSING_CONTENT_TYPE',
|
'status': 'MISSING_CONTENT_TYPE',
|
||||||
'message': 'Please set the content-type header field'
|
'message': 'Please set the content-type header field'
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// API accepts both JSON in body and HTTP parameters
|
// API accepts both JSON in body and HTTP parameters
|
||||||
if (req.headers['content-type'] === 'application/json') {
|
if (req.headers['content-type'] === 'application/json') {
|
||||||
username = req.body.username;
|
username = req.body.username;
|
||||||
email = req.body.email;
|
email = req.body.email;
|
||||||
firstName = req.body.firstName;
|
firstName = req.body.firstName;
|
||||||
lastName = req.body.lastName;
|
lastName = req.body.lastName;
|
||||||
password = req.body.password;
|
password = req.body.password;
|
||||||
} else if (req.headers['content-type'] === 'application/x-www-form-urlencoded') {
|
} else if (req.headers['content-type'] === 'application/x-www-form-urlencoded') {
|
||||||
username = (req.query.username ?? '').toString();
|
username = (req.query.username ?? '').toString();
|
||||||
email = (req.query.email ?? '').toString();
|
email = (req.query.email ?? '').toString();
|
||||||
firstName = (req.query.firstName ?? '').toString();
|
firstName = (req.query.firstName ?? '').toString();
|
||||||
lastName = (req.query.lastName ?? '').toString();
|
lastName = (req.query.lastName ?? '').toString();
|
||||||
password = (req.query.password ?? '').toString();
|
password = (req.query.password ?? '').toString();
|
||||||
} else {
|
} else {
|
||||||
res.status(400).send({
|
res.status(400).send({
|
||||||
'status': 'WRONG_CONTENT_TYPE',
|
'status': 'WRONG_CONTENT_TYPE',
|
||||||
'message': 'The transmitted content-type is not supported'
|
'message': 'The transmitted content-type is not supported'
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let userIP = req.socket.remoteAddress ?? '';
|
let userIP = req.socket.remoteAddress ?? '';
|
||||||
let deviceInfo = req.headers['user-agent'] ?? '';
|
let deviceInfo = req.headers['user-agent'] ?? '';
|
||||||
|
|
||||||
if (username === '' || email === '' || firstName === '' || lastName === '' || password === '') {
|
if (username === '' || email === '' || firstName === '' || lastName === '' || password === '') {
|
||||||
res.status(400).send({
|
res.status(400).send({
|
||||||
'status': 'WRONG_PARAMS',
|
'status': 'WRONG_PARAMS',
|
||||||
'message': 'Missing or wrong parameters'
|
'message': 'Missing or wrong parameters'
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for invalid username / email
|
// Check for invalid username / email
|
||||||
const status = await UserService.checkUsernameAndEmail(useDev, username, email);
|
const status = await UserService.checkUsernameAndEmail(useDev, username, email);
|
||||||
if (status.hasProblems) {
|
if (status.hasProblems) {
|
||||||
// Username and/or email are duplicates, return error
|
// Username and/or email are duplicates, return error
|
||||||
res.status(400).send({
|
res.status(400).send({
|
||||||
'message': status.messages[0],
|
'message': status.messages[0],
|
||||||
'status': status.status[0],
|
'status': status.status[0],
|
||||||
'additionalMessages': status.messages.slice(1),
|
'additionalMessages': status.messages.slice(1),
|
||||||
'additionalStatus': status.status.slice(1)
|
'additionalStatus': status.status.slice(1)
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create user
|
// Create user
|
||||||
let session = await UserService.registerUser(useDev, username, email, firstName, lastName, password, userIP, deviceInfo);
|
let session = await UserService.registerUser(useDev, username, email, firstName, lastName, password, userIP, deviceInfo);
|
||||||
|
|
||||||
res.status(201).send(session);
|
res.status(201).send(session);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
let errorGuid = Guid.create().toString();
|
let errorGuid = Guid.create().toString();
|
||||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
'status': 'PROCESSING_ERROR',
|
'status': 'PROCESSING_ERROR',
|
||||||
'message': 'Internal Server Error. Try again later.',
|
'message': 'Internal Server Error. Try again later.',
|
||||||
'reference': errorGuid
|
'reference': errorGuid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -13,38 +13,38 @@ import {Guid} from 'guid-typescript';
|
||||||
export const sessionRouter = express.Router();
|
export const sessionRouter = express.Router();
|
||||||
|
|
||||||
sessionRouter.get('/:isDevCall', async (req: Request, res: Response) => {
|
sessionRouter.get('/:isDevCall', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
let userId = (req.query.userId ?? '').toString();
|
let userId = (req.query.userId ?? '').toString();
|
||||||
let sessionId = (req.query.sessionId ?? '').toString();
|
let sessionId = (req.query.sessionId ?? '').toString();
|
||||||
let sessionKey = (req.query.sessionKey ?? '').toString();
|
let sessionKey = (req.query.sessionKey ?? '').toString();
|
||||||
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
||||||
|
|
||||||
if (userId === '' || sessionId === '' || sessionKey === '') {
|
if (userId === '' || sessionId === '' || sessionKey === '') {
|
||||||
res.status(400).send({
|
res.status(400).send({
|
||||||
'status': 'WRONG_PARAMS',
|
'status': 'WRONG_PARAMS',
|
||||||
'message': 'Missing or wrong parameters'
|
'message': 'Missing or wrong parameters'
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!await UserService.checkSession(useDev, userId, sessionId, sessionKey)) {
|
if (!await UserService.checkSession(useDev, userId, sessionId, sessionKey)) {
|
||||||
res.status(403).send({
|
res.status(403).send({
|
||||||
'status': 'INVALID_SESSION',
|
'status': 'INVALID_SESSION',
|
||||||
'message': 'The user or session could not be found or the session is invalid'
|
'message': 'The user or session could not be found or the session is invalid'
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let data = await SessionService.getSessionData(useDev, userId);
|
let data = await SessionService.getSessionData(useDev, userId);
|
||||||
|
|
||||||
res.status(200).send(data);
|
res.status(200).send(data);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
let errorGuid = Guid.create().toString();
|
let errorGuid = Guid.create().toString();
|
||||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
'status': 'PROCESSING_ERROR',
|
'status': 'PROCESSING_ERROR',
|
||||||
'message': 'Internal Server Error. Try again later.',
|
'message': 'Internal Server Error. Try again later.',
|
||||||
'reference': errorGuid
|
'reference': errorGuid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -12,38 +12,38 @@ import {Guid} from 'guid-typescript';
|
||||||
export const userRouter = express.Router();
|
export const userRouter = express.Router();
|
||||||
|
|
||||||
userRouter.get('/:isDevCall', async (req: Request, res: Response) => {
|
userRouter.get('/:isDevCall', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
let userId = (req.query.userId ?? '').toString();
|
let userId = (req.query.userId ?? '').toString();
|
||||||
let sessionId = (req.query.sessionId ?? '').toString();
|
let sessionId = (req.query.sessionId ?? '').toString();
|
||||||
let sessionKey = (req.query.sessionKey ?? '').toString();
|
let sessionKey = (req.query.sessionKey ?? '').toString();
|
||||||
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
let useDev: boolean = (req.params.isDevCall ?? '') === 'dev'; // TBD
|
||||||
|
|
||||||
if (userId === '' || sessionId === '' || sessionKey === '') {
|
if (userId === '' || sessionId === '' || sessionKey === '') {
|
||||||
res.status(400).send({
|
res.status(400).send({
|
||||||
'status': 'WRONG_PARAMS',
|
'status': 'WRONG_PARAMS',
|
||||||
'message': 'Missing or wrong parameters'
|
'message': 'Missing or wrong parameters'
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!await UserService.checkSession(useDev, userId, sessionId, sessionKey)) {
|
if (!await UserService.checkSession(useDev, userId, sessionId, sessionKey)) {
|
||||||
res.status(403).send({
|
res.status(403).send({
|
||||||
'status': 'INVALID_SESSION',
|
'status': 'INVALID_SESSION',
|
||||||
'message': 'The user or session could not be found or the session is invalid'
|
'message': 'The user or session could not be found or the session is invalid'
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let data = await UserService.getUserData(useDev, userId);
|
let data = await UserService.getUserData(useDev, userId);
|
||||||
|
|
||||||
res.status(200).send(data);
|
res.status(200).send(data);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
let errorGuid = Guid.create().toString();
|
let errorGuid = Guid.create().toString();
|
||||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
'status': 'PROCESSING_ERROR',
|
'status': 'PROCESSING_ERROR',
|
||||||
'message': 'Internal Server Error. Try again later.',
|
'message': 'Internal Server Error. Try again later.',
|
||||||
'reference': errorGuid
|
'reference': errorGuid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -65,34 +65,34 @@ export const raPlaMiddlewareRouter = express.Router();
|
||||||
* example: 2
|
* example: 2
|
||||||
*/
|
*/
|
||||||
raPlaMiddlewareRouter.get('/', async (req: Request, res: Response) => {
|
raPlaMiddlewareRouter.get('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
let user = (req.query.user ?? '').toString();
|
let user = (req.query.user ?? '').toString();
|
||||||
let file = (req.query.file ?? '').toString();
|
let file = (req.query.file ?? '').toString();
|
||||||
let blockers = (req.query.blockers ?? '').toString() === '1';
|
let blockers = (req.query.blockers ?? '').toString() === '1';
|
||||||
let wahl = (req.query.wahl ?? '').toString();
|
let wahl = (req.query.wahl ?? '').toString();
|
||||||
let pflicht = (req.query.pflicht ?? '').toString();
|
let pflicht = (req.query.pflicht ?? '').toString();
|
||||||
|
|
||||||
const allowedCharsRegex: RegExp = /^[a-zA-Z0-9]+$/;
|
const allowedCharsRegex: RegExp = /^[a-zA-Z0-9]+$/;
|
||||||
|
|
||||||
if (user === '' || file === '') {
|
if (user === '' || file === '') {
|
||||||
res.status(400).send('Please at least provide user and file for RaPla!');
|
res.status(400).send('Please at least provide user and file for RaPla!');
|
||||||
return;
|
return;
|
||||||
} else if (!allowedCharsRegex.test(user) || !allowedCharsRegex.test(file)) {
|
} else if (!allowedCharsRegex.test(user) || !allowedCharsRegex.test(file)) {
|
||||||
res.status(400).send('Please provide a valid user and file!');
|
res.status(400).send('Please provide a valid user and file!');
|
||||||
return;
|
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.set({'Content-Disposition': 'attachment; filename=' + file + '.ics'});
|
||||||
res.status(200).send(resultingFile);
|
res.status(200).send(resultingFile);
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
let errorGuid = Guid.create().toString();
|
let errorGuid = Guid.create().toString();
|
||||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
'status': 'PROCESSING_ERROR',
|
'status': 'PROCESSING_ERROR',
|
||||||
'message': 'Internal Server Error. Try again later.',
|
'message': 'Internal Server Error. Try again later.',
|
||||||
'reference': errorGuid
|
'reference': errorGuid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,15 +14,15 @@ export const highlightMarkerRouter = express.Router();
|
||||||
highlightMarkerRouter.use('/addHighlight', addHighlightRouter);
|
highlightMarkerRouter.use('/addHighlight', addHighlightRouter);
|
||||||
|
|
||||||
highlightMarkerRouter.get('/', async (req: Request, res: Response) => {
|
highlightMarkerRouter.get('/', async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
res.status(200).send('Pluto Development Twitch Highlight Marker API Endpoint');
|
res.status(200).send('Pluto Development Twitch Highlight Marker API Endpoint');
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
let errorGuid = Guid.create().toString();
|
let errorGuid = Guid.create().toString();
|
||||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
'status': 'PROCESSING_ERROR',
|
'status': 'PROCESSING_ERROR',
|
||||||
'message': 'Internal Server Error. Try again later.',
|
'message': 'Internal Server Error. Try again later.',
|
||||||
'reference': errorGuid
|
'reference': errorGuid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -12,46 +12,46 @@ import {Guid} from 'guid-typescript';
|
||||||
export const addHighlightRouter = express.Router();
|
export const addHighlightRouter = express.Router();
|
||||||
|
|
||||||
addHighlightRouter.get('/', (req: Request, res: Response) => {
|
addHighlightRouter.get('/', (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
res.status(200).send('GET endpoint not defined.');
|
res.status(200).send('GET endpoint not defined.');
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
let errorGuid = Guid.create().toString();
|
let errorGuid = Guid.create().toString();
|
||||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
'status': 'PROCESSING_ERROR',
|
'status': 'PROCESSING_ERROR',
|
||||||
'message': 'Internal Server Error. Try again later.',
|
'message': 'Internal Server Error. Try again later.',
|
||||||
'reference': errorGuid
|
'reference': errorGuid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
addHighlightRouter.post('/', (req: Request, res: Response) => {
|
addHighlightRouter.post('/', (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
// Check input params
|
// Check input params
|
||||||
const body = req.body;
|
const body = req.body;
|
||||||
|
|
||||||
if (body.access_key !== process.env.TWITCH_HIGHLIGHTS_ACCESS_KEY) {
|
if (body.access_key !== process.env.TWITCH_HIGHLIGHTS_ACCESS_KEY) {
|
||||||
// Unauthorized, return error
|
// Unauthorized, return error
|
||||||
res.type('application/json');
|
res.type('application/json');
|
||||||
res.status(403).send({'status': 'error', 'description': 'Unauthorized.'});
|
res.status(403).send({'status': 'error', 'description': 'Unauthorized.'});
|
||||||
} else if (!body.streamer || !body.stream_id || !body.stream_game || !body.timestamp || !body.description || !body.username) {
|
} else if (!body.streamer || !body.stream_id || !body.stream_game || !body.timestamp || !body.description || !body.username) {
|
||||||
// Missing params, return error
|
// Missing params, return error
|
||||||
res.type('application/json');
|
res.type('application/json');
|
||||||
res.status(400).send({'status': 'error', 'description': 'Missing parameters.'});
|
res.status(400).send({'status': 'error', 'description': 'Missing parameters.'});
|
||||||
} else {
|
} else {
|
||||||
// Everything fine, return success
|
// Everything fine, return success
|
||||||
AddHighlightService.createHighlightEntry(body);
|
AddHighlightService.createHighlightEntry(body);
|
||||||
|
|
||||||
res.type('application/json');
|
res.type('application/json');
|
||||||
res.status(200).send({'status': 'success', 'description': ''});
|
res.status(200).send({'status': 'success', 'description': ''});
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e) {
|
||||||
let errorGuid = Guid.create().toString();
|
let errorGuid = Guid.create().toString();
|
||||||
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
|
||||||
res.status(500).send({
|
res.status(500).send({
|
||||||
'status': 'PROCESSING_ERROR',
|
'status': 'PROCESSING_ERROR',
|
||||||
'message': 'Internal Server Error. Try again later.',
|
'message': 'Internal Server Error. Try again later.',
|
||||||
'reference': errorGuid
|
'reference': errorGuid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
test('Test template', async () => {
|
|
||||||
expect(true).toBe(true);
|
|
||||||
});
|
|
Loading…
Reference in New Issue
Block a user