All files / src/Batch InventoryProductsList.ts

93.33% Statements 14/15
66.66% Branches 2/3
100% Functions 7/7
93.33% Lines 14/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102  16x   16x   16x   16x 16x       16x       3x                                   1x     1x                                       1x     1x 2x       1x       1x                                                                
import BatchProcessDto from '@orchesty/nodejs-sdk/dist/lib/Utils/BatchProcessDto';
import { ABaseBatch } from './ABaseBatch';
 
export const NAME = 'inventory-products-list';
 
export default class InventoryProductsList extends ABaseBatch<IInput> {
 
    public constructor(private readonly useAsBatch = false) {
        super();
    }
 
    public getName(): string {
        return NAME;
    }
 
    protected getMethod(): string {
        return 'getInventoryProductsList';
    }
 
    // eslint-disable-next-line @typescript-eslint/require-await
    protected async getParameters(dto: BatchProcessDto<IInput>, page: number, _lastRun?: Date): Promise<object> {
        const {
            inventoryId,
            filterId,
            filterCategoryId,
            filterEan,
            filterSku,
            filterName,
            filterPriceFrom,
            filterPriceTo,
            filterStockFrom,
            filterStockTo,
            filterSort,
            includeVariants,
        } = dto.getJsonData();
 
        /* eslint-disable @typescript-eslint/naming-convention */
        return {
            inventory_id: inventoryId,
            filter_id: filterId,
            filter_category_id: filterCategoryId,
            filter_ean: filterEan,
            filter_sku: filterSku,
            filter_name: filterName,
            filter_price_from: filterPriceFrom,
            filter_price_to: filterPriceTo,
            filter_stock_from: filterStockFrom,
            filter_stock_to: filterStockTo,
            filter_sort: filterSort,
            include_variants: includeVariants,
            page,
        };
        /* eslint-enable @typescript-eslint/naming-convention */
    }
 
    // eslint-disable-next-line @typescript-eslint/require-await
    protected async processOutputData(dto: BatchProcessDto, body: IOutput): Promise<BatchProcessDto> {
        Iif (this.useAsBatch) {
            dto.addItem(body);
        } else {
            Object.values(body.products).forEach((product) => {
                dto.addItem(product);
            });
        }
 
        return dto;
    }
 
    protected hasNextPage(jsonBody: IOutput): boolean {
        return Object.keys(jsonBody.products).length >= 1000;
    }
 
}
 
export interface IInput {
    inventoryId: string;
    filterId?: number;
    filterCategoryId?: number;
    filterEan?: string;
    filterSku?: string;
    filterName?: string;
    filterPriceFrom?: number;
    filterPriceTo?: number;
    filterStockFrom?: number;
    filterStockTo?: number;
    filterSort?: string;
    includeVariants?: boolean;
}
 
export interface Product {
    id: number;
    ean: string;
    sku: string;
    name: string;
    prices: Record<string, number>,
    stock: Record<string, number>
}
 
export interface IOutput {
    products: Record<string, Product>
}