@bytebrand/export-cars 1.5.2 → 1.6.1

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.
Files changed (215) hide show
  1. package/dist/{config → configs}/alleskralle.config.js +3 -5
  2. package/dist/configs/alleskralle.config.js.map +1 -0
  3. package/dist/{config → configs}/as24.config.js +3 -1
  4. package/dist/configs/as24.config.js.map +1 -0
  5. package/dist/{config → configs}/auto24.config.js +3 -3
  6. package/dist/configs/auto24.config.js.map +1 -0
  7. package/dist/configs/autoboerse.config.js +16 -0
  8. package/dist/configs/autoboerse.config.js.map +1 -0
  9. package/dist/{config → configs}/autouncle.config.js +3 -2
  10. package/dist/configs/autouncle.config.js.map +1 -0
  11. package/dist/{config → configs}/by-owner.config.js +2 -2
  12. package/dist/configs/by-owner.config.js.map +1 -0
  13. package/dist/{config → configs}/config.d.ts +8 -12
  14. package/dist/{config → configs}/config.js +14 -20
  15. package/dist/configs/config.js.map +1 -0
  16. package/dist/configs/criteo.config.js +16 -0
  17. package/dist/configs/criteo.config.js.map +1 -0
  18. package/dist/{config → configs}/dasparking.config.js +3 -5
  19. package/dist/configs/dasparking.config.js.map +1 -0
  20. package/dist/{config → configs}/eauto.config.js +4 -3
  21. package/dist/configs/eauto.config.js.map +1 -0
  22. package/dist/{config → configs}/fb.config.js +3 -2
  23. package/dist/configs/fb.config.js.map +1 -0
  24. package/dist/{config → configs}/google.config.js +3 -2
  25. package/dist/configs/google.config.js.map +1 -0
  26. package/dist/configs/index.d.ts +16 -0
  27. package/dist/configs/index.js +33 -0
  28. package/dist/configs/index.js.map +1 -0
  29. package/dist/{config/kleinanzeigeFocus.config.js → configs/kleinanzeigefocus.config.js} +3 -4
  30. package/dist/configs/kleinanzeigefocus.config.js.map +1 -0
  31. package/dist/{config → configs}/marktde.config.js +4 -3
  32. package/dist/configs/marktde.config.js.map +1 -0
  33. package/dist/{config → configs}/meinstadt.config.js +4 -4
  34. package/dist/configs/meinstadt.config.js.map +1 -0
  35. package/dist/{config → configs}/ooyyo.config.js +3 -4
  36. package/dist/configs/ooyyo.config.js.map +1 -0
  37. package/dist/{config → configs}/yescar.config.js +4 -3
  38. package/dist/configs/yescar.config.js.map +1 -0
  39. package/dist/enums/export-type.enum.d.ts +0 -1
  40. package/dist/enums/export-type.enum.js +0 -1
  41. package/dist/enums/export-type.enum.js.map +1 -1
  42. package/dist/enums/file-types.enum.d.ts +7 -7
  43. package/dist/enums/file-types.enum.js +11 -10
  44. package/dist/enums/file-types.enum.js.map +1 -1
  45. package/dist/export.schema.d.ts +4 -33
  46. package/dist/export.schema.js +32 -61
  47. package/dist/export.schema.js.map +1 -1
  48. package/dist/exporters/as24.exporter.d.ts +3 -5
  49. package/dist/exporters/as24.exporter.js +20 -22
  50. package/dist/exporters/as24.exporter.js.map +1 -1
  51. package/dist/exporters/auto24.exporter.d.ts +1 -1
  52. package/dist/exporters/auto24.exporter.js +8 -17
  53. package/dist/exporters/auto24.exporter.js.map +1 -1
  54. package/dist/exporters/autouncle.exporter.d.ts +3 -5
  55. package/dist/exporters/autouncle.exporter.js +19 -35
  56. package/dist/exporters/autouncle.exporter.js.map +1 -1
  57. package/dist/exporters/by-owner.exporter.d.ts +2 -3
  58. package/dist/exporters/by-owner.exporter.js +4 -7
  59. package/dist/exporters/by-owner.exporter.js.map +1 -1
  60. package/dist/exporters/fb.exporter.d.ts +2 -3
  61. package/dist/exporters/fb.exporter.js +10 -16
  62. package/dist/exporters/fb.exporter.js.map +1 -1
  63. package/dist/exporters/google.exporter.d.ts +3 -4
  64. package/dist/exporters/google.exporter.js +13 -19
  65. package/dist/exporters/google.exporter.js.map +1 -1
  66. package/dist/exporters/index.d.ts +10 -1
  67. package/dist/exporters/index.js +10 -1
  68. package/dist/exporters/index.js.map +1 -1
  69. package/dist/exporters/meinstadt.exporter.d.ts +1 -1
  70. package/dist/exporters/meinstadt.exporter.js +18 -34
  71. package/dist/exporters/meinstadt.exporter.js.map +1 -1
  72. package/dist/exporters/mobile.exporter.d.ts +2 -5
  73. package/dist/exporters/mobile.exporter.js +14 -44
  74. package/dist/exporters/mobile.exporter.js.map +1 -1
  75. package/dist/exporters/modix.exporter.d.ts +2 -2
  76. package/dist/exporters/modix.exporter.js +7 -11
  77. package/dist/exporters/modix.exporter.js.map +1 -1
  78. package/dist/exporters/ooyyo.exporter.js +6 -9
  79. package/dist/exporters/ooyyo.exporter.js.map +1 -1
  80. package/dist/exporters/rubrikk.exporter.js +8 -14
  81. package/dist/exporters/rubrikk.exporter.js.map +1 -1
  82. package/dist/main.js +1 -1
  83. package/dist/main.js.map +1 -1
  84. package/dist/services/car.service.js +1 -4
  85. package/dist/services/car.service.js.map +1 -1
  86. package/dist/services/config.service.d.ts +1 -1
  87. package/dist/services/user.service.d.ts +0 -2
  88. package/dist/services/user.service.js +0 -3
  89. package/dist/services/user.service.js.map +1 -1
  90. package/dist/transformers/as24.transformer.d.ts +4 -2
  91. package/dist/transformers/as24.transformer.js +25 -3
  92. package/dist/transformers/as24.transformer.js.map +1 -1
  93. package/dist/transformers/auto24.transfomer.js +1 -1
  94. package/dist/transformers/auto24.transfomer.js.map +1 -1
  95. package/dist/transformers/autouncle.transformer.js +1 -1
  96. package/dist/transformers/autouncle.transformer.js.map +1 -1
  97. package/dist/transformers/fb.transformer.js +2 -2
  98. package/dist/transformers/fb.transformer.js.map +1 -1
  99. package/dist/transformers/google.transformer.js +3 -3
  100. package/dist/transformers/google.transformer.js.map +1 -1
  101. package/dist/transformers/meinstadt.transformer.js +1 -1
  102. package/dist/transformers/meinstadt.transformer.js.map +1 -1
  103. package/dist/transformers/mobile.transformer.js +1 -1
  104. package/dist/transformers/mobile.transformer.js.map +1 -1
  105. package/dist/transformers/modix.transformer.d.ts +1 -3
  106. package/dist/transformers/modix.transformer.js +4 -12
  107. package/dist/transformers/modix.transformer.js.map +1 -1
  108. package/dist/transformers/ooyyo.transformer.js +2 -2
  109. package/dist/transformers/ooyyo.transformer.js.map +1 -1
  110. package/dist/transformers/rubrikk.transformer.js +1 -1
  111. package/dist/transformers/rubrikk.transformer.js.map +1 -1
  112. package/dist/tsconfig.build.tsbuildinfo +1 -1
  113. package/package.json +11 -11
  114. package/src/configs/alleskralle.config.ts +12 -0
  115. package/src/{config → configs}/as24.config.ts +3 -1
  116. package/src/configs/auto24.config.ts +12 -0
  117. package/src/configs/autoboerse.config.ts +13 -0
  118. package/src/configs/autouncle.config.ts +11 -0
  119. package/src/configs/by-owner.config.ts +13 -0
  120. package/src/{config → configs}/config.ts +14 -21
  121. package/src/configs/criteo.config.ts +13 -0
  122. package/src/configs/dasparking.config.ts +12 -0
  123. package/src/{config → configs}/eauto.config.ts +4 -3
  124. package/src/{config → configs}/fb.config.ts +3 -2
  125. package/src/configs/google.config.ts +11 -0
  126. package/src/configs/index.ts +16 -0
  127. package/src/{config → configs}/kleinanzeigeFocus.config.ts +3 -4
  128. package/src/{config → configs}/marktde.config.ts +4 -3
  129. package/src/configs/meinstadt.config.ts +14 -0
  130. package/src/configs/ooyyo.config.ts +14 -0
  131. package/src/configs/yescar.config.ts +16 -0
  132. package/src/enums/export-type.enum.ts +12 -1
  133. package/src/enums/file-types.enum.ts +8 -8
  134. package/src/export.schema.ts +35 -33
  135. package/src/exporters/as24.exporter.ts +27 -30
  136. package/src/exporters/auto24.exporter.ts +15 -23
  137. package/src/exporters/autouncle.exporter.ts +27 -38
  138. package/src/exporters/by-owner.exporter.ts +7 -5
  139. package/src/exporters/fb.exporter.ts +11 -13
  140. package/src/exporters/google.exporter.ts +16 -17
  141. package/src/exporters/index.ts +10 -1
  142. package/src/exporters/meinstadt.exporter.ts +24 -41
  143. package/src/exporters/mobile.exporter.ts +21 -63
  144. package/src/exporters/modix.exporter.ts +15 -14
  145. package/src/exporters/ooyyo.exporter.ts +10 -11
  146. package/src/exporters/rubrikk.exporter.ts +11 -16
  147. package/src/main.ts +1 -1
  148. package/src/services/car.service.ts +3 -5
  149. package/src/services/config.service.ts +1 -1
  150. package/src/services/user.service.ts +1 -5
  151. package/src/transformers/as24.transformer.ts +29 -5
  152. package/src/transformers/auto24.transfomer.ts +1 -1
  153. package/src/transformers/autouncle.transformer.ts +1 -1
  154. package/src/transformers/fb.transformer.ts +2 -2
  155. package/src/transformers/google.transformer.ts +3 -3
  156. package/src/transformers/meinstadt.transformer.ts +1 -1
  157. package/src/transformers/mobile.transformer.ts +1 -1
  158. package/src/transformers/modix.transformer.ts +8 -17
  159. package/src/transformers/ooyyo.transformer.ts +2 -2
  160. package/src/transformers/rubrikk.transformer.ts +1 -1
  161. package/tsconfig.json +5 -3
  162. package/dist/config/alleskralle.config.js.map +0 -1
  163. package/dist/config/as24.config.js.map +0 -1
  164. package/dist/config/auto24.config.js.map +0 -1
  165. package/dist/config/autoboerse.config.js +0 -16
  166. package/dist/config/autoboerse.config.js.map +0 -1
  167. package/dist/config/autoborse.config.d.ts +0 -5
  168. package/dist/config/autoborse.config.js +0 -15
  169. package/dist/config/autoborse.config.js.map +0 -1
  170. package/dist/config/autouncle.config.js.map +0 -1
  171. package/dist/config/by-owner.config.js.map +0 -1
  172. package/dist/config/config.js.map +0 -1
  173. package/dist/config/criteo.config.js +0 -14
  174. package/dist/config/criteo.config.js.map +0 -1
  175. package/dist/config/dasparking.config.js.map +0 -1
  176. package/dist/config/eauto.config.js.map +0 -1
  177. package/dist/config/fb.config.js.map +0 -1
  178. package/dist/config/google.config.js.map +0 -1
  179. package/dist/config/index.d.ts +0 -1
  180. package/dist/config/index.js +0 -18
  181. package/dist/config/index.js.map +0 -1
  182. package/dist/config/kleinanzeigeFocus.config.js.map +0 -1
  183. package/dist/config/marktde.config.js.map +0 -1
  184. package/dist/config/meinstadt.config.js.map +0 -1
  185. package/dist/config/ooyyo.config.js.map +0 -1
  186. package/dist/config/yescar.config.js.map +0 -1
  187. package/src/config/alleskralle.config.ts +0 -14
  188. package/src/config/auto24.config.ts +0 -12
  189. package/src/config/autoboerse.config.ts +0 -13
  190. package/src/config/autoborse.config.ts +0 -12
  191. package/src/config/autouncle.config.ts +0 -10
  192. package/src/config/by-owner.config.ts +0 -10
  193. package/src/config/criteo.config.ts +0 -11
  194. package/src/config/dasparking.config.ts +0 -14
  195. package/src/config/google.config.ts +0 -10
  196. package/src/config/index.ts +0 -1
  197. package/src/config/meinstadt.config.ts +0 -15
  198. package/src/config/ooyyo.config.ts +0 -15
  199. package/src/config/yescar.config.ts +0 -12
  200. /package/dist/{config → configs}/alleskralle.config.d.ts +0 -0
  201. /package/dist/{config → configs}/as24.config.d.ts +0 -0
  202. /package/dist/{config → configs}/auto24.config.d.ts +0 -0
  203. /package/dist/{config → configs}/autoboerse.config.d.ts +0 -0
  204. /package/dist/{config → configs}/autouncle.config.d.ts +0 -0
  205. /package/dist/{config → configs}/by-owner.config.d.ts +0 -0
  206. /package/dist/{config → configs}/criteo.config.d.ts +0 -0
  207. /package/dist/{config → configs}/dasparking.config.d.ts +0 -0
  208. /package/dist/{config → configs}/eauto.config.d.ts +0 -0
  209. /package/dist/{config → configs}/fb.config.d.ts +0 -0
  210. /package/dist/{config → configs}/google.config.d.ts +0 -0
  211. /package/dist/{config/kleinanzeigeFocus.config.d.ts → configs/kleinanzeigefocus.config.d.ts} +0 -0
  212. /package/dist/{config → configs}/marktde.config.d.ts +0 -0
  213. /package/dist/{config → configs}/meinstadt.config.d.ts +0 -0
  214. /package/dist/{config → configs}/ooyyo.config.d.ts +0 -0
  215. /package/dist/{config → configs}/yescar.config.d.ts +0 -0
