@bytebrand/export-cars 1.21.11 → 1.21.13

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.21.11",
3
+ "version": "1.21.13",
4
4
  "description": "",
5
5
  "author": "bytebrand",
6
6
  "license": "UNLICENSED",
@@ -8,6 +8,7 @@ import { CarService, RulesService, LoaderService, ConfigService } from '../servi
8
8
  import { MobileTransformer } from '../transformers/mobile.transformer';
9
9
  import { Exporter } from '../interfaces/exporter.interface';
10
10
  import { SantanderCSVBuilder } from 'src/formats/santander-csv.builder';
11
+ import { SantanderTransformer } from 'src/transformers/santander.transformer';
11
12
 
12
13
  @Injectable()
13
14
  export class SantanderExporter implements Exporter {
@@ -26,7 +27,7 @@ export class SantanderExporter implements Exporter {
26
27
 
27
28
  const santanderCSVBuilder = new SantanderCSVBuilder(fileCSV);
28
29
 
29
- const mobileTransformer = await this.moduleRef.create(MobileTransformer);
30
+ const santanderTransformer = await this.moduleRef.create(SantanderTransformer);
30
31
 
31
32
  await this.loaderService.process(async (chunk: FsChunkInterface) => {
32
33
  chunk.data = chunk.data.filter(e => this.carService.filterCar(e, this.rulesService.rules));
@@ -35,9 +36,11 @@ export class SantanderExporter implements Exporter {
35
36
  for (let i = 0; i < chunk.data.length; i += 1) {
36
37
  const data = chunk.data[i];
37
38
  const { car, images } = data;
38
- const transformedData = await mobileTransformer.transform(car, images);
39
+ const transformedData = await santanderTransformer.transform(car, images);
39
40
 
40
- await santanderCSVBuilder.addItem(transformedData);
41
+ const transformedNormalizedData = await santanderTransformer.normalizeCarData(transformedData)
42
+
43
+ await santanderCSVBuilder.addItem(transformedNormalizedData);
41
44
  this.carService.counter.countCar(data.images);
42
45
  }
43
46
  }
@@ -5,7 +5,12 @@ export class SantanderCSVBuilder extends XMLBuilderBase {
5
5
  }
6
6
 
7
7
  async addItem(car: unknown): Promise<void> {
8
- let values = Object.values(car);
8
+ let values = Object.values(car).map(value => {
9
+ if (typeof value === 'string' && value.includes(',')) {
10
+ return `"${value}"`;
11
+ }
12
+ return value;
13
+ });
9
14
  await this.write(values.join(',') + '\n');
10
15
  }
11
16
 
@@ -0,0 +1,53 @@
1
+ import { get, isEmpty, isNil, set, toString, upperFirst } from 'lodash';
2
+
3
+ import { Injectable } from '@nestjs/common';
4
+
5
+ import { CarDescriptionFactory, DescriptionTypeEnum } from '@bytebrand/car-description';
6
+ import { ImboImageResponseInterface } from '@bytebrand/chunkable';
7
+ import { LoggerService } from '@bytebrand/cronicle-helper';
8
+ import { DataSchemes } from '@bytebrand/car-schema';
9
+
10
+ import { MappingService, UserService, ImagesService } from '../services';
11
+ import { MappingRules } from '../interfaces/mapping-rules.interface';
12
+ import { isNotEmptyArray } from '../utils';
13
+ import { ConfigService } from '../services';
14
+ import { ExportType } from '../enums';
15
+ import { MobileTransformer } from './mobile.transformer';
16
+
17
+ const vinGenerator = require('vin-generator');
18
+
19
+ @Injectable()
20
+ export class SantanderTransformer extends MobileTransformer {
21
+ constructor(
22
+ mappingService: MappingService,
23
+ userService: UserService,
24
+ configService: ConfigService,
25
+ imagesService: ImagesService,
26
+ ) {
27
+ super(mappingService, userService, configService, imagesService);
28
+ }
29
+
30
+ async normalizeCarData(transformedCarData: unknown): Promise<unknown> {
31
+ const data = transformedCarData as Array<{ [key: string]: any }>;
32
+
33
+ const allKeys = new Set<string>();
34
+ for (const car of data) {
35
+ for (const key of Object.keys(car)) {
36
+ allKeys.add(key);
37
+ }
38
+ }
39
+
40
+ const normalizedData = await Promise.all(data.map(async car => {
41
+ const normalizedCar: { [key: string]: any } = { ...car };
42
+ for (const key of allKeys) {
43
+ if (!(key in normalizedCar)) {
44
+ normalizedCar[key] = "";
45
+ }
46
+ }
47
+ return normalizedCar;
48
+ }));
49
+
50
+ return normalizedData;
51
+ }
52
+
53
+ }