From 50ef82785b6c6cd6ffc3c3d74a1c738855516745 Mon Sep 17 00:00:00 2001 From: Bamdad Sabbagh Date: Tue, 26 Mar 2024 17:26:26 +0100 Subject: [PATCH] feat(Ad): Add price per square meter for real estates ads Fixes #385 --- src/app/ad/ad.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/app/ad/ad.ts b/src/app/ad/ad.ts index 980e233..6b87474 100644 --- a/src/app/ad/ad.ts +++ b/src/app/ad/ad.ts @@ -136,6 +136,14 @@ export class Ad { return this.props?.price?.[0].toString() || '?'; } + private getPricePerSquareMeter() { + const price = this.props.price[0]; + const square = this.props.attributes.find((attr) => attr.key === 'square'); + const squarePrice = Number(square.value); + const pricePerSquareMeter = price / squarePrice; + return pricePerSquareMeter.toFixed(0); + } + private getName() { return `${this.props.location.zipcode} - ${this.props.list_id} - ${this.props.subject} - ${this.getPrice()} euros`; } @@ -164,6 +172,10 @@ export class Ad { } } + private get isRealEstateSale(): boolean { + return this.props.category_name === 'Ventes immobilières'; + } + private printAttributes(): void { // Title this.pdf.printText({ @@ -183,6 +195,13 @@ export class Ad { }); } }); + + if (this.isRealEstateSale) { + this.pdf.printText({ + text: `Prix au m² : ${this.getPricePerSquareMeter()} €/m²`, + size: FONT_SIZES.small, + }); + } } private buildDescription(): void {