@@ -1,14 +1,15 @@
1
1
  import { Injectable } from '@nestjs/common';
2
- import { CarService, RulesService, ConfigService, LoaderService } from '../services';
3
- import { FsChunkInterface } from '@bytebrand/chunkable';
4
- import { Exporter } from '../interfaces/exporter.interface';
5
- import { CronicleUtils } from '@bytebrand/cronicle-helper';
6
- import { toNumber } from 'lodash';
7
2
  import { ModuleRef } from '@nestjs/core';
8
- import { Auto24XmlBuilder } from '../formats/auto24-xml.builder';
9
- import { Auto24Transformer } from '../transformers/auto24.transfomer';
3
+
4
+ import { CronicleUtils } from '@bytebrand/cronicle-helper';
5
+ import { FsChunkInterface } from '@bytebrand/chunkable';
10
6
  import { Zipper } from '@bytebrand/zipper';
11
7
 
8
+ import { CarService, RulesService, ConfigService, LoaderService } from '../services';
9
+ import { Auto24Transformer } from '../transformers/auto24.transfomer';
10
+ import { Auto24XmlBuilder } from '../formats/auto24-xml.builder';
11
+ import { Exporter } from '../interfaces/exporter.interface';
12
+
12
13
  @Injectable()
13
14
  export class Auto24Exporter implements Exporter {
14
15
  constructor(
@@ -17,17 +18,14 @@ export class Auto24Exporter implements Exporter {
17
18
  private loaderService: LoaderService,
18
19
  private moduleRef: ModuleRef,
19
20
  private rulesService: RulesService,
20
- ) {}
21
+ ) { }
21
22
 
22
23
  async export(): Promise<void> {
23
- for (const file of this.configService.config.outputFiles) {
24
- const exists = await CronicleUtils.exists(file);
25
- exists && (await CronicleUtils.unlink(file));
26
- }
27
-
28
24
  const [fileXml, fileGZ] = this.configService.config.outputFiles;
25
+ await Promise.all([await CronicleUtils.unlinkIfExists(fileXml), await CronicleUtils.unlinkIfExists(fileGZ)]);
29
26
 
30
27
  const xmlBuilder = new Auto24XmlBuilder(fileXml);
28
+ await xmlBuilder.buildStart();
31
29
 
32
30
  const auto24Transformer = await this.moduleRef.create(Auto24Transformer);
33
31
 
@@ -35,25 +33,19 @@ export class Auto24Exporter implements Exporter {
35
33
  const chunkData = chunk.data.filter(car => this.carService.filterCar(car, this.rulesService.rules));
36
34
 
37
35
  if (chunk && chunkData) {
38
- if (toNumber(chunk.id) === 0) {
39
- await xmlBuilder.buildStart(chunk.total);
40
- }
41
-
42
36
  for (let i = 0; i < chunk.data.length; i += 1) {
43
37
  const data = chunk.data[i];
44
38
  const { car, images } = data;
45
- await xmlBuilder.addItem(auto24Transformer.transform(car, images), this.configService.config.location);
39
+ await xmlBuilder.addItem(auto24Transformer.transform(car, images), 'Deutschland');
46
40
  this.carService.counter.countCar(images);
47
41
  }
48
- chunk.data = null;
42
+
49
43
  }
50
44
  });
51
45
 
52
46
  await xmlBuilder.buildEnd();
53
- console.log(this.carService.counter.getCountedCars());
54
47
 
55
- if (fileGZ) {
56
- await Zipper.tar({ dest: fileGZ, fileList: [fileXml] });
57
- }
48
+ fileGZ && await Zipper.tar({ dest: fileGZ, fileList: [fileXml] });
49
+ console.log(this.carService.counter.getCountedCars());
58
50
  }
