@bytebrand/export-cars 1.22.22 → 1.22.24

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytebrand/export-cars",
3
- "version": "1.22.22",
3
+ "version": "1.22.24",
4
4
  "description": "",
5
5
  "author": "bytebrand",
6
6
  "license": "UNLICENSED",
@@ -8,7 +8,6 @@ import { Injectable } from '@nestjs/common';
8
8
  import { ConfigService, ImagesService, TransformerService, UserService } from '../services';
9
9
  import { GoogleXmlItem } from '../interfaces';
10
10
  import { isValidVin } from '../utils';
11
- import moment from 'moment';
12
11
 
13
12
  const GOOGLE_MAX_TRIM_LENGTH = 50;
14
13
  const TIMESTAMP_FIRST_YEAR = 1970;
@@ -215,7 +214,7 @@ export class GoogleTransformer {
215
214
  }
216
215
 
217
216
  private getVehicleMsrp(car: DataSchemes.Car): string | undefined {
218
- const retailPrice = get(car, 'recommendedRetailPrice');
217
+ const retailPrice = get(car, 'price.recomendedRetailPrice');
219
218
  const salesPrice = get(car, 'price.currentSalesPrice', 0);
220
219
  if (!retailPrice || round(retailPrice, 2) === round(salesPrice, 2)) {
221
220
  return undefined;
@@ -540,12 +539,19 @@ export class GoogleTransformer {
540
539
  return !mileage ? 10 : mileage;
541
540
  }
542
541
 
543
- private getYear(car: DataSchemes.Car) {
544
- // mainData.firstModelsProductionDate is already a 4-digit year (mobile.de "vintage"),
545
- // not a timestamp — do not run it through `new Date(...)`.
542
+ private getYear(car: DataSchemes.Car): number {
543
+ // mainData.firstModelsProductionDate/constructionYear are already 4-digit years
544
+ // (mobile.de "vintage"); firstRegistration/metaData.creationDate are unix timestamps
545
+ // in seconds. Not every car has firstModelsProductionDate (e.g. dealer FTP imports),
546
+ // so fall through to other date sources — `year` is a mandatory Google feed field.
546
547
  const firstModelsProductionYear = toSafeInteger(get(car, 'mainData.firstModelsProductionDate', 0));
548
+ const constructionYear = toSafeInteger(get(car, 'mainData.constructionYear', 0));
549
+ const firstRegistrationYear = new Date(+get(car, 'mainData.firstRegistration', 0) * 1000).getUTCFullYear();
550
+ const metaCreationYear = new Date(+get(car, 'metaData.creationDate', 0) * 1000).getUTCFullYear();
551
+ const currentYear = new Date().getUTCFullYear();
547
552
 
548
- return firstModelsProductionYear > TIMESTAMP_FIRST_YEAR ? firstModelsProductionYear : null
553
+ return [firstModelsProductionYear, constructionYear, firstRegistrationYear, metaCreationYear, currentYear]
554
+ .find(year => year > TIMESTAMP_FIRST_YEAR);
549
555
  }
550
556
 
551
557
  private getDateFirstRegistered(car: DataSchemes.Car): string {