@bytebrand/export-cars 1.10.1 → 1.10.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytebrand/export-cars",
3
- "version": "1.10.1",
3
+ "version": "1.10.2",
4
4
  "description": "",
5
5
  "author": "bytebrand",
6
6
  "license": "UNLICENSED",
@@ -60,5 +60,5 @@
60
60
  "engines": {
61
61
  "node": ">=14.0.0"
62
62
  },
63
- "gitHead": "b3581108ff2e4747c41c6c69facbd8a599051940"
63
+ "gitHead": "4fd5ec3e85f39f7932eead7b1dbd60dc780d39f0"
64
64
  }
@@ -1,9 +1,11 @@
1
1
  import { CACHE_MANAGER, Inject, Injectable } from '@nestjs/common';
2
+
3
+ import { MarketingImageConfigInterface, MarketingImageConfigsInterface } from '@bytebrand/autode-request';
4
+
2
5
  import { RequestService } from './request.service';
3
6
  import { Cache } from 'cache-manager';
4
7
  import { get } from 'lodash';
5
- import { MarketingImageConfigInterface, MarketingImageConfigsInterface } from '@bytebrand/autode-request';
6
- import { ExportType, FileType } from '../enums';
8
+
7
9
 
8
10
  @Injectable()
9
11
  export class UserService {
@@ -1,5 +1,5 @@
1
- import { TranslatorExtended } from '@bytebrand/schema-tools';
2
- import { de, deVehicleDetailsPage, deVehicleProps } from '@bytebrand/i18n-dictionaries';
1
+ import { Cache } from 'cache-manager';
2
+ import * as moment from 'moment';
3
3
  import {
4
4
  escape,
5
5
  findIndex,
@@ -15,17 +15,23 @@ import {
15
15
  trim,
16
16
  truncate,
17
17
  } from 'lodash';
18
- import * as moment from 'moment';
19
- import { DataSchemes } from '@bytebrand/car-schema';
20
- import { DePostalCodesService } from '@bytebrand/car-basic-data-scope';
18
+
19
+ import { CACHE_MANAGER, Inject, Injectable } from '@nestjs/common';
20
+
21
21
  import { DePostalCodesEntryInterface } from '@bytebrand/car-basic-data-scope/dist/interfaces/DePostalCodesInterface';
22
- import { ConfigService, ImagesService } from '../services';
22
+ import { de, deVehicleDetailsPage, deVehicleProps } from '@bytebrand/i18n-dictionaries';
23
+ import { DePostalCodesService } from '@bytebrand/car-basic-data-scope';
23
24
  import { ImboImageResponseInterface } from '@bytebrand/chunkable';
24
- import { isValidVin } from '../utils/validator.utils';
25
- import { Injectable } from '@nestjs/common';
26
- import { FbDescription } from './fb-description.transformer';
25
+ import { TranslatorExtended } from '@bytebrand/schema-tools';
26
+ import { DataSchemes } from '@bytebrand/car-schema';
27
+
27
28
  import { Description } from '../interfaces/description.interface';
29
+ import { FbDescription } from './fb-description.transformer';
30
+ import { ConfigService, ImagesService } from '../services';
28
31
  import { FbEquipment } from './fb-equipment.transformer';
32
+ import { isValidVin } from '../utils/validator.utils';
33
+ import { UserService } from 'src/services';
34
+ import { ImageType } from '../enums';
29
35
  import {
30
36
  DEFAULT_ADDR1,
31
37
  DEFAULT_CITY,
@@ -34,8 +40,7 @@ import {
34
40
  FB_MIN_MILEAGES,
35
41
  TIMESTAMP_FIRST_YEAR,
36
42
  } from '../constants/fb.constants';
37
- import { UserService } from 'src/services';
38
- import { ImageType } from '../enums';
43
+
39
44
 
40
45
  @Injectable()
41
46
  export class FbTransformer {
@@ -43,7 +48,11 @@ export class FbTransformer {
43
48
  private postalCodesService: DePostalCodesService;
44
49
  private imagesService: ImagesService;
45
50
 
46
- constructor(private readonly configService: ConfigService, private readonly userService: UserService) {
51
+ constructor(
52
+ @Inject(CACHE_MANAGER) private cacheManager: Cache,
53
+ private readonly configService: ConfigService,
54
+ private readonly userService: UserService
55
+ ) {
47
56
  this.imagesService = new ImagesService(configService, userService);
48
57
  const dict = { ...de, ...deVehicleProps, ...deVehicleDetailsPage };
49
58
  this.translator = new TranslatorExtended(dict);
@@ -317,10 +326,17 @@ export class FbTransformer {
317
326
  }
318
327
 
319
328
  private async getLocationByInfo(info: { zip: number; city: string }): Promise<DePostalCodesEntryInterface> {
320
- let entry: DePostalCodesEntryInterface = await this.postalCodesService.getLocationByPostalCode(info.zip);
329
+ const cacheKey = `${info.city}_${info.zip}`;
330
+
331
+ let entry: DePostalCodesEntryInterface = await this.cacheManager.get(cacheKey);
332
+ if (entry) { return entry };
333
+
334
+ entry = await this.postalCodesService.getLocationByPostalCode(info.zip);
335
+ await this.cacheManager.set(cacheKey, entry);
321
336
 
322
337
  if (!entry) {
323
338
  entry = await this.postalCodesService.getLocationByCity(info.city);
339
+ await this.cacheManager.set(cacheKey, entry);
324
340
  }
325
341
  return entry;
326
342
  }