59
51
  }
@@ -1,14 +1,15 @@
1
+ import { get } from 'lodash';
2
+
1
3
  import { Injectable } from '@nestjs/common';
2
- import { CarService, RulesService, ConfigService, LoaderService } from '../services';
3
- import { FsChunkInterface } from '@bytebrand/chunkable';
4
- import { Exporter } from '../interfaces/exporter.interface';
5
- import { CronicleUtils } from '@bytebrand/cronicle-helper';
6
4
  import { ModuleRef } from '@nestjs/core';
7
- import { AutouncleJsonBuilder } from '../formats/autouncle-json.builder';
5
+
6
+ import { CronicleUtils } from '@bytebrand/cronicle-helper';
7
+ import { FsChunkInterface } from '@bytebrand/chunkable';
8
+
8
9
  import { AutouncleTransformer } from '../transformers/autouncle.transformer';
9
- import { get, isNil } from 'lodash';
10
- import { ExportType, FileTypes } from '../enums';
11
- import { UserService } from '../services';
10
+ import { AutouncleJsonBuilder } from '../formats/autouncle-json.builder';
11
+ import { CarService, RulesService, LoaderService, ConfigService } from '../services';
12
+ import { Exporter } from '../interfaces/exporter.interface';
12
13
 
13
14
  @Injectable()
