@bytebrand/export-cars 1.22.28 → 1.22.29

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.28",
3
+ "version": "1.22.29",
4
4
  "description": "",
5
5
  "author": "bytebrand",
6
6
  "license": "UNLICENSED",
@@ -33,6 +33,7 @@ export class Config {
33
33
  mappingSpreadsheetTitle: string;
34
34
  dealersSpreadsheetId: string;
35
35
  dealersSpreadsheetTitle: string;
36
+ metaPushPrioritySpreadsheetId: string;
36
37
 
37
38
  protected environmentConfig = {
38
39
  [Environment.DEVELOP]: {
@@ -65,6 +66,7 @@ export class Config {
65
66
  this.mappingSpreadsheetId = '147qz9sTgs1wi13ua8YKa0IgfxAn1X_qH6LkGnAnzeyY';
66
67
  this.dealersSpreadsheetId = '1gWrcA-uRTpna1h66Mbe2Y7NA0tIhlUaQXBcS4a_UzOw';
67
68
  this.dealersSpreadsheetTitle = 'dealers_mapping';
69
+ this.metaPushPrioritySpreadsheetId = params.metaPushPrioritySpreadsheetId;
68
70
  this.userActionsUrl = `https://www.${this.domain}/service/user-actions`;
69
71
  this.imboUrl = `https://www.${this.domain}/service/image-imbo`;
70
72
  this.imageUrl = `https://images.${this.domain}`;
@@ -5,3 +5,5 @@ export const DEFAULT_ZIP = '06796';
5
5
  export const DEFAULT_CITY = 'Sandersdorf-Brehna';
6
6
  export const DEFAULT_ADDR1 = 'Max-Planck-Str. 19';
7
7
  export const TIMESTAMP_FIRST_YEAR = 1970;
8
+ export const META_PUSH_PRIORITY_STANDARD = 'standard';
9
+ export const META_PUSH_PRIORITY_ALLOWED_VALUES = ['user_priority_1', 'user_priority_2'];
@@ -5,3 +5,9 @@ export interface DealersMapping {
5
5
  combinationId: string;
6
6
  aos24Id?: string;
7
7
  }
8
+
9
+ export interface MetaPushPriorityMapping {
10
+ user_id: string;
11
+ meta_push_priority: string;
12
+ comment?: string;
13
+ }
@@ -10,4 +10,5 @@ export interface Params {
10
10
  isNewCar?: boolean;
11
11
  cpc?: string;
12
12
  ownerId?: string;
13
+ metaPushPrioritySpreadsheetId?: string;
13
14
  }
@@ -2,13 +2,14 @@ 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
+ import { DealersMapping, MetaPushPriorityMapping } from '../interfaces/dealers-mapping.interface';
6
6
 
7
7
  @Injectable()
8
8
  export class MappingService {
9
9
  constructor(private configService: ConfigService) {}
10
10
  private rules: MappingRules[];
11
11
  private dealers: any;
12
+ private metaPushPriorities: MetaPushPriorityMapping[];
12
13
 
13
14
  async getRules(): Promise<MappingRules[]> {
14
15
  if (!this.rules) {
@@ -41,7 +42,23 @@ export class MappingService {
41
42
  return this.dealers;
42
43
  }
43
44
 
44
- private rowsToRules(rows: GoogleSpreadsheetRow[]): MappingRules[] | DealersMapping[] {
45
+ async getMetaPushPriorityMapping(): Promise<MetaPushPriorityMapping[]> {
46
+ if (!this.metaPushPriorities) {
47
+ const spreadsheetId = this.configService.config.metaPushPrioritySpreadsheetId;
48
+ if (!spreadsheetId) {
49
+ this.metaPushPriorities = [];
50
+ return this.metaPushPriorities;
51
+ }
52
+ const spreadsheet = new GoogleSpreadsheet(spreadsheetId);
53
+ spreadsheet.useApiKey(this.configService.config.apikey);
54
+ await spreadsheet.loadInfo();
55
+ const rows = await spreadsheet.sheetsByIndex[0].getRows();
56
+ this.metaPushPriorities = this.rowsToRules(rows) as MetaPushPriorityMapping[];
57
+ }
58
+ return this.metaPushPriorities;
59
+ }
60
+
61
+ private rowsToRules(rows: GoogleSpreadsheetRow[]): MappingRules[] | DealersMapping[] | MetaPushPriorityMapping[] {
45
62
  return rows.map(row =>
46
63
  Object.assign(
47
64
  {},
@@ -28,7 +28,7 @@ import { DataSchemes } from '@bytebrand/car-schema';
28
28
 
29
29
  import { Description } from '../interfaces/description.interface';
30
30
  import { FbDescription } from './fb-description.transformer';
31
- import { ConfigService, ImagesService } from '../services';
31
+ import { ConfigService, ImagesService, MappingService } from '../services';
32
32
  import { FbEquipment } from './fb-equipment.transformer';
33
33
  import { isValidVin } from '../utils';
34
34
  import { UserService } from 'src/services';
@@ -39,6 +39,8 @@ import {
39
39
  DEFAULT_ZIP,
40
40
  FB_MAX_TRIM_LENGTH,
41
41
  FB_MIN_MILEAGES,
42
+ META_PUSH_PRIORITY_ALLOWED_VALUES,
43
+ META_PUSH_PRIORITY_STANDARD,
42
44
  TIMESTAMP_FIRST_YEAR,
43
45
  } from '../constants/fb.constants';
44
46
 
@@ -52,6 +54,7 @@ export class FbTransformer {
52
54
  @Inject(CACHE_MANAGER) private cacheManager: Cache,
53
55
  private readonly configService: ConfigService,
54
56
  private readonly userService: UserService,
57
+ private readonly mappingService: MappingService,
55
58
  ) {
56
59
  this.imagesService = new ImagesService(configService, userService);
57
60
  const dict = { ...de, ...deVehicleProps, ...deVehicleDetailsPage };
@@ -70,6 +73,7 @@ export class FbTransformer {
70
73
  }): Promise<unknown> {
71
74
  const autodeId = toString(get(car, '_id', ''));
72
75
  const year = this.getYear(car);
76
+ const ownerId = get(car, 'metaData.ownerId', null);
73
77
  const dealerInfo = this.getDealerItems(car);
74
78
  // console.time(`Address ${car._id}`);
75
79
  const address = await this.getAddress(car, owner);
@@ -82,6 +86,8 @@ export class FbTransformer {
82
86
  fb_page_id: '176306386132',
83
87
  ...address,
84
88
  ...dealerInfo,
89
+ user_id: ownerId,
90
+ custom_label_4: await this.getMetaPushPriority(ownerId),
85
91
  vehicle_id: get(car, 'metaData.vehicleId', autodeId),
86
92
  stock_number: autodeId,
87
93
  availability: this.mapAvailability(car),
@@ -158,6 +164,13 @@ export class FbTransformer {
158
164
  );
159
165
  }
160
166
 
167
+ private async getMetaPushPriority(ownerId: string): Promise<string> {
168
+ const priorities = await this.mappingService.getMetaPushPriorityMapping();
169
+ const entry = priorities.find(priority => priority.user_id === ownerId);
170
+ const value = get(entry, 'meta_push_priority', '');
171
+ return includes(META_PUSH_PRIORITY_ALLOWED_VALUES, value) ? value : META_PUSH_PRIORITY_STANDARD;
172
+ }
173
+
161
174
  private getDealerItems(car: DataSchemes.Car): {
162
175
  dealer_communication_channel: string;
163
176
  dealer_id: unknown;