BETTERZON-107: Refactoring code with Proxy as design pattern (#49)

This commit is contained in:
Patrick 2021-05-20 10:23:41 +02:00 committed by GitHub
parent ead1f10b25
commit e7543e6430
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 6 deletions

View File

@ -4,7 +4,24 @@ export interface Price {
vendor_id: number; vendor_id: number;
price_in_cents: number; price_in_cents: number;
timestamp: Date; timestamp: Date;
// Only for deals }
amazonDifference?: number;
amazonDifferencePercent?: number; export class Deal implements Price {
price_id: number;
product_id: number;
vendor_id: number;
price_in_cents: number;
timestamp: Date;
amazonDifference: number;
amazonDifferencePercent: number;
constructor(price_id: number, product_id: number, vendor_id: number, price_in_cents: number, timestamp: Date, amazonDifference: number, amazonDifferencePercent: number) {
this.price_id = price_id;
this.product_id = product_id;
this.vendor_id = vendor_id;
this.price_in_cents = price_in_cents;
this.timestamp = timestamp;
this.amazonDifference = amazonDifference;
this.amazonDifferencePercent = amazonDifferencePercent;
}
} }

View File

@ -15,7 +15,7 @@ const pool = mariadb.createPool({
* Data Model Interfaces * Data Model Interfaces
*/ */
import {Price} from './price.interface'; import {Deal, Price} from './price.interface';
import {Prices} from './prices.interface'; import {Prices} from './prices.interface';
@ -255,7 +255,7 @@ export const getBestDeals = async (amount: number): Promise<Prices> => {
} }
// Iterate over all prices to find the products with the biggest difference between amazon and other vendor // Iterate over all prices to find the products with the biggest difference between amazon and other vendor
let deals: Price[] = []; let deals: Deal[] = [];
Object.keys(allPrices).forEach(productId => { Object.keys(allPrices).forEach(productId => {
if (allPrices[parseInt(productId)]) { if (allPrices[parseInt(productId)]) {
@ -287,7 +287,7 @@ export const getBestDeals = async (amount: number): Promise<Prices> => {
// Push only deals were the amazon price is actually higher // Push only deals were the amazon price is actually higher
if (deal.amazonDifferencePercent > 0) { if (deal.amazonDifferencePercent > 0) {
deals.push(deal as Price); deals.push(deal as Deal);
} }
} }
}); });