All files / src/Batch RaynetCRMGetClients.ts

93.75% Statements 15/16
87.5% Branches 7/8
100% Functions 4/4
93.75% Lines 15/16

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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 19910x   10x     10x 10x   10x   10x     10x       2x 2x   2x             2x       2x       2x   2x       2x                                                                                                                                                                                                                                                                                                                          
import ABatchNode from '@orchesty/nodejs-sdk/dist/lib/Batch/ABatchNode';
import ResponseDto from '@orchesty/nodejs-sdk/dist/lib/Transport/Curl/ResponseDto';
import { HttpMethods } from '@orchesty/nodejs-sdk/dist/lib/Transport/HttpMethods';
import BatchProcessDto from '@orchesty/nodejs-sdk/dist/lib/Utils/BatchProcessDto';
 
export const NAME = 'raynet-crm-get-clients';
export const LIMIT = 1000;
 
export default class RaynetCRMGetClients extends ABatchNode {
 
    protected limit = LIMIT;
 
    public getName(): string {
        return NAME;
    }
 
    public async processAction(dto: BatchProcessDto<IInput>): Promise<BatchProcessDto> {
        const email = this.getData(dto);
        const page = Number(dto.getBatchCursor('0'));
 
        const req = await this.getApplication().getRequestDto(
            dto,
            await this.getApplicationInstallFromProcess(dto),
            HttpMethods.GET,
            `company?offset=${page}&limit=${this.limit}${email ? `&primaryAddress-contactInfo.email=${email}` : ''}`,
        );
 
        return this.processResponse(dto, await this.getSender().send<IResponse>(req, [200]), page);
    }
 
    protected getData(dto: BatchProcessDto<IInput>): string {
        return dto.getJsonData().email ?? '';
    }
 
    protected processResponse(dto: BatchProcessDto, resp: ResponseDto<IResponse>, page: number): BatchProcessDto {
        const { totalCount } = resp.getJsonBody();
 
        Iif (totalCount && totalCount > this.limit * (page + 1)) {
            dto.setBatchCursor(String(page + 1));
        }
 
        return dto.setItemList(resp.getJsonBody().data);
    }
 
}
 
export interface IInput {
    email?: string;
}
 
/* eslint-disable @typescript-eslint/naming-convention */
export interface IResponse {
    success: string;
    totalCount: number;
    data: {
        id: number;
        name: string;
        titleBefore?: unknown;
        firstName?: unknown;
        lastName?: unknown;
        titleAfter?: unknown;
        person: boolean;
        role: string;
        state: string;
        rating: string;
        owner: {
            id: number;
            fullName: string;
        };
        regNumber: string;
        taxNumber: string;
        taxNumber2?: unknown;
        taxPayer: string;
        bankAccount?: unknown;
        databox?: unknown;
        court?: unknown;
        primaryAddress: {
            id: number;
            primary: boolean;
            contactAddress: boolean;
            address: {
                id: number;
                city: string;
                country: string;
                name: string;
                province: string;
                street: string;
                zipCode: string;
                lat: number;
                lng: number;
            };
            territory: {
                id: number;
                value: string;
            };
            contactInfo: {
                email: string;
                email2: string;
                primary: boolean;
                tel1: string;
                tel1Type: string;
                tel2: string;
                tel2Type: string;
                www: string;
                otherContact?: unknown;
            };
            extIds?: unknown;
        };
        contactAddress: {
            id: number;
            primary: boolean;
            contactAddress: boolean;
            address: {
                id: number;
                city: string;
                country: string;
                name: string;
                province: string;
                street: string;
                zipCode: string;
                lat?: unknown;
                lng?: unknown;
            };
            territory: {
                id: number;
                value: string;
            };
            contactInfo: {
                email: string;
                email2?: unknown;
                primary: boolean;
                tel1: string;
                tel1Type: string;
                tel2: string;
                tel2Type: string;
                www?: unknown;
                otherContact?: unknown;
            };
            extIds?: unknown;
        };
        category: {
            id: number;
            value: string;
        };
        turnover: {
            id: number;
            value: string;
        };
        economyActivity: {
            id: number;
            value: string;
        };
        companyClassification1: {
            id: number;
            value: string;
        };
        companyClassification2: {
            id: number;
            value: string;
        };
        companyClassification3: {
            id: number;
            value: string;
        };
        paymentTerm: {
            id: number;
            value: string;
        };
        contactSource: {
            id: number;
            value: string;
        };
        birthday?: unknown;
        notice: string;
        tags: string[];
        customFields?: unknown;
        'rowInfo.createdAt': string;
        'rowInfo.createdBy': string;
        'rowInfo.updatedAt': string;
        'rowInfo.updatedBy': string;
        'rowInfo.rowAccess'?: unknown;
        'rowInfo.rowState'?: unknown;
        securityLevel: {
            id: number;
            name: string;
        };
        inlineGdpr: {
            id: number;
            validFrom: string;
            validTill: string;
            legalTitle: string;
            templateName: string;
            gdprTemplate: number;
        }[];
        _version: number;
    }[];
}
/* eslint-enable @typescript-eslint/naming-convention */