@bytebrand/export-cars 1.0.14 → 1.0.15

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.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "",
5
5
  "author": "bytebrand",
6
6
  "license": "UNLICENSED",
@@ -17,7 +17,7 @@
17
17
  "@bytebrand/autode-request": "^1.5.13",
18
18
  "@bytebrand/car-basic-data-scope": "~7.1.11",
19
19
  "@bytebrand/car-description": "^1.2.24",
20
- "@bytebrand/car-schema": "^3.9.12",
20
+ "@bytebrand/car-schema": "^3.12.24",
21
21
  "@bytebrand/chunkable": "^5.4.4",
22
22
  "@bytebrand/cronicle-helper": "^1.7.4",
23
23
  "@bytebrand/fe-financing": "^5.3.1",
@@ -64,5 +64,5 @@
64
64
  "engines": {
65
65
  "node": ">=14.0.0"
66
66
  },
67
- "gitHead": "096d9d9ff57b54b5fe3ac91597e463cd657f1a69"
67
+ "gitHead": "6159441288cbd0bafd0e3c3a3b2d99e9fea1fdbc"
68
68
  }
@@ -35,6 +35,8 @@ export class Config {
35
35
  googleSheetsApiKey: string;
36
36
  mappingSpreadsheetId: string;
37
37
  mappingSpreadsheetTitle: string;
38
+ dealersSpreadsheetId: string;
39
+ dealersSpreadsheetTitle: string;
38
40
 
39
41
  protected environmentConfig = {
40
42
  [Environment.LOCAL]: {
@@ -73,6 +75,8 @@ export class Config {
73
75
  this.url = this.environmentConfig[params.environment].url;
74
76
  this.googleSheetsApiKey = params.googleSheetsApiKey;
75
77
  this.mappingSpreadsheetId = '147qz9sTgs1wi13ua8YKa0IgfxAn1X_qH6LkGnAnzeyY';
78
+ this.dealersSpreadsheetId = '1gWrcA-uRTpna1h66Mbe2Y7NA0tIhlUaQXBcS4a_UzOw';
79
+ this.dealersSpreadsheetTitle = 'dealers_mapping';
76
80
  this.userActionsUrl = `https://www.${this.url}/service/user-actions`;
77
81
  this.imboUrl = `https://www.${this.url}/service/image-imbo`;
78
82
  this.imageUrl = `https://images.${this.url}`;
@@ -13,10 +13,8 @@ import { Injectable } from '@nestjs/common';
13
13
  import { ModuleRef } from '@nestjs/core';
14
14
  import { HttpService } from '@nestjs/axios';
15
15
  import { lastValueFrom } from 'rxjs';
16
- import { createWriteStream } from 'fs';
17
16
  import { get } from 'lodash';
18
17
  import { RulesService } from '../services/rules.service';
19
- import { pipeline } from 'stream/promises';
20
18
 
21
19
  @Injectable()
22
20
  export class MobileExporter implements Exporter {
@@ -0,0 +1,7 @@
1
+ export interface DealersMapping {
2
+ firebaseUserId: string;
3
+ dealerId: string;
4
+ dealerEmail: string;
5
+ combinationId: string;
6
+ aos24Id?: string;
7
+ }
@@ -11,7 +11,6 @@ export interface Params {
11
11
  Date?: string;
12
12
  isNewCar?: boolean;
13
13
  isCriteo?: boolean;
14
- fileXML?: string;
15
14
  dealers?: string;
16
15
  cpc?: string;
17
16
  ownerId?: string;
@@ -2,11 +2,13 @@ import { Injectable } from '@nestjs/common';
2
2
  import { MappingRules } from '../interfaces/mapping-rules.interface';
3
3
  import { GoogleSpreadsheet, GoogleSpreadsheetRow } from 'google-spreadsheet';
4
4
  import { ConfigService } from './config.service';
5
+ import { DealersMapping } from '../interfaces/dealers-mapping.interface';
5
6
 
6
7
  @Injectable()
7
8
  export class MappingService {
8
9
  constructor(private configService: ConfigService) {}
9
10
  private rules: MappingRules[];
11
+ private dealers: any;
10
12
 
11
13
  async getRules(): Promise<MappingRules[]> {
12
14
  if (!this.rules) {
@@ -14,7 +16,7 @@ export class MappingService {
14
16
  spreadsheet.useApiKey(this.configService.config.googleSheetsApiKey);
15
17
  await spreadsheet.loadInfo();
16
18
  const rows = await spreadsheet.sheetsByTitle[this.configService.config.mappingSpreadsheetTitle].getRows();
17
- const mappingRules = this.rowsToRules(rows);
19
+ const mappingRules = this.rowsToRules(rows) as MappingRules[];
18
20
 
19
21
  mappingRules.map((rule, _i, selfRules) => {
20
22
  this.removeEmptyKeys(rule);
@@ -28,7 +30,18 @@ export class MappingService {
28
30
  return this.rules;
29
31
  }
30
32
 
31
- private rowsToRules(rows: GoogleSpreadsheetRow[]): MappingRules[] {
33
+ async getDealersMapping(): Promise<DealersMapping[]> {
34
+ if (!this.dealers) {
35
+ const spreadsheet = new GoogleSpreadsheet(this.configService.config.dealersSpreadsheetId);
36
+ spreadsheet.useApiKey(this.configService.config.googleSheetsApiKey);
37
+ await spreadsheet.loadInfo();
38
+ const rows = await spreadsheet.sheetsByTitle[this.configService.config.dealersSpreadsheetTitle].getRows();
39
+ this.dealers = this.rowsToRules(rows) as DealersMapping[];
40
+ }
41
+ return this.dealers;
42
+ }
43
+
44
+ private rowsToRules(rows: GoogleSpreadsheetRow[]): MappingRules[] | DealersMapping[] {
32
45
  return rows.map(row =>
33
46
  Object.assign(
34
47
  {},
@@ -51,6 +51,10 @@ export class MobileTransformer {
51
51
  set(transformedCarData, 293, toString(get(carData, 'leasing.monthlyInstallment', '')));
52
52
  set(transformedCarData, 1, get(carData, 'metaData.vehicleId', null));
53
53
 
54
+ if (this.configService.config.campaign === 'eauto' && carData.offer.ftpFolder === 'auto_de_eautos') {
55
+ set(transformedCarData, 12, get(carData, 'offer.internalNumber', null));
56
+ }
57
+
54
58
  return transformedCarData;
55
59
  }
56
60
 
@@ -128,7 +132,7 @@ export class MobileTransformer {
128
132
  return this.getAutodeUrl(car);
129
133
  }
130
134
  case 'persistentId': {
131
- return this.getPersistentId();
135
+ return this.getPersistentId(car);
132
136
  }
133
137
  case 'price.vatDeductible': {
134
138
  return this.getVatDeductible(car);
@@ -174,9 +178,16 @@ export class MobileTransformer {
174
178
  }
175
179
  }
176
180
 
177
- private getPersistentId() {
181
+ private async getPersistentId(car: DataSchemes.Car) {
178
182
  switch (this.configService.config.campaign) {
179
183
  case 'eauto':
184
+ if (car.offer.ftpFolder === 'auto_de_eautos') {
185
+ const dealers = await this.mappingService.getDealersMapping();
186
+ const dealerId = dealers.find(dealer => dealer.firebaseUserId === car.metaData.ownerId)?.dealerId;
187
+ if (dealerId) {
188
+ return dealerId;
189
+ }
190
+ }
180
191
  return '416';
181
192
  default:
182
193
  return '04109003';