All files / src/Connector ShoptetGetAllProducts.ts

93.33% Statements 14/15
75% Branches 3/4
100% Functions 2/2
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  12x 12x   12x   12x     12x       1x 1x   1x   1x       1x       1x   1x 1x   1x                        
import ProcessDto from '@orchesty/nodejs-sdk/dist/lib/Utils/ProcessDto';
import ShoptetPremiumApplication from '../ShoptetPremiumApplication';
import AShoptetConnector from './AShoptetConnector';
 
export const NAME = 'shoptet-get-all-products';
 
export default class ShoptetGetAllProducts extends AShoptetConnector {
 
    public getName(): string {
        return NAME;
    }
 
    public async processAction(dto: ProcessDto<{ from: string }>): Promise<ProcessDto<IOutput>> {
        const { from } = dto.getJsonData();
        const appInstall = await this.getApplicationInstallFromProcess(dto);
 
        let url = 'api/products/snapshot';
 
        const creationTimeFrom = from || ShoptetPremiumApplication.shoptetDateISO(
            appInstall.getNonEncryptedSettings().lastRunListProductChanges,
        );
 
        Iif (creationTimeFrom) {
            url = `${url}?creationTimeFrom=${creationTimeFrom}`;
        }
 
        const response = await this.doRequest(url, dto) as IResponse;
 
        appInstall.addNonEncryptedSettings({ lastRunListProductChanges: new Date() });
        await this.getDbClient().getApplicationRepository().update(appInstall);
 
        return dto.setNewJsonData(response.data);
    }
 
}
 
interface IResponse {
    data: IOutput;
}
 
export interface IOutput {
    jobId: string;
}