14
15
  export class AutouncleExporter implements Exporter {
@@ -18,47 +19,35 @@ export class AutouncleExporter implements Exporter {
18
19
  private loaderService: LoaderService,
19
20
  private rulesService: RulesService,
20
21
  private moduleRef: ModuleRef,
21
- private readonly userService: UserService,
22
- ) {}
22
+ ) { }
23
23
 
24
24
  async export(): Promise<void> {
25
- const fileName = this.userService.getFileName(ExportType.AUTOUNCLE, FileTypes.json);
26
-
27
- const exists = await CronicleUtils.exists(fileName);
28
- exists && (await CronicleUtils.unlink(fileName));
25
+ const [fileName] = this.configService.config.outputFiles;
26
+ await CronicleUtils.unlinkIfExists(fileName);
29
27
 
30
28
  const autouncleJsonBuilder = new AutouncleJsonBuilder(fileName);
31
- const autouncleTransformer = await this.moduleRef.create(AutouncleTransformer);
32
-
33
29
  await autouncleJsonBuilder.buildStart();
30
+
31
+ const autouncleTransformer = await this.moduleRef.create(AutouncleTransformer);
34
32
 
35
33
  let firstCar = true;
36
34
  await this.loaderService.process(async (chunk: FsChunkInterface) => {
37
- let chunkData;
38
- if (this.configService.config.isNewCar) {
39
- chunkData = chunk.data.filter(
40
- e => this.carService.filterCar(e, this.rulesService.rules) && this.carService.isCarNew(e),
41
- );
42
- } else {
43
- chunkData = chunk.data.filter(e => this.carService.filterCar(e, this.rulesService.rules));
44
- }
45
- chunk.data = null;
46
- for (const data of chunkData) {
47
- const ownerId = get(data.car, 'metaData.ownerId', null);
48
- if (!isNil(ownerId)) {
49
- const owner = await this.carService.getOwner(ownerId);
50
- if (owner) {
51
- const car = await autouncleTransformer.transform({ owner, ...data });
52
- await autouncleJsonBuilder.addItem(car, firstCar);
53
- this.carService.counter.countCar(data.images);
54
- }
55
- if (firstCar) {
56
- firstCar = false;
57
- }
58
- }
35
+ chunk.data = chunk.data.filter(e => this.carService.filterCar(e, this.rulesService.rules));
36
+
37
+ for (const data of chunk.data) {
38
+ const ownerId = get(data.car, 'metaData.ownerId');
39
+ const owner = await this.carService.getOwner(ownerId);
40
+ const car = await autouncleTransformer.transform({ owner, ...data });
41
+
42
+ await autouncleJsonBuilder.addItem(car, firstCar);
43
+
44
+ this.carService.counter.countCar(data.images);
45
+
46
+ if (firstCar) { firstCar = false; }
59
47
  }
60
48
  });
61
49
 
62
50
  await autouncleJsonBuilder.buildEnd();
51
+ console.log(this.carService.counter.getCountedCars());
63
52
  }
64
53
  }
@@ -1,4 +1,4 @@
1
- import { ConfigService, LoaderService, CarService, RulesService, UserService } from '../services';
1
+ import { ConfigService, LoaderService, CarService, RulesService } from '../services';
2
2
  import { FsChunkInterface } from '@bytebrand/chunkable';
3
3
  import { Exporter } from '../interfaces/exporter.interface';
4
4
  import { CronicleUtils } from '@bytebrand/cronicle-helper';
@@ -6,23 +6,24 @@ import { Injectable } from '@nestjs/common';
6
6
  import { ModuleRef } from '@nestjs/core';
7
7
  import { ByOwnerTransformer } from '../transformers/by-owner.transformer';
8
8
  import { createWriteStream } from 'fs';
9
- import { ExportType, FileTypes } from '../enums';
10
9
 
11
10
  const createCsvWriter = require('csv-write-stream');
