@bytebrand/export-cars 1.21.12 → 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/.eslintrc.js +8 -1
- package/dist/exporters/santander.exporter.js +5 -4
- package/dist/exporters/santander.exporter.js.map +1 -1
- package/dist/transformers/santander.transformer.d.ts +7 -0
- package/dist/transformers/santander.transformer.js +50 -0
- package/dist/transformers/santander.transformer.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/exporters/santander.exporter.ts +6 -3
- package/src/transformers/santander.transformer.ts +53 -0
package/package.json
CHANGED
|
@@ -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
|
|
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
|
|
39
|
+
const transformedData = await santanderTransformer.transform(car, images);
|
|
39
40
|
|
|
40
|
-
await
|
|
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
|
}
|
|
@@ -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
|
+
}
|