mirror of
https://github.com/Mueller-Patrick/Betterzon.git
synced 2024-12-23 12:15:11 +00:00
Compare commits
No commits in common. "5c7e79fd55ca8f3ce1f39b23a147a4ed1a70deb8" and "0f19bd77cda1fa89df618b02aa2231ff01930d6e" have entirely different histories.
5c7e79fd55
...
0f19bd77cd
4984
Backend/package-lock.json
generated
4984
Backend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
@ -11,9 +11,7 @@
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/cookie-parser": "^1.4.2",
|
|
||||||
"bcrypt": "^5.0.1",
|
"bcrypt": "^5.0.1",
|
||||||
"cookie-parser": "^1.4.5",
|
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.2.0",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
|
|
|
@ -14,9 +14,6 @@ import {vendorsRouter} from './models/vendors/vendors.router';
|
||||||
import {errorHandler} from './middleware/error.middleware';
|
import {errorHandler} from './middleware/error.middleware';
|
||||||
import {notFoundHandler} from './middleware/notFound.middleware';
|
import {notFoundHandler} from './middleware/notFound.middleware';
|
||||||
import {usersRouter} from './models/users/users.router';
|
import {usersRouter} from './models/users/users.router';
|
||||||
import {pricealarmsRouter} from './models/pricealarms/pricealarms.router';
|
|
||||||
|
|
||||||
const cookieParser = require('cookie-parser');
|
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
|
@ -41,14 +38,12 @@ const app = express();
|
||||||
app.use(helmet());
|
app.use(helmet());
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.use(cookieParser());
|
|
||||||
app.use('/products', productsRouter);
|
app.use('/products', productsRouter);
|
||||||
app.use('/categories', categoriesRouter);
|
app.use('/categories', categoriesRouter);
|
||||||
app.use('/manufacturers', manufacturersRouter);
|
app.use('/manufacturers', manufacturersRouter);
|
||||||
app.use('/prices', pricesRouter);
|
app.use('/prices', pricesRouter);
|
||||||
app.use('/users', usersRouter);
|
app.use('/users', usersRouter);
|
||||||
app.use('/vendors', vendorsRouter);
|
app.use('/vendors', vendorsRouter);
|
||||||
app.use('/pricealarms', pricealarmsRouter);
|
|
||||||
|
|
||||||
app.use(errorHandler);
|
app.use(errorHandler);
|
||||||
app.use(notFoundHandler);
|
app.use(notFoundHandler);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import HttpException from '../common/http-exception';
|
import HttpException from "../common/http-exception";
|
||||||
import {Request, Response, NextFunction} from 'express';
|
import { Request, Response, NextFunction } from "express";
|
||||||
|
|
||||||
export const errorHandler = (
|
export const errorHandler = (
|
||||||
error: HttpException,
|
error: HttpException,
|
||||||
|
@ -9,7 +9,7 @@ export const errorHandler = (
|
||||||
) => {
|
) => {
|
||||||
const status = error.statusCode || 500;
|
const status = error.statusCode || 500;
|
||||||
const message =
|
const message =
|
||||||
error.message || 'It\'s not you. It\'s us. We are having some problems.';
|
error.message || "It's not you. It's us. We are having some problems.";
|
||||||
|
|
||||||
response.status(status).send(message);
|
response.status(status).send(message);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {Request, Response, NextFunction} from 'express';
|
import { Request, Response, NextFunction } from "express";
|
||||||
|
|
||||||
export const notFoundHandler = (
|
export const notFoundHandler = (
|
||||||
request: Request,
|
request: Request,
|
||||||
|
@ -6,7 +6,7 @@ export const notFoundHandler = (
|
||||||
next: NextFunction
|
next: NextFunction
|
||||||
) => {
|
) => {
|
||||||
|
|
||||||
const message = 'Resource not found';
|
const message = "Resource not found";
|
||||||
|
|
||||||
response.status(404).send(message);
|
response.status(404).send(message);
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,7 +27,7 @@ categoriesRouter.get('/', async (req: Request, res: Response) => {
|
||||||
res.status(200).send(categories);
|
res.status(200).send(categories);
|
||||||
} catch (e) {
|
} 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."}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ categoriesRouter.get('/:id', async (req: Request, res: Response) => {
|
||||||
res.status(200).send(category);
|
res.status(200).send(category);
|
||||||
} catch (e) {
|
} 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."}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -65,6 +65,6 @@ categoriesRouter.get('/search/:term', async (req: Request, res: Response) => {
|
||||||
res.status(200).send(categories);
|
res.status(200).send(categories);
|
||||||
} catch (e) {
|
} 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."}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -27,7 +27,7 @@ manufacturersRouter.get('/', async (req: Request, res: Response) => {
|
||||||
res.status(200).send(manufacturers);
|
res.status(200).send(manufacturers);
|
||||||
} catch (e) {
|
} 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."}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ manufacturersRouter.get('/:id', async (req: Request, res: Response) => {
|
||||||
res.status(200).send(manufacturer);
|
res.status(200).send(manufacturer);
|
||||||
} catch (e) {
|
} 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."}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -65,6 +65,6 @@ manufacturersRouter.get('/search/:term', async (req: Request, res: Response) =>
|
||||||
res.status(200).send(manufacturer);
|
res.status(200).send(manufacturer);
|
||||||
} catch (e) {
|
} 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."}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
export interface PriceAlarm {
|
|
||||||
alarm_id: number;
|
|
||||||
user_id: number;
|
|
||||||
product_id: number;
|
|
||||||
defined_price: number;
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
import {PriceAlarm} from './pricealarm.interface';
|
|
||||||
|
|
||||||
export interface PriceAlarms {
|
|
||||||
[key: number]: PriceAlarm;
|
|
||||||
}
|
|
|
@ -1,102 +0,0 @@
|
||||||
/**
|
|
||||||
* Required External Modules and Interfaces
|
|
||||||
*/
|
|
||||||
|
|
||||||
import express, {Request, Response} from 'express';
|
|
||||||
import * as PriceAlarmsService from './pricealarms.service';
|
|
||||||
import {PriceAlarm} from './pricealarm.interface';
|
|
||||||
import {PriceAlarms} from './pricealarms.interface';
|
|
||||||
import * as UserService from '../users/users.service';
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Router Definition
|
|
||||||
*/
|
|
||||||
export const pricealarmsRouter = express.Router();
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Controller Definitions
|
|
||||||
*/
|
|
||||||
|
|
||||||
//GET pricealarms/
|
|
||||||
pricealarmsRouter.get('/', async (req: Request, res: Response) => {
|
|
||||||
try {
|
|
||||||
// Authenticate user
|
|
||||||
const user_ip = req.connection.remoteAddress ?? '';
|
|
||||||
const user = await UserService.checkSessionWithCookie(req.cookies.betterauth, user_ip);
|
|
||||||
|
|
||||||
const priceAlarms = await PriceAlarmsService.getPriceAlarms(user.user_id);
|
|
||||||
|
|
||||||
res.status(200).send(priceAlarms);
|
|
||||||
} catch (e) {
|
|
||||||
console.log('Error handling a request: ' + e.message);
|
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// POST pricealarms/create
|
|
||||||
pricealarmsRouter.post('/create', async (req: Request, res: Response) => {
|
|
||||||
try {
|
|
||||||
// Authenticate user
|
|
||||||
const user_ip = req.connection.remoteAddress ?? '';
|
|
||||||
const user = await UserService.checkSessionWithCookie(req.cookies.betterauth, user_ip);
|
|
||||||
|
|
||||||
// Get info for price alarm creation
|
|
||||||
const product_id = req.body.product_id;
|
|
||||||
const defined_price = req.body.defined_price;
|
|
||||||
|
|
||||||
if (!product_id || !defined_price) {
|
|
||||||
// Missing
|
|
||||||
res.status(400).send(JSON.stringify({message: 'Missing parameters'}));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create price alarm
|
|
||||||
const success = await PriceAlarmsService.createPriceAlarm(user.user_id, product_id, defined_price);
|
|
||||||
|
|
||||||
if (success) {
|
|
||||||
res.status(201).send(JSON.stringify({success: true}));
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
res.status(500).send(JSON.stringify({success: false}));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.log('Error handling a request: ' + e.message);
|
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// PUT pricealarms/update
|
|
||||||
pricealarmsRouter.put('/update', async (req: Request, res: Response) => {
|
|
||||||
try {
|
|
||||||
// Authenticate user
|
|
||||||
const user_ip = req.connection.remoteAddress ?? '';
|
|
||||||
const user = await UserService.checkSessionWithCookie(req.cookies.betterauth, user_ip);
|
|
||||||
|
|
||||||
// Get info for price alarm creation
|
|
||||||
const alarm_id = req.body.alarm_id;
|
|
||||||
const defined_price = req.body.defined_price;
|
|
||||||
|
|
||||||
if (!alarm_id || !defined_price) {
|
|
||||||
// Missing
|
|
||||||
res.status(400).send(JSON.stringify({message: 'Missing parameters'}));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create price alarm
|
|
||||||
const success = await PriceAlarmsService.updatePriceAlarm(alarm_id, user.user_id, defined_price);
|
|
||||||
|
|
||||||
if (success) {
|
|
||||||
res.status(201).send(JSON.stringify({success: true}));
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
res.status(500).send(JSON.stringify({success: false}));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.log('Error handling a request: ' + e.message);
|
|
||||||
res.status(500).send(JSON.stringify({'message': 'Internal Server Error. Try again later.'}));
|
|
||||||
}
|
|
||||||
});
|
|
|
@ -1,106 +0,0 @@
|
||||||
import * as dotenv from 'dotenv';
|
|
||||||
|
|
||||||
dotenv.config();
|
|
||||||
|
|
||||||
const mariadb = require('mariadb');
|
|
||||||
const pool = mariadb.createPool({
|
|
||||||
host: process.env.DB_HOST,
|
|
||||||
user: process.env.DB_USER,
|
|
||||||
password: process.env.DB_PASSWORD,
|
|
||||||
database: process.env.DB_DATABASE,
|
|
||||||
connectionLimit: 5
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Data Model Interfaces
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {PriceAlarm} from './pricealarm.interface';
|
|
||||||
import {PriceAlarms} from './pricealarms.interface';
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Service Methods
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a price alarm for the given user for the product with the defined price
|
|
||||||
* @param user_id The id of the user to create the price alarm for
|
|
||||||
* @param product_id The id of the product to create the price alarm for
|
|
||||||
* @param defined_price The defined price for the price alarm
|
|
||||||
*/
|
|
||||||
export const createPriceAlarm = async (user_id: number, product_id: number, defined_price: number): Promise<Boolean> => {
|
|
||||||
let conn;
|
|
||||||
try {
|
|
||||||
conn = await pool.getConnection();
|
|
||||||
const res = await conn.query('INSERT INTO price_alarms (user_id, product_id, defined_price) VALUES (?, ?, ?)', [user_id, product_id, defined_price]);
|
|
||||||
|
|
||||||
if (res.affectedRows === 1) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
throw err;
|
|
||||||
} finally {
|
|
||||||
if (conn) {
|
|
||||||
conn.end();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetches and returns all price alarms for the given user
|
|
||||||
* @param user_id
|
|
||||||
*/
|
|
||||||
export const getPriceAlarms = async (user_id: number): Promise<PriceAlarms> => {
|
|
||||||
let conn;
|
|
||||||
let priceAlarms = [];
|
|
||||||
try {
|
|
||||||
conn = await pool.getConnection();
|
|
||||||
const rows = await conn.query('SELECT alarm_id, user_id, product_id, defined_price FROM price_alarms WHERE user_id = ?', user_id);
|
|
||||||
for (let row in rows) {
|
|
||||||
if (row !== 'meta') {
|
|
||||||
priceAlarms.push(rows[row]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return priceAlarms;
|
|
||||||
} catch (err) {
|
|
||||||
throw err;
|
|
||||||
} finally {
|
|
||||||
if (conn) {
|
|
||||||
conn.end();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the given price alarm with the given fields
|
|
||||||
* @param alarm_id The id of the price alarm to update
|
|
||||||
* @param user_id The id of the user that wants to update the price alarm
|
|
||||||
* @param defined_price The defined price for the price alarm
|
|
||||||
*/
|
|
||||||
export const updatePriceAlarm = async (alarm_id: number, user_id: number, defined_price: number): Promise<Boolean> => {
|
|
||||||
let conn;
|
|
||||||
try {
|
|
||||||
conn = await pool.getConnection();
|
|
||||||
const res = await conn.query('UPDATE price_alarms SET defined_price = ? WHERE alarm_id = ? AND user_id = ?', [defined_price, alarm_id, user_id]);
|
|
||||||
|
|
||||||
if (res.affectedRows === 1) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
throw err;
|
|
||||||
} finally {
|
|
||||||
if (conn) {
|
|
||||||
conn.end();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
};
|
|
|
@ -40,7 +40,7 @@ pricesRouter.get('/', async (req: Request, res: Response) => {
|
||||||
res.status(200).send(prices);
|
res.status(200).send(prices);
|
||||||
} catch (e) {
|
} 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."}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ pricesRouter.get('/:id', async (req: Request, res: Response) => {
|
||||||
res.status(200).send(price);
|
res.status(200).send(price);
|
||||||
} catch (e) {
|
} 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."}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ pricesRouter.get('/bestDeals/:amount', async (req: Request, res: Response) => {
|
||||||
res.status(200).send(prices);
|
res.status(200).send(prices);
|
||||||
} catch (e) {
|
} 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."}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -97,6 +97,6 @@ pricesRouter.get('/byProduct/list/:ids', async (req: Request, res: Response) =>
|
||||||
res.status(200).send(prices);
|
res.status(200).send(prices);
|
||||||
} catch (e) {
|
} 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."}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -27,7 +27,7 @@ productsRouter.get('/', async (req: Request, res: Response) => {
|
||||||
res.status(200).send(products);
|
res.status(200).send(products);
|
||||||
} catch (e) {
|
} 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."}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ productsRouter.get('/:id', async (req: Request, res: Response) => {
|
||||||
res.status(200).send(product);
|
res.status(200).send(product);
|
||||||
} catch (e) {
|
} 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."}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ productsRouter.get('/search/:term', async (req: Request, res: Response) => {
|
||||||
res.status(200).send(products);
|
res.status(200).send(products);
|
||||||
} catch (e) {
|
} 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."}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -84,6 +84,6 @@ productsRouter.get('/list/:ids', async (req: Request, res: Response) => {
|
||||||
res.status(200).send(products);
|
res.status(200).send(products);
|
||||||
} catch (e) {
|
} 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."}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -47,13 +47,10 @@ usersRouter.post('/register', async (req: Request, res: Response) => {
|
||||||
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.cookie('betterauth', JSON.stringify({
|
res.status(201).send(session);
|
||||||
id: session.session_id,
|
|
||||||
key: session.session_key
|
|
||||||
}), {expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 30)}).sendStatus(201);
|
|
||||||
} catch (e) {
|
} 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."}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -73,34 +70,39 @@ usersRouter.post('/login', async (req: Request, res: Response) => {
|
||||||
// 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.cookie('betterauth', JSON.stringify({
|
res.status(201).send(session);
|
||||||
id: session.session_id,
|
|
||||||
key: session.session_key
|
|
||||||
}), {expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 30)}).sendStatus(200);
|
|
||||||
} catch (e) {
|
} 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 sessionId: string = req.body.sessionId;
|
||||||
|
const sessionKey: string = req.body.sessionKey;
|
||||||
const ip: string = req.connection.remoteAddress ?? '';
|
const ip: string = req.connection.remoteAddress ?? '';
|
||||||
|
|
||||||
// Update the user entry and create a session
|
if (!sessionId || !sessionKey) {
|
||||||
const user: User = await UserService.checkSessionWithCookie(req.cookies.betterauth, ip);
|
// Missing
|
||||||
|
res.status(400).send(JSON.stringify({message: 'Missing parameters'}));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!user.user_id) {
|
// Update the user entry and create a session
|
||||||
|
const user: User = await UserService.checkSession(sessionId, sessionKey, ip);
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,6 +110,6 @@ usersRouter.post('/checkSessionValid', async (req: Request, res: Response) => {
|
||||||
res.status(201).send(user);
|
res.status(201).send(user);
|
||||||
} catch (e) {
|
} 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."}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -68,7 +68,7 @@ export const createUser = async (username: string, password: string, email: stri
|
||||||
return {
|
return {
|
||||||
session_id: sessionId,
|
session_id: sessionId,
|
||||||
session_key: sessionKey,
|
session_key: sessionKey,
|
||||||
session_key_hash: 'HIDDEN',
|
session_key_hash: '',
|
||||||
last_IP: ip
|
last_IP: ip
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ export const login = async (username: string, password: string, ip: string): Pro
|
||||||
return {
|
return {
|
||||||
session_id: sessionId,
|
session_id: sessionId,
|
||||||
session_key: sessionKey,
|
session_key: sessionKey,
|
||||||
session_key_hash: 'HIDDEN',
|
session_key_hash: '',
|
||||||
last_IP: ip
|
last_IP: ip
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ export const checkSession = async (sessionId: string, sessionKey: string, ip: st
|
||||||
// Key is valid, continue
|
// Key is valid, continue
|
||||||
|
|
||||||
// Check if the session is still valid
|
// Check if the session is still valid
|
||||||
if (validUntil <= new Date()) {
|
if(validUntil <= new Date()) {
|
||||||
// Session expired, return invalid
|
// Session expired, return invalid
|
||||||
return {} as User;
|
return {} as User;
|
||||||
}
|
}
|
||||||
|
@ -193,7 +193,7 @@ export const checkSession = async (sessionId: string, sessionKey: string, ip: st
|
||||||
await conn.commit();
|
await conn.commit();
|
||||||
|
|
||||||
// Get the other required user information and update the user
|
// Get the other required user information and update the user
|
||||||
const userQuery = 'SELECT user_id, username, email, registration_date, last_login_date FROM users WHERE user_id = ?';
|
const userQuery = "SELECT user_id, username, email, registration_date, last_login_date FROM users WHERE user_id = ?";
|
||||||
const userRows = await conn.query(userQuery, userId);
|
const userRows = await conn.query(userQuery, userId);
|
||||||
let username = '';
|
let username = '';
|
||||||
let email = '';
|
let email = '';
|
||||||
|
@ -213,7 +213,7 @@ export const checkSession = async (sessionId: string, sessionKey: string, ip: st
|
||||||
user_id: userId,
|
user_id: userId,
|
||||||
username: username,
|
username: username,
|
||||||
email: email,
|
email: email,
|
||||||
password_hash: 'HIDDEN',
|
password_hash: '',
|
||||||
registration_date: registrationDate,
|
registration_date: registrationDate,
|
||||||
last_login_date: lastLoginDate
|
last_login_date: lastLoginDate
|
||||||
};
|
};
|
||||||
|
@ -229,20 +229,6 @@ export const checkSession = async (sessionId: string, sessionKey: string, ip: st
|
||||||
return {} as User;
|
return {} as User;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls the checkSession method after extracting the required information from the authentication cookie
|
|
||||||
* @param cookie The betterauth cookie
|
|
||||||
* @param ip The users IP address
|
|
||||||
*/
|
|
||||||
export const checkSessionWithCookie = async (cookie: any, ip: string): Promise<User> => {
|
|
||||||
const parsedCookie = JSON.parse(cookie);
|
|
||||||
const session_id = parsedCookie.id;
|
|
||||||
const session_key = parsedCookie.key;
|
|
||||||
|
|
||||||
|
|
||||||
return checkSession(session_id, session_key, '');
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used in the checkUsernameAndEmail method as return value
|
* Used in the checkUsernameAndEmail method as return value
|
||||||
*/
|
*/
|
||||||
|
|
6
Backend/src/models/vendors/vendors.router.ts
vendored
6
Backend/src/models/vendors/vendors.router.ts
vendored
|
@ -27,7 +27,7 @@ vendorsRouter.get('/', async (req: Request, res: Response) => {
|
||||||
res.status(200).send(vendors);
|
res.status(200).send(vendors);
|
||||||
} catch (e) {
|
} 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."}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ vendorsRouter.get('/:id', async (req: Request, res: Response) => {
|
||||||
res.status(200).send(vendor);
|
res.status(200).send(vendor);
|
||||||
} catch (e) {
|
} 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."}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -65,6 +65,6 @@ vendorsRouter.get('/search/:term', async (req: Request, res: Response) => {
|
||||||
res.status(200).send(vendors);
|
res.status(200).send(vendors);
|
||||||
} catch (e) {
|
} 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."}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,32 +1,32 @@
|
||||||
const webpack = require('webpack');
|
const webpack = require("webpack");
|
||||||
const path = require('path');
|
const path = require("path");
|
||||||
const nodeExternals = require('webpack-node-externals');
|
const nodeExternals = require("webpack-node-externals");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
entry: ['webpack/hot/poll?100', './src/index.ts'],
|
entry: ["webpack/hot/poll?100", "./src/index.ts"],
|
||||||
watch: false,
|
watch: false,
|
||||||
target: 'node',
|
target: "node",
|
||||||
externals: [
|
externals: [
|
||||||
nodeExternals({
|
nodeExternals({
|
||||||
whitelist: ['webpack/hot/poll?100']
|
whitelist: ["webpack/hot/poll?100"]
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
{
|
{
|
||||||
test: /.tsx?$/,
|
test: /.tsx?$/,
|
||||||
use: 'ts-loader',
|
use: "ts-loader",
|
||||||
exclude: /node_modules/
|
exclude: /node_modules/
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
mode: 'development',
|
mode: "development",
|
||||||
resolve: {
|
resolve: {
|
||||||
extensions: ['.tsx', '.ts', '.js']
|
extensions: [".tsx", ".ts", ".js"]
|
||||||
},
|
},
|
||||||
plugins: [new webpack.HotModuleReplacementPlugin()],
|
plugins: [new webpack.HotModuleReplacementPlugin()],
|
||||||
output: {
|
output: {
|
||||||
path: path.join(__dirname, 'dist'),
|
path: path.join(__dirname, "dist"),
|
||||||
filename: 'index.js'
|
filename: "index.js"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,24 +10,17 @@
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/resource" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/test/resource" type="java-resource" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="openjdk-16" jdkType="JavaSDK" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: io.cucumber:cucumber-java:2.3.1" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: io.cucumber:cucumber-core:2.3.1" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: info.cukes:cucumber-html:0.2.6" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: io.cucumber:cucumber-jvm-deps:1.0.6" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: io.cucumber:gherkin:5.0.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: io.cucumber:tag-expressions:1.1.1" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: io.cucumber:cucumber-junit:2.3.1" level="project" />
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
|
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
|
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
|
||||||
<orderEntry type="library" name="Maven: io.cucumber:cucumber-java:6.10.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.cucumber:cucumber-core:6.10.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.cucumber:cucumber-gherkin:6.10.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.cucumber:cucumber-gherkin-messages:6.10.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.cucumber:messages:15.0.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.cucumber:tag-expressions:3.0.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.cucumber:cucumber-expressions:10.3.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.cucumber:datatable:3.5.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.cucumber:cucumber-plugin:6.10.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.cucumber:docstring:6.10.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.cucumber:html-formatter:13.0.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.cucumber:create-meta:4.0.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apiguardian:apiguardian-api:1.1.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: io.cucumber:cucumber-junit:6.10.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.maven.plugins:maven-compiler-plugin:3.8.1" level="project" />
|
<orderEntry type="library" name="Maven: org.apache.maven.plugins:maven-compiler-plugin:3.8.1" level="project" />
|
||||||
<orderEntry type="library" name="Maven: org.apache.maven:maven-plugin-api:3.0" level="project" />
|
<orderEntry type="library" name="Maven: org.apache.maven:maven-plugin-api:3.0" level="project" />
|
||||||
<orderEntry type="library" name="Maven: org.apache.maven:maven-model:3.0" level="project" />
|
<orderEntry type="library" name="Maven: org.apache.maven:maven-model:3.0" level="project" />
|
||||||
|
@ -60,25 +53,5 @@
|
||||||
<orderEntry type="library" name="Maven: org.codehaus.plexus:plexus-compiler-api:2.8.4" level="project" />
|
<orderEntry type="library" name="Maven: org.codehaus.plexus:plexus-compiler-api:2.8.4" level="project" />
|
||||||
<orderEntry type="library" name="Maven: org.codehaus.plexus:plexus-compiler-manager:2.8.4" level="project" />
|
<orderEntry type="library" name="Maven: org.codehaus.plexus:plexus-compiler-manager:2.8.4" level="project" />
|
||||||
<orderEntry type="library" scope="RUNTIME" name="Maven: org.codehaus.plexus:plexus-compiler-javac:2.8.4" level="project" />
|
<orderEntry type="library" scope="RUNTIME" name="Maven: org.codehaus.plexus:plexus-compiler-javac:2.8.4" level="project" />
|
||||||
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-java:3.141.59" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-api:3.141.59" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-chrome-driver:3.141.59" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-edge-driver:3.141.59" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-firefox-driver:3.141.59" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-ie-driver:3.141.59" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-opera-driver:3.141.59" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-remote-driver:3.141.59" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-safari-driver:3.141.59" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-support:3.141.59" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: net.bytebuddy:byte-buddy:1.8.15" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-exec:1.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.google.guava:guava:25.0-jre" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.checkerframework:checker-compat-qual:2.0.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.1.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.codehaus.mojo:animal-sniffer-annotations:1.14" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:3.11.0" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.squareup.okio:okio:1.14.0" level="project" />
|
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
|
@ -4,7 +4,7 @@
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>xyz.betterzon</groupId>
|
<groupId>de.taskhub</groupId>
|
||||||
<artifactId>CucumberTests</artifactId>
|
<artifactId>CucumberTests</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -13,30 +13,21 @@
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>io.cucumber</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>cucumber-java</artifactId>
|
||||||
<version>4.12</version>
|
<version>2.3.1</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>io.cucumber</groupId>
|
|
||||||
<artifactId>cucumber-java</artifactId>
|
|
||||||
<version>6.10.3</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.cucumber</groupId>
|
<groupId>io.cucumber</groupId>
|
||||||
<artifactId>cucumber-junit</artifactId>
|
<artifactId>cucumber-junit</artifactId>
|
||||||
<version>6.10.3</version>
|
<version>2.3.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.8.1</version>
|
<version>3.8.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.seleniumhq.selenium</groupId>
|
|
||||||
<artifactId>selenium-java</artifactId>
|
|
||||||
<version>3.141.59</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
|
@ -1,10 +1,6 @@
|
||||||
import io.cucumber.junit.Cucumber;
|
import cucumber.api.CucumberOptions;
|
||||||
import io.cucumber.junit.CucumberOptions;
|
import cucumber.api.junit.Cucumber;
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
|
||||||
import stepdefs.Preconditions;
|
|
||||||
|
|
||||||
@RunWith(Cucumber.class)
|
@RunWith(Cucumber.class)
|
||||||
@CucumberOptions(
|
@CucumberOptions(
|
||||||
|
@ -13,13 +9,4 @@ import stepdefs.Preconditions;
|
||||||
)
|
)
|
||||||
|
|
||||||
public class RunTest {
|
public class RunTest {
|
||||||
@BeforeClass
|
|
||||||
public static void setup() {
|
|
||||||
Preconditions.driver= new FirefoxDriver();
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterClass
|
|
||||||
public static void teardown() {
|
|
||||||
Preconditions.driver.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
package stepdefs;
|
|
||||||
|
|
||||||
import org.openqa.selenium.WebDriver;
|
|
||||||
|
|
||||||
public class Preconditions {
|
|
||||||
public static WebDriver driver;
|
|
||||||
}
|
|
|
@ -1,9 +1,8 @@
|
||||||
package stepdefs;
|
package stepdefs;
|
||||||
|
|
||||||
import io.cucumber.java.PendingException;
|
import cucumber.api.java.en.Given;
|
||||||
import io.cucumber.java.en.Given;
|
import cucumber.api.java.en.Then;
|
||||||
import io.cucumber.java.en.Then;
|
import cucumber.api.java.en.When;
|
||||||
import io.cucumber.java.en.When;
|
|
||||||
|
|
||||||
public class PriceAlarm {
|
public class PriceAlarm {
|
||||||
@Given("^the user has at least (\\d+) price alarm set$")
|
@Given("^the user has at least (\\d+) price alarm set$")
|
||||||
|
|
|
@ -1,38 +1,21 @@
|
||||||
package stepdefs;
|
package stepdefs;
|
||||||
|
|
||||||
import io.cucumber.java.PendingException;
|
import cucumber.api.PendingException;
|
||||||
import io.cucumber.java.en.Given;
|
import cucumber.api.java.en.Given;
|
||||||
import io.cucumber.java.en.Then;
|
import cucumber.api.java.en.Then;
|
||||||
import io.cucumber.java.en.When;
|
import cucumber.api.java.en.When;
|
||||||
import org.openqa.selenium.By;
|
|
||||||
import org.openqa.selenium.Keys;
|
|
||||||
import org.openqa.selenium.WebElement;
|
|
||||||
import org.openqa.selenium.support.ui.ExpectedConditions;
|
|
||||||
import org.openqa.selenium.support.ui.WebDriverWait;
|
|
||||||
|
|
||||||
public class SearchProduct {
|
public class SearchProduct {
|
||||||
@Given("^the user is on the landing page$")
|
@Given("^the user is on the landing page$")
|
||||||
public void the_user_is_on_the_landing_page() throws Exception {
|
public void the_user_is_on_the_landing_page() throws Exception {
|
||||||
//throw new PendingException();
|
|
||||||
Preconditions.driver.get("https://betterzon.xyz");
|
|
||||||
WebElement logo = (new WebDriverWait(Preconditions.driver, 10))
|
|
||||||
.until(ExpectedConditions.elementToBeClickable(By.cssSelector(".logo")));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@When("^the user enters the search term \"([^\"]*)\" and clicks search$")
|
@When("^the user enters the search term \"([^\"]*)\" and clicks search$")
|
||||||
public void the_user_enters_the_search_term_and_clicks_search(String searchTerm) throws Exception {
|
public void the_user_enters_the_search_term_and_clicks_search(String arg0) throws Exception {
|
||||||
WebElement searchField = Preconditions.driver.findElement(By.cssSelector(".ng-untouched.ng-pristine.ng-valid"));
|
|
||||||
searchField.sendKeys(searchTerm);
|
|
||||||
searchField.sendKeys(Keys.ENTER);
|
|
||||||
WebElement logo = (new WebDriverWait(Preconditions.driver, 10))
|
|
||||||
.until(ExpectedConditions.elementToBeClickable(By.cssSelector(".logo")));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Then("^the user should see the error page \"([^\"]*)\"$")
|
@Then("^the user should see the error page \"([^\"]*)\"$")
|
||||||
public void the_user_should_see_the_error_page(String arg0) throws Exception {
|
public void the_user_should_see_the_error_page(String arg0) throws Exception {
|
||||||
WebElement noProdsFoundMsg = (new WebDriverWait(Preconditions.driver, 10))
|
|
||||||
.until(ExpectedConditions.elementToBeClickable(By.cssSelector(".ng-star-inserted")));
|
|
||||||
assert(noProdsFoundMsg.getText().contains("No Products found!"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Given("^the user is not logged in$")
|
@Given("^the user is not logged in$")
|
||||||
|
@ -45,9 +28,6 @@ public class SearchProduct {
|
||||||
|
|
||||||
@Then("^the user should see a list of products$")
|
@Then("^the user should see a list of products$")
|
||||||
public void the_user_should_see_a_list_of_products() throws Exception {
|
public void the_user_should_see_a_list_of_products() throws Exception {
|
||||||
WebElement product = (new WebDriverWait(Preconditions.driver, 10))
|
|
||||||
.until(ExpectedConditions.elementToBeClickable(By.cssSelector(".productItem.ng-star-inserted")));
|
|
||||||
assert(product.isDisplayed());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@When("^the user clicks on the first product$")
|
@When("^the user clicks on the first product$")
|
||||||
|
|
22
Frontend/package-lock.json
generated
22
Frontend/package-lock.json
generated
|
@ -4210,12 +4210,6 @@
|
||||||
"integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=",
|
"integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/cookieconsent": {
|
|
||||||
"version": "3.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/cookieconsent/-/cookieconsent-3.1.1.tgz",
|
|
||||||
"integrity": "sha512-v8JWLJcI7Zs9NWrs8hiVldVtm3EBF70TJI231vxn6YToBGj0c9dvdnYwltydkAnrbBMOM/qX1xLFrnTfm5wTag==",
|
|
||||||
"peer": true
|
|
||||||
},
|
|
||||||
"node_modules/copy-concurrently": {
|
"node_modules/copy-concurrently": {
|
||||||
"version": "1.0.5",
|
"version": "1.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/copy-concurrently/-/copy-concurrently-1.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/copy-concurrently/-/copy-concurrently-1.0.5.tgz",
|
||||||
|
@ -9276,12 +9270,7 @@
|
||||||
"node_modules/ngx-cookieconsent": {
|
"node_modules/ngx-cookieconsent": {
|
||||||
"version": "2.2.3",
|
"version": "2.2.3",
|
||||||
"resolved": "https://registry.npmjs.org/ngx-cookieconsent/-/ngx-cookieconsent-2.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/ngx-cookieconsent/-/ngx-cookieconsent-2.2.3.tgz",
|
||||||
"integrity": "sha512-vg7M4XZSTFRAQq20M0YVJdz5OkXIu0t0MSYos0vvu7oblaEivQstA1Mg5bO7OJYp+oFoTEefWhvO2nCiyHn9SQ==",
|
"integrity": "sha512-vg7M4XZSTFRAQq20M0YVJdz5OkXIu0t0MSYos0vvu7oblaEivQstA1Mg5bO7OJYp+oFoTEefWhvO2nCiyHn9SQ=="
|
||||||
"peerDependencies": {
|
|
||||||
"@angular/common": ">=6.0.0",
|
|
||||||
"@angular/core": ">=6.0.0",
|
|
||||||
"cookieconsent": ">=3.1.0"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"node_modules/nice-try": {
|
"node_modules/nice-try": {
|
||||||
"version": "1.0.5",
|
"version": "1.0.5",
|
||||||
|
@ -19828,12 +19817,6 @@
|
||||||
"integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=",
|
"integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"cookieconsent": {
|
|
||||||
"version": "3.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/cookieconsent/-/cookieconsent-3.1.1.tgz",
|
|
||||||
"integrity": "sha512-v8JWLJcI7Zs9NWrs8hiVldVtm3EBF70TJI231vxn6YToBGj0c9dvdnYwltydkAnrbBMOM/qX1xLFrnTfm5wTag==",
|
|
||||||
"peer": true
|
|
||||||
},
|
|
||||||
"copy-concurrently": {
|
"copy-concurrently": {
|
||||||
"version": "1.0.5",
|
"version": "1.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/copy-concurrently/-/copy-concurrently-1.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/copy-concurrently/-/copy-concurrently-1.0.5.tgz",
|
||||||
|
@ -24040,8 +24023,7 @@
|
||||||
"ngx-cookieconsent": {
|
"ngx-cookieconsent": {
|
||||||
"version": "2.2.3",
|
"version": "2.2.3",
|
||||||
"resolved": "https://registry.npmjs.org/ngx-cookieconsent/-/ngx-cookieconsent-2.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/ngx-cookieconsent/-/ngx-cookieconsent-2.2.3.tgz",
|
||||||
"integrity": "sha512-vg7M4XZSTFRAQq20M0YVJdz5OkXIu0t0MSYos0vvu7oblaEivQstA1Mg5bO7OJYp+oFoTEefWhvO2nCiyHn9SQ==",
|
"integrity": "sha512-vg7M4XZSTFRAQq20M0YVJdz5OkXIu0t0MSYos0vvu7oblaEivQstA1Mg5bO7OJYp+oFoTEefWhvO2nCiyHn9SQ=="
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"nice-try": {
|
"nice-try": {
|
||||||
"version": "1.0.5",
|
"version": "1.0.5",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<app-top-bar></app-top-bar>
|
<app-top-bar></app-top-bar>
|
||||||
<div class="page-content">
|
|
||||||
<router-outlet></router-outlet>
|
<router-outlet></router-outlet>
|
||||||
</div>
|
|
||||||
<app-bottom-bar></app-bottom-bar>
|
<app-bottom-bar></app-bottom-bar>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,63 +1,28 @@
|
||||||
.bottom-bar-wrapper {
|
.bottom-bar-container {
|
||||||
display: grid;
|
background-color: black
|
||||||
grid-template-columns: 546px 546px 546px;
|
;
|
||||||
grid-template-rows: 70px 70px 70px;
|
|
||||||
grid-column-gap: 0px;
|
|
||||||
grid-row-gap: 0px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.folge-uns-item {
|
|
||||||
grid-column: 2; grid-row: 1;
|
|
||||||
justify-self: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.link-items {
|
|
||||||
grid-column: 2; grid-row: 2;
|
|
||||||
justify-self: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.footer-links li {
|
|
||||||
display: inline;
|
|
||||||
margin-right: 60px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#footer-line {
|
|
||||||
grid-area: 3/1/3/4;
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
background-color: #000000;
|
height: 68px;
|
||||||
height: 2px;
|
position: fixed;
|
||||||
|
padding: 16px;
|
||||||
|
align-items: center;
|
||||||
|
bottom: 0;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 100px auto 100px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bottom-logo {
|
.betterzonlogo {
|
||||||
grid-column: 1; grid-row: 3;
|
grid-column-start: 1;
|
||||||
|
grid-column-end: 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bottom-info {
|
.references {
|
||||||
grid-column: 3; grid-row: 3;
|
grid-column-start: 2;
|
||||||
justify-self: right;
|
grid-column-end: 3;
|
||||||
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
#folge {
|
.copyright {
|
||||||
font-size: 46px;
|
grid-column-start: 3;
|
||||||
font-weight: bold;
|
grid-column-end: 4;
|
||||||
color: #E53167;
|
|
||||||
margin-right: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#uns {
|
|
||||||
font-size: 32px;
|
|
||||||
font-weight: bold;
|
|
||||||
color: #000000;
|
|
||||||
}
|
|
||||||
|
|
||||||
#better {
|
|
||||||
font-size: 28px;
|
|
||||||
font-weight: bold;
|
|
||||||
color: #3480E3;
|
|
||||||
}
|
|
||||||
|
|
||||||
#zon {
|
|
||||||
font-size: 28px;
|
|
||||||
font-weight: bold;
|
|
||||||
color: #E53167;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +1,14 @@
|
||||||
<div class="bottom-bar-wrapper">
|
<div class="bottom-bar-container">
|
||||||
<div class="folge-uns-item">
|
<div class="betterzonlogo">
|
||||||
<p><span id="folge">FOLGE</span><span id="uns">UNS</span></p>
|
<a>
|
||||||
|
<img src="assets/images/Betterzon.svg" [routerLink]="''" alt="Betterzon Logo" width="50px">
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="link-items">
|
<div class="references">
|
||||||
<ul style="list-style-type:none" class="footer-links">
|
<mat-icon aria-hidden="false" aria-label="Example home icon" [routerLink]="''">home</mat-icon>
|
||||||
<li><a href="https://github.com/Mueller-Patrick/Betterzon">GiT</a></li>
|
|
||||||
<li><a href="https://blog.betterzon.xyz/">BLOG</a></li>
|
|
||||||
<li><a href="https://github.com/Mueller-Patrick/Betterzon/wiki">Wiki</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
</div>
|
||||||
<div id="footer-line">
|
<div class="copyright">
|
||||||
|
Betterzon ©2020
|
||||||
</div>
|
|
||||||
<div class="bottom-logo">
|
|
||||||
<p><span id="better">BETTER</span><span id="zon">ZON</span></p>
|
|
||||||
</div>
|
|
||||||
<div class="bottom-info">
|
|
||||||
<ul style="list-style-type:none" class="footer-links">
|
|
||||||
<li><a>DATENSCHUTZERKLÄRUNG</a></li>
|
|
||||||
<li><a>IMPRESSUM</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1 +1,3 @@
|
||||||
|
.column {
|
||||||
|
width: 33.33%;
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
<div id="mainComponents">
|
<div id="mainComponents">
|
||||||
<div id="searchContainer">
|
<div id="searchContainer">
|
||||||
<input type="text" [(ngModel)]="searchInput" placeholder="Search" (keyup.enter)="startedSearch()">
|
<input type="text" [(ngModel)]="searchInput" placeholder="Search" (keyup.enter)="startedSearch()">
|
||||||
|
@ -14,3 +15,4 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<app-footer></app-footer>
|
||||||
|
|
|
@ -1,13 +1,22 @@
|
||||||
/* general settings */
|
|
||||||
|
|
||||||
* {
|
* {
|
||||||
|
font-family: 'Roboto', Arial, sans-serif;
|
||||||
|
color: #616161;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
}
|
}
|
||||||
|
|
||||||
html, body {
|
body {
|
||||||
height: 100%;
|
|
||||||
margin: 0;
|
margin: 0;
|
||||||
background-color: #FFFFFF;
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
router-outlet + * {
|
||||||
|
padding: 0 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Text */
|
/* Text */
|
||||||
|
@ -24,10 +33,6 @@ h1, h2 {
|
||||||
font-weight: lighter;
|
font-weight: lighter;
|
||||||
}
|
}
|
||||||
|
|
||||||
h3 {
|
|
||||||
font-size: 18px;
|
|
||||||
}
|
|
||||||
|
|
||||||
p {
|
p {
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
@ -36,21 +41,14 @@ p {
|
||||||
|
|
||||||
a {
|
a {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
color: #000000;
|
color: #1976d2;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
a:hover {
|
a:hover {
|
||||||
opacity: 0.8;
|
opacity: 0.8;
|
||||||
color: #3480E3;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
a, p{
|
|
||||||
font-size: 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* links */
|
|
||||||
|
|
||||||
/* Input */
|
/* Input */
|
||||||
|
|
||||||
input {
|
input {
|
||||||
|
@ -109,7 +107,7 @@ label {
|
||||||
app-top-bar {
|
app-top-bar {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 68px;
|
height: 68px;
|
||||||
background-color: #f2f2f2;
|
background-color: #1976d2;
|
||||||
padding: 16px;
|
padding: 16px;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
|
@ -118,22 +116,9 @@ app-top-bar {
|
||||||
box-shadow: 0 3px 5px -1px rgba(0,0,0,.2),0 6px 10px 0 rgba(0,0,0,.14),0 1px 18px 0 rgba(0,0,0,.12)
|
box-shadow: 0 3px 5px -1px rgba(0,0,0,.2),0 6px 10px 0 rgba(0,0,0,.14),0 1px 18px 0 rgba(0,0,0,.12)
|
||||||
}
|
}
|
||||||
|
|
||||||
app-top-bar h1 {
|
app-top-bar, app-bottom-bar h1 {
|
||||||
color: white;
|
color: white;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Bottom Bar */
|
|
||||||
app-bottom-bar{
|
|
||||||
background-color: #F8F8F8;
|
|
||||||
width: 1640px;
|
|
||||||
height: 210px;
|
|
||||||
position: fixed;
|
|
||||||
margin-top: 90px;
|
|
||||||
bottom: 0;
|
|
||||||
flex-direction: row;
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user