1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import ExtrDb from "../../data-storage/db/extr";
- import GenericExtr from "../../data-storage/db/extr/generic-extr";
- export default class All {
- private _db: ExtrDb;
- public async get(requestedFields: Array<string>, db: ExtrDb): Promise<Array<GenericExtr>> {
- this._db = db;
- return this.build(await this._db.getAll(requestedFields));
- }
- public async filteredBy(filters: any, requestedFields: Array<string>, db: ExtrDb): Promise<Array<GenericExtr>> {
- this._db = db;
- return this.build(await this._db.getFilteredBy(filters, requestedFields));
- }
- private build(
- extrsData: Array<GenericExtr>
- ): Array<GenericExtr> {
- if (!extrsData) {
- throw new Error("No extrs found");
- }
- return extrsData.map(extrData => {
- return {
- year: extrData.year,
- maker: extrData.maker,
- model: extrData.model,
- version: extrData.version,
- color: extrData.color,
- price: extrData.price,
- title: extrData.title,
- description: extrData.description,
- plate: extrData.plate,
- mileage: extrData.mileage,
- gearbox: extrData.gearbox,
- engine: extrData.engine,
- fuel: extrData.fuel,
- imageUrl: extrData.imageUrl,
- code: extrData.code,
- url: extrData.url,
- region: extrData.region,
- city: extrData.city,
- sellerType: extrData.sellerType,
- sellerName: extrData.sellerName,
- publicationCreationDate: extrData.publicationCreationDate,
- publicationCreationRawDate: extrData.publicationCreationRawDate,
- publicationUpdateDate: extrData.publicationUpdateDate,
- publicationCreatedAt: extrData.publicationCreatedAt,
- };
- });
- }
- }
|