all.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import ExtrDb from "../../data-storage/db/extr";
  2. import GenericExtr from "../../data-storage/db/extr/generic-extr";
  3. export default class All {
  4. private _db: ExtrDb;
  5. public async get(requestedFields: Array<string>, db: ExtrDb): Promise<Array<GenericExtr>> {
  6. this._db = db;
  7. return this.build(await this._db.getAll(requestedFields));
  8. }
  9. public async filteredBy(filters: any, requestedFields: Array<string>, db: ExtrDb): Promise<Array<GenericExtr>> {
  10. this._db = db;
  11. return this.build(await this._db.getFilteredBy(filters, requestedFields));
  12. }
  13. private build(
  14. extrsData: Array<GenericExtr>
  15. ): Array<GenericExtr> {
  16. if (!extrsData) {
  17. throw new Error("No extrs found");
  18. }
  19. return extrsData.map(extrData => {
  20. return {
  21. year: extrData.year,
  22. maker: extrData.maker,
  23. model: extrData.model,
  24. version: extrData.version,
  25. color: extrData.color,
  26. price: extrData.price,
  27. title: extrData.title,
  28. description: extrData.description,
  29. plate: extrData.plate,
  30. mileage: extrData.mileage,
  31. gearbox: extrData.gearbox,
  32. engine: extrData.engine,
  33. fuel: extrData.fuel,
  34. imageUrl: extrData.imageUrl,
  35. code: extrData.code,
  36. url: extrData.url,
  37. region: extrData.region,
  38. city: extrData.city,
  39. sellerType: extrData.sellerType,
  40. sellerName: extrData.sellerName,
  41. publicationCreationDate: extrData.publicationCreationDate,
  42. publicationCreationRawDate: extrData.publicationCreationRawDate,
  43. publicationUpdateDate: extrData.publicationUpdateDate,
  44. publicationCreatedAt: extrData.publicationCreatedAt,
  45. };
  46. });
  47. }
  48. }