12
11
 
12
+ /**
13
+ * @deprecated
14
+ */
13
15
  @Injectable()
14
16
  export class ByOwnerExporter implements Exporter {
15
17
  constructor(
16
18
  private configService: ConfigService,
17
19
  private loaderService: LoaderService,
18
20
  private moduleRef: ModuleRef,
19
- private userService: UserService,
20
21
  private carService: CarService,
21
22
  private rulesService: RulesService,
22
23
  ) {}
23
24
 
24
25
  async export(): Promise<void> {
25
- const fileName = this.userService.getFileName(ExportType.BY_OWNER, FileTypes.csv);
26
+ const [fileName] = this.configService.config.outputFiles;
26
27
 
27
28
  await CronicleUtils.unlinkIfExists(fileName);
28
29
 
@@ -37,6 +38,7 @@ export class ByOwnerExporter implements Exporter {
37
38
  chunk.data = null;
38
39
  });
39
40
 
40
- csvWriter.end();
41
+ await csvWriter.end();
42
+ console.log(this.carService.counter.getCountedCars());
41
43
  }
42
44
  }
@@ -7,7 +7,6 @@ import { get } from 'lodash';
7
7
  import { FbXmlBuilder } from '../formats/fb-xml.builder';
8
8
  import { ModuleRef } from '@nestjs/core';
9
9
  import { FbTransformer } from '../transformers/fb.transformer';
10
- import { ExportType, FileTypes } from '../enums';
11
10
  import { FbXmlItem } from '../interfaces';
12
11
 
13
12
  @Injectable()
@@ -18,18 +17,17 @@ export class FbExporter implements Exporter {
18
17
  private rulesService: RulesService,
19
18
  private loaderService: LoaderService,
20
19
  private moduleRef: ModuleRef,
21
- private userService: UserService,
22
- ) {}
20
+ ) { }
23
21
 
24
22
  async export(): Promise<void> {
25
- const fileName = this.userService.getFileName(ExportType.FB, FileTypes.xml);
23
+ const [fileName] = this.configService.config.outputFiles;
24
+ await CronicleUtils.unlinkIfExists(fileName);
26
25
 
27
- const exists = await CronicleUtils.exists(fileName);
28
- exists && (await CronicleUtils.unlink(fileName));
29
26
 
30
- const fbTransformer = await this.moduleRef.create(FbTransformer);
31
27
  const fbXmlBuilder = new FbXmlBuilder(fileName);
32
- await fbXmlBuilder.buildStart(this.configService.config.url);
28
+ await fbXmlBuilder.buildStart(this.configService.config.domain);
29
+
30
+ const fbTransformer = await this.moduleRef.create(FbTransformer);
33
31
 
34
32
  await this.loaderService.process(async (chunk: FsChunkInterface) => {
35
33
  const chunkData = chunk.data.filter(car => this.carService.filterCar(car, this.rulesService.rules));
@@ -37,14 +35,14 @@ export class FbExporter implements Exporter {
37
35
  for (const data of chunkData) {
38
36
  const ownerId = get(data.car, 'metaData.ownerId', null);
39
37
  const owner = await this.carService.getOwner(ownerId);
40
- if (owner) {
41
- const car = await fbTransformer.transform({ owner, ...data });
42
- await fbXmlBuilder.addItem(car as FbXmlItem);
43
- this.carService.counter.countCar(data.images);
44
- }
38
+ const car = await fbTransformer.transform({ owner, ...data });
39
+
40
+ await fbXmlBuilder.addItem(car as FbXmlItem);
41
+ this.carService.counter.countCar(data.images);
45
42
  }
46
43
  });
47
44
 
48
45
  await fbXmlBuilder.buildEnd();
46
+ console.log(this.carService.counter.getCountedCars());
49
47
  }
50
48
  }
@@ -1,12 +1,13 @@
1
1
  import { Injectable } from '@nestjs/common';
2
- import { CarService, ConfigService, LoaderService, RulesService, UserService } from '../services';
3
- import { FsChunkInterface } from '@bytebrand/chunkable';
4
- import { Exporter } from '../interfaces/exporter.interface';
2
+ import { ModuleRef } from '@nestjs/core';
3
+
5
4
  import { CronicleUtils } from '@bytebrand/cronicle-helper';
6
- import { GoogleXmlBuilder } from '../formats/google-xml.builder';
5
+ import { FsChunkInterface } from '@bytebrand/chunkable';
6
+
7
+ import { CarService, ConfigService, LoaderService, RulesService } from '../services';
7
8
  import { GoogleTransformer } from '../transformers/google.transformer';
8
- import { ModuleRef } from '@nestjs/core';
9
- import { ExportType, FileTypes } from '../enums';
9
+ import { GoogleXmlBuilder } from '../formats/google-xml.builder';
10
+ import { Exporter } from '../interfaces/exporter.interface';
10
11
 
11
12
  @Injectable()
