mirror of
https://github.com/Mueller-Patrick/Betterzon.git
synced 2024-12-22 19:55:12 +00:00
BETTERZON-107: Refactoring code with Proxy as design pattern (#49)
This commit is contained in:
parent
ead1f10b25
commit
e7543e6430
|
@ -4,7 +4,24 @@ export interface Price {
|
|||
vendor_id: number;
|
||||
price_in_cents: number;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ const pool = mariadb.createPool({
|
|||
* Data Model Interfaces
|
||||
*/
|
||||
|
||||
import {Price} from './price.interface';
|
||||
import {Deal, Price} from './price.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
|
||||
let deals: Price[] = [];
|
||||
let deals: Deal[] = [];
|
||||
|
||||
Object.keys(allPrices).forEach(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
|
||||
if (deal.amazonDifferencePercent > 0) {
|
||||
deals.push(deal as Price);
|
||||
deals.push(deal as Deal);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user