@bytebrand/export-cars 1.23.1 → 1.23.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/transformers/facebook-shop.transformer.d.ts +1 -0
- package/dist/transformers/facebook-shop.transformer.js +23 -20
- package/dist/transformers/facebook-shop.transformer.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/transformers/facebook-shop.transformer.ts +27 -20
- package/dist/tsconfig.tsbuildinfo +0 -1
package/package.json
CHANGED
|
@@ -118,14 +118,14 @@ export class FacebookShopTransformer {
|
|
|
118
118
|
// matching exactly what the CDP displays (per ticket: data.rate.*/data.leasing.*).
|
|
119
119
|
const offersFinancing = get(car, 'rate.offersFinancing') !== false;
|
|
120
120
|
const rawFinancing = {
|
|
121
|
-
monthlyPayment:
|
|
122
|
-
downPayment:
|
|
123
|
-
termLength:
|
|
121
|
+
monthlyPayment: this.getNum(car, 'rate.monthlyInstallment'),
|
|
122
|
+
downPayment: this.getNum(car, 'rate.firstInstallment'),
|
|
123
|
+
termLength: this.getNum(car, 'rate.paybackPeriod'),
|
|
124
124
|
};
|
|
125
125
|
const rawLeasing = {
|
|
126
|
-
monthlyPayment:
|
|
127
|
-
downPayment:
|
|
128
|
-
termLength:
|
|
126
|
+
monthlyPayment: this.getNum(car, 'leasing.monthlyInstallment'),
|
|
127
|
+
downPayment: this.getNum(car, 'leasing.firstInstallment'),
|
|
128
|
+
termLength: this.getNum(car, 'leasing.paybackPeriod'),
|
|
129
129
|
};
|
|
130
130
|
const leasingIsEligible = this.isLeasingEligible(car);
|
|
131
131
|
|
|
@@ -140,10 +140,10 @@ export class FacebookShopTransformer {
|
|
|
140
140
|
disclaimer: OFFER_DISCLAIMER,
|
|
141
141
|
financials: {
|
|
142
142
|
...rawFinancing,
|
|
143
|
-
apr:
|
|
144
|
-
finalPayment:
|
|
145
|
-
totalAmount:
|
|
146
|
-
netLoanAmount:
|
|
143
|
+
apr: this.getNum(computedFinancing, 'annualPercentageRate'),
|
|
144
|
+
finalPayment: this.getNum(computedFinancing, 'finalInstallment'),
|
|
145
|
+
totalAmount: this.getNum(computedFinancing, 'grossLoanAmount'),
|
|
146
|
+
netLoanAmount: this.getNum(computedFinancing, 'netLoanAmount'),
|
|
147
147
|
},
|
|
148
148
|
});
|
|
149
149
|
}
|
|
@@ -157,10 +157,10 @@ export class FacebookShopTransformer {
|
|
|
157
157
|
disclaimer: OFFER_DISCLAIMER,
|
|
158
158
|
financials: {
|
|
159
159
|
...rawLeasing,
|
|
160
|
-
apr:
|
|
161
|
-
finalPayment:
|
|
162
|
-
totalAmount:
|
|
163
|
-
netLoanAmount:
|
|
160
|
+
apr: this.getNum(computedLeasing, 'annualPercentageRate'),
|
|
161
|
+
finalPayment: this.getNum(computedLeasing, 'finalInstallment'),
|
|
162
|
+
totalAmount: this.getNum(computedLeasing, 'grossLoanAmount'),
|
|
163
|
+
netLoanAmount: this.getNum(computedLeasing, 'netLoanAmount'),
|
|
164
164
|
},
|
|
165
165
|
});
|
|
166
166
|
}
|
|
@@ -194,10 +194,10 @@ export class FacebookShopTransformer {
|
|
|
194
194
|
// Mirrors getLeasing.ts's isLeasingActive: same car ages out of leasing eligibility once
|
|
195
195
|
// it's older than leasing.maxAge months or past leasing.maxMileage km.
|
|
196
196
|
private isLeasingEligible(car: DataSchemes.Car): boolean {
|
|
197
|
-
const firstRegistration =
|
|
198
|
-
const mileage =
|
|
199
|
-
const maxAge =
|
|
200
|
-
const maxMileage =
|
|
197
|
+
const firstRegistration = this.getNum(car, 'mainData.firstRegistration');
|
|
198
|
+
const mileage = this.getNum(car, 'mainData.mileage');
|
|
199
|
+
const maxAge = this.getNum(car, 'leasing.maxAge', 24);
|
|
200
|
+
const maxMileage = this.getNum(car, 'leasing.maxMileage', 1000000);
|
|
201
201
|
|
|
202
202
|
const registrationMs = firstRegistration ? firstRegistration * 1000 : Date.now();
|
|
203
203
|
const maxCarAge = new Date().setMonth(new Date().getMonth() - maxAge);
|
|
@@ -221,6 +221,13 @@ export class FacebookShopTransformer {
|
|
|
221
221
|
return { value, isGoogle };
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
+
// lodash's get() only falls back to the default for an *undefined* path — an explicit
|
|
225
|
+
// `null` stored on the Car document (a common Mongo pattern for "not set") passes
|
|
226
|
+
// straight through and ends up rendering as an empty XML tag. Coalesce it here instead.
|
|
227
|
+
private getNum(source: any, path: string, fallback = 0): number {
|
|
228
|
+
return get(source, path) ?? fallback;
|
|
229
|
+
}
|
|
230
|
+
|
|
224
231
|
private formatEUR(value: number): string {
|
|
225
232
|
return Math.round(value || 0).toLocaleString(DE_LOCALE);
|
|
226
233
|
}
|
|
@@ -233,7 +240,7 @@ export class FacebookShopTransformer {
|
|
|
233
240
|
}
|
|
234
241
|
|
|
235
242
|
private getYear(car: DataSchemes.Car): string {
|
|
236
|
-
const firstRegistration =
|
|
243
|
+
const firstRegistration = this.getNum(car, 'mainData.firstRegistration');
|
|
237
244
|
return firstRegistration ? moment(firstRegistration * 1000).format('YYYY') : moment().format('YYYY');
|
|
238
245
|
}
|
|
239
246
|
|
|
@@ -252,7 +259,7 @@ export class FacebookShopTransformer {
|
|
|
252
259
|
}
|
|
253
260
|
|
|
254
261
|
private getPriceValue(car: DataSchemes.Car): number {
|
|
255
|
-
return round(
|
|
262
|
+
return round(this.getNum(car, 'price.currentSalesPrice'), 2);
|
|
256
263
|
}
|
|
257
264
|
|
|
258
265
|
private getColor(car: DataSchemes.Car): string {
|