12
13
  export class GoogleExporter implements Exporter {
@@ -16,30 +17,28 @@ export class GoogleExporter implements Exporter {
16
17
  private rulesService: RulesService,
17
18
  private loaderService: LoaderService,
18
19
  private moduleRef: ModuleRef,
19
- private userService: UserService,
20
20
  ) {}
21
21
 
22
22
  async export(): Promise<void> {
23
- const exportType = this.configService.config.isCriteo ? ExportType.CRITEO : ExportType.GOOGLE;
24
- const fileName = this.userService.getFileName(exportType, FileTypes.xml);
23
+ const [fileName] = this.configService.config.outputFiles;
24
+ await CronicleUtils.unlinkIfExists(fileName);
25
25
 
26
- const exists = await CronicleUtils.exists(fileName);
27
- exists && (await CronicleUtils.unlink(fileName));
26
+ const googleXmlBuilder = new GoogleXmlBuilder(fileName);
27
+ await googleXmlBuilder.buildStart(this.configService.config.domain);
28
28
 
29
29
  const googleTransformer = await this.moduleRef.create(GoogleTransformer);
30
- const googleXmlBuilder = new GoogleXmlBuilder(fileName);
31
- await googleXmlBuilder.buildStart(this.configService.config.url);
32
30
 
33
31
  await this.loaderService.process(async (chunk: FsChunkInterface) => {
34
- const chunkData = chunk.data.filter(car => this.carService.filterCar(car, this.rulesService.rules));
35
- chunk.data = null;
36
- for (const data of chunkData) {
37
- const car = await googleTransformer.transform({ ...data });
32
+ chunk.data = chunk.data.filter(car => this.carService.filterCar(car, this.rulesService.rules));
33
+
34
+ for (const data of chunk.data) {
35
+ const car = await googleTransformer.transform(data);
38
36
  await googleXmlBuilder.addItem(car);
39
37
  this.carService.counter.countCar(data.images);
40
38
  }
41
39
  });
42
40
 
43
41
  await googleXmlBuilder.buildEnd();
42
+ console.log(this.carService.counter.getCountedCars());
44
43
  }
45
44
  }
@@ -1,2 +1,11 @@
1
- export * from './rubrikk.exporter';
1
+ export * from './as24.exporter';
2
+ export * from './auto24.exporter';
3
+ export * from './autouncle.exporter';
4
+ export * from './by-owner.exporter';
5
+ export * from './fb.exporter';
6
+ export * from './google.exporter';
7
+ export * from './meinstadt.exporter';
8
+ export * from './mobile.exporter';
2
9
  export * from './modix.exporter';
10
+ export * from './ooyyo.exporter';
11
+ export * from './rubrikk.exporter';
@@ -1,14 +1,15 @@
1
- import { CarService, RulesService, LoaderService, ConfigService } from '../services';
2
- import { FsChunkInterface } from '@bytebrand/chunkable';
3
- import { Exporter } from '../interfaces/exporter.interface';
4
- import { CronicleUtils } from '@bytebrand/cronicle-helper';
5
- import { Zipper } from '@bytebrand/zipper';
6
1
  import { Injectable } from '@nestjs/common';
7
2
  import { ModuleRef } from '@nestjs/core';
8
- import { MeinstadtJsonBuilder } from '../formats/meinstadt-json.builder';
9
- import { get, isNil } from 'lodash';
3
+
4
+ import { CronicleUtils } from '@bytebrand/cronicle-helper';
5
+ import { FsChunkInterface } from '@bytebrand/chunkable';
6
+ import { Zipper } from '@bytebrand/zipper';
7
+
8
+ import { CarService, RulesService, LoaderService, ConfigService } from '../services';
10
9
  import { MeinstadtTransformer } from '../transformers/meinstadt.transformer';
10
+ import { MeinstadtJsonBuilder } from '../formats/meinstadt-json.builder';
11
11
  import { MeinstadtJsonItem } from '../interfaces/export-item.interface';
12
+ import { Exporter } from '../interfaces/exporter.interface';
12
13
 
13
14
  @Injectable()
14
15
  export class MeinstadtExporter implements Exporter {
@@ -18,50 +19,32 @@ export class MeinstadtExporter implements Exporter {
18
19
  private rulesService: RulesService,
19
20
  private loaderService: LoaderService,
20
21
  private moduleRef: ModuleRef,
21
- ) {}
22
+ ) { }
22
23
 
23
24
  async export(): Promise<void> {
24
- for (const file of this.configService.config.outputFiles) {
25
- const exists = await CronicleUtils.exists(file);
26
- exists && (await CronicleUtils.unlink(file));
27
- }
28
-
29
- const [fileCarJson, fileGZ] = this.configService.config.outputFiles;
25
+ const [fileJson, fileGZ] = this.configService.config.outputFiles;
26
+ await Promise.all([CronicleUtils.unlinkIfExists(fileJson), CronicleUtils.unlinkIfExists(fileGZ)])
30
27
 
31
- const meinstadtJsonBuilder = new MeinstadtJsonBuilder(fileCarJson);
32
- meinstadtJsonBuilder.buildStart();
28
+ const meinstadtJsonBuilder = new MeinstadtJsonBuilder(fileJson);
29
+ await meinstadtJsonBuilder.buildStart();
33
30
 
34
31
  const meinstadtTransformer = await this.moduleRef.create(MeinstadtTransformer);
35
32
 
36
33
  let firstCar = true;
37
34
  await this.loaderService.process(async (chunk: FsChunkInterface) => {
38
- let chunkData;
39
- if (this.configService.config.isNewCar) {
40
- chunkData = chunk.data.filter(
41
- e => this.carService.filterCar(e, this.rulesService.rules) && this.carService.isCarNew(e),
42
- );
43
- } else {
44
- chunkData = chunk.data.filter(e => this.carService.filterCar(e, this.rulesService.rules));
45
- }
46
- chunk.data = null;
47
- for (const data of chunkData) {
48
- const ownerId = get(data.car, 'metaData.ownerId', null);
49
- if (!isNil(ownerId)) {
50
- const owner = await this.carService.getOwner(ownerId);
51
- if (owner) {
52
- const car = await meinstadtTransformer.transform({ owner, ...data });
53
- await meinstadtJsonBuilder.addItem(car as MeinstadtJsonItem, firstCar);
54
- this.carService.counter.countCar(data.images);
55
- }
56
- if (firstCar) {
57
- firstCar = false;
58
- }
59
- }
35
+ chunk.data = chunk.data.filter(e => this.carService.filterCar(e, this.rulesService.rules));
36
+
37
+ for (const data of chunk.data) {
38
+ const car = await meinstadtTransformer.transform({ ...data });
39
+ await meinstadtJsonBuilder.addItem(car as MeinstadtJsonItem, firstCar);
40
+ this.carService.counter.countCar(data.images);
41
+
42
+ if (firstCar) { firstCar = false; }
60
43
  }
61
44
  });
62
45
 
63
- meinstadtJsonBuilder.buildEnd();
64
-
65
- await Zipper.zip({ dest: fileGZ, fileList: [fileCarJson] });
46
+ await meinstadtJsonBuilder.buildEnd();
47
+ await Zipper.zip({ dest: fileGZ, fileList: [fileJson] });
48
+ console.log(this.carService.counter.getCountedCars());
66
49
  }
67
50
  }
@@ -1,18 +1,18 @@
1
- import { CarService, RulesService, LoaderService, ConfigService } from '../services';
2
- import { FsChunkInterface } from '@bytebrand/chunkable';
3
1
  import { writeFile } from 'fs/promises';
2
+ import { basename, normalize } from 'path';
3
+
4
+ import { Injectable } from '@nestjs/common';
5
+ import { ModuleRef } from '@nestjs/core';
6
+
7
+ import { CronicleUtils } from '@bytebrand/cronicle-helper';
8
+ import { FsChunkInterface } from '@bytebrand/chunkable';
9
+ import { Zipper } from '@bytebrand/zipper';
10
+
11
+ import { CarService, RulesService, LoaderService, ConfigService } from '../services';
4
12
  import { MobileTransformer } from '../transformers/mobile.transformer';
5
13
  import { convertToCSV } from '../utils/converter.utils';
6
14
  import { Exporter } from '../interfaces/exporter.interface';
7
- import { CronicleUtils } from '@bytebrand/cronicle-helper';
8
- import { Zipper } from '@bytebrand/zipper';
9
- import { normalize, join, extname } from 'path';
10
- import { Injectable } from '@nestjs/common';
11
- import { ModuleRef } from '@nestjs/core';
12
- import { HttpService } from '@nestjs/axios';
13
- import { lastValueFrom } from 'rxjs';
14
- import { get } from 'lodash';
15
- import { FileTypes } from '../enums';
15
+ import { FileType } from '../enums';
16
16
 
17
17
  @Injectable()
18
18
  export class MobileExporter implements Exporter {
@@ -22,83 +22,41 @@ export class MobileExporter implements Exporter {
22
22
  private rulesService: RulesService,
23
23
  private loaderService: LoaderService,
24
24
  private moduleRef: ModuleRef,
25
- private httpService: HttpService,
26
- ) {}
25
+ ) { }
27
26
 
28
27
  async export(): Promise<void> {
29
- const fileName = '416';
28
+ const [fileName] = this.configService.config.outputFiles;
30
29
 
31
30
  await CronicleUtils.ensureDir(this.configService.config.pathesConfig.localConvertedDirectory);
32
31
  await CronicleUtils.emptyDir(this.configService.config.pathesConfig.localConvertedDirectory);
33
- if (this.configService.config.downloadImages) {
34
- await CronicleUtils.ensureDir(join(this.configService.config.pathesConfig.localConvertedDirectory, 'images'));
35
- }
36
32
 
37
33
  const mobileTransformer = await this.moduleRef.create(MobileTransformer);
38
34
 
39
35
  await this.loaderService.process(async (chunk: FsChunkInterface) => {
40
- if (this.configService.config.isNewCar) {
41
- chunk.data = chunk.data.filter(
42
- e => this.carService.filterCar(e, this.rulesService.rules) && this.carService.isCarNew(e),
43
- );
44
- } else {
45
- chunk.data = chunk.data.filter(e => this.carService.filterCar(e, this.rulesService.rules));
46
- }
36
+ chunk.data = chunk.data.filter(e => this.carService.filterCar(e, this.rulesService.rules));
47
37
 
48
38
  if (chunk && chunk.data) {
49
39
  for (let i = 0; i < chunk.data.length; i += 1) {
50
40
  const data = chunk.data[i];
51
41
  const { car, images } = data;
52
42
  const transformedData = await mobileTransformer.transform(car, images);
53
- if (this.configService.config.downloadImages) {
54
- await this.downloadImages(get(transformedData, '1'), get(transformedData, '26', '').split(';'));
55
- }
56
- const transformedDataCSV = `${convertToCSV(transformedData)}\n`;
57
43
 
58
- await writeFile(
59
- `${this.configService.config.pathesConfig.localConvertedDirectory}/${fileName}.${FileTypes.csv}`,
60
- Buffer.from(transformedDataCSV),
61
- { flag: 'a' },
62
- );
44
+ const file = `${this.configService.config.pathesConfig.localConvertedDirectory}/${fileName}`;
45
+ await writeFile(file, Buffer.from(`${convertToCSV(transformedData)}\n`), { flag: 'a' });
46
+
63
47
  this.carService.counter.countCar(data.images);
64
48
  }
65
- chunk.data = null;
49
+
66
50
  }
67
51
  });
68
52
 
69
- const fileZIP = normalize(
70
- `${this.configService.config.pathesConfig.localConvertedDirectory}/${fileName}.${FileTypes.zip}`,
71
- );
72
- const fileCSV = normalize(
73
- `${this.configService.config.pathesConfig.localConvertedDirectory}/${fileName}.${FileTypes.csv}`,
74
- );
53
+ const fileZIP = normalize(`${this.configService.config.pathesConfig.localConvertedDirectory}/${basename(fileName)}.${FileType.ZIP}`);
54
+ const fileCSV = normalize(`${this.configService.config.pathesConfig.localConvertedDirectory}/${fileName}`);
75
55
  const fileList = [fileCSV];
76
- if (this.configService.config.downloadImages) {
77
- const fileImages = normalize(join(this.configService.config.pathesConfig.localConvertedDirectory, 'images'));
78
- fileList.push(fileImages);
79
- }
80
56
 
81
57
  if (await CronicleUtils.exists(fileCSV)) {
82
58
  await Zipper.zip({ fileList, dest: fileZIP });
83
59
  }
84
- }
85
-
86
- private downloadImages(vehicleId: string, imageUrls: string[]): Promise<PromiseSettledResult<unknown>[]> {
87
- return Promise.allSettled(
88
- imageUrls.map(async (imageUrl, index) => {
89
- const response = await lastValueFrom(
90
- this.httpService.get(imageUrl, {
91
- responseType: 'arraybuffer',
92
- }),
93
- );
94
- const imageFile = join(
95
- this.configService.config.pathesConfig.localConvertedDirectory,
96
- 'images',
97
- `${vehicleId}_${index + 1}${extname(imageUrl) || FileTypes.jpg}`,
98
- );
99
-
100
- return writeFile(imageFile, response.data, { flag: 'w' });
101
- }),
102
- );
60
+ console.log(this.carService.counter.getCountedCars());
103
61
  }
104
62
  }
@@ -1,12 +1,14 @@
1
1
  import { Injectable } from '@nestjs/common';
2
- import { Exporter } from '../interfaces/exporter.interface';
3
- import { CarService, ConfigService, LoaderService } from '../services';
4
2
  import { ModuleRef } from '@nestjs/core';
3
+
5
4
  import { CronicleUtils } from '@bytebrand/cronicle-helper';
6
- import { ModixXmlBuilder } from '../formats';
7
- import { ModixTransformer } from '../transformers';
8
5
  import { FsChunkInterface } from '@bytebrand/chunkable';
9
6
 
7
+ import { CarService, ConfigService, LoaderService } from '../services';
8
+ import { Exporter } from '../interfaces/exporter.interface';
9
+ import { ModixTransformer } from '../transformers';
10
+ import { ModixXmlBuilder } from '../formats';
11
+
10
12
  @Injectable()
11
13
  export class ModixExporter implements Exporter {
12
14
  constructor(
@@ -16,30 +18,29 @@ export class ModixExporter implements Exporter {
16
18
  private moduleRef: ModuleRef,
17
19
  ) {}
18
20
  async export(): Promise<void> {
19
- for (const file of this.configService.config.outputFiles) {
20
- const exists = await CronicleUtils.exists(file);
21
- exists && (await CronicleUtils.unlink(file));
22
- }
23
-
24
21
  const [fileXml] = this.configService.config.outputFiles;
22
+ await CronicleUtils.unlinkIfExists(fileXml);
25
23
 
26
24
  const modixXmlBuilder = new ModixXmlBuilder(fileXml);
25
+ await modixXmlBuilder.buildStart();
26
+
27
27
  const modixTransformer = await this.moduleRef.create(ModixTransformer);
28
28
 
29
- await modixXmlBuilder.buildStart();
30
29
  await this.loaderService.process(async (chunk: FsChunkInterface) => {
31
30
  if (chunk && chunk.data) {
32
31
  for (let i = 0; i < chunk.data.length; i += 1) {
33
32
  const data = chunk.data[i];
34
- const { car, images } = data;
35
33
 
36
- const transformed_car = await modixTransformer.transform({ car, images });
34
+ const transformed_car = await modixTransformer.transform(data);
37
35
  await modixXmlBuilder.addItem(transformed_car);
38
- this.carService.counter.countCar(images);
36
+
37
+ this.carService.counter.countCar(data.images);
39
38
  }
40
- chunk.data = null;
39
+
41
40
  }
42
41
  });
42
+
43
43
  await modixXmlBuilder.buildEnd();
44
+ console.log(this.carService.counter.getCountedCars())
44
45
  }
45
46
  }
@@ -16,20 +16,17 @@ export class OoyyoExporter implements Exporter {
16
16
  private loaderService: LoaderService,
17
17
  private moduleRef: ModuleRef,
18
18
  private rulesService: RulesService,
19
- ) {}
19
+ ) { }
20
20
 
21
21
  async export(): Promise<void> {
22
- for (const file of this.configService.config.outputFiles) {
23
- const exists = await CronicleUtils.exists(file);
24
- exists && (await CronicleUtils.unlink(file));
25
- }
22
+ const [fileXml, fileGZ] = this.configService.config.outputFiles;
23
+ await Promise.all([CronicleUtils.unlinkIfExists(fileXml), CronicleUtils.unlinkIfExists(fileGZ)]);
24
+
25
+ const ooyyoXmlBuilder = new OoyyoXmlBuilder(fileXml);
26
+ await ooyyoXmlBuilder.buildStart();
26
27
 
27
- const [fileCarXml, fileGZ] = this.configService.config.outputFiles;
28
- const ooyyoXmlBuilder = new OoyyoXmlBuilder(fileCarXml);
29
28
  const ooyyoTransformer = await this.moduleRef.create(OoyyoTransformer);
30
29
 
31
- await ooyyoXmlBuilder.buildStart();
32
-
33
30
  await this.loaderService.process(async (chunk: FsChunkInterface) => {
34
31
  const chunkData = chunk.data.filter(car => this.carService.filterCar(car, this.rulesService.rules));
35
32
 
@@ -38,14 +35,16 @@ export class OoyyoExporter implements Exporter {
38
35
  const data = chunk.data[i];
39
36
  const { car, images } = data;
40
37
  await ooyyoXmlBuilder.addItem(ooyyoTransformer.transform(car, images));
38
+
41
39
  this.carService.counter.countCar(images);
42
40
  }
43
- chunk.data = null;
41
+
44
42
  }
45
43
  });
46
44
 
47
45
  await ooyyoXmlBuilder.buildEnd();
46
+ console.log(this.carService.counter.getCountedCars());
48
47
 
49
- await Zipper.tar({ dest: fileGZ, fileList: [fileCarXml] });
48
+ await Zipper.tar({ dest: fileGZ, fileList: [fileXml] });
50
49
  }
51
50
  }