All files / src/Connector PohodaPostReceiptConnector.ts

100% Statements 10/10
100% Branches 0/0
100% Functions 5/5
100% Lines 10/10

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  18x 18x   18x   18x     18x       1x         1x                     1x   1x         1x                                                                                                                                    
import ProcessDto from '@orchesty/nodejs-sdk/dist/lib/Utils/ProcessDto';
import { checkErrorInResponse, NAME as APPLICATION_NAME, ResponseState } from '../PohodaApplication';
import APohodaConnector from './APohodaConnector';
 
export const NAME = `${APPLICATION_NAME}-post-receipt-connector`;
 
export default class PohodaPostReceiptConnector extends APohodaConnector<IInput, IOutput, IResponse> {
 
    public getName(): string {
        return NAME;
    }
 
    protected getSchema(): string {
        return 'http://www.stormware.cz/schema/version_2/prijemka.xsd';
    }
 
    // eslint-disable-next-line @typescript-eslint/require-await
    protected async createItemData(dto: ProcessDto<IInput>): Promise<object> {
        return {
            /* eslint-disable @typescript-eslint/naming-convention */
            'itemData:prijemka': {
                '@_version': '2.0',
                ...dto.getJsonData(),
            },
            /* eslint-enable @typescript-eslint/naming-convention */
        };
    }
 
    protected getItemData(data: IResponse): IOutput {
        checkErrorInResponse(data.prijemkaResponse.importDetails?.detail);
 
        return data.prijemkaResponse.producedDetails;
    }
 
    // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/require-await
    protected async getCustomDataPackAttributes(dto: ProcessDto<IInput>): Promise<object> {
        return {
            // eslint-disable-next-line @typescript-eslint/naming-convention
            '@_xmlns:type': 'http://www.stormware.cz/schema/version_2/type.xsd',
        };
    }
 
}
 
export interface IInput {
    /* eslint-disable @typescript-eslint/naming-convention */
    'itemData:prijemkaHeader'?: {
        'itemData:partnerIdentity'?: {
            'type:id'?: number;
            'type:address'?: {
                'type:company'?: string;
            };
        };
        'itemData:intNote'?: string;
    };
    'itemData:prijemkaDetail'?: {
        'itemData:prijemkaItem': {
            'itemData:text'?: string;
            'itemData:quantity'?: number;
            'itemData:stockItem'?: {
                'type:stockItem'?: {
                    'type:id'?: number;
                };
            };
        }[];
    };
    'itemData:prijemkaSummary'?: {
        'itemData:foreignCurrency'?: {
            'type:currency'?: {
                'type:id'?: number;
            };
        };
    };
    /* eslint-enable @typescript-eslint/naming-convention */
}
 
export interface IResponse {
    prijemkaResponse: {
        importDetails?: {
            detail: {
                state: ResponseState;
                note: string;
            }[];
        };
        producedDetails: IOutput;
    };
}
 
export interface IOutput {
    id: number;
    number: string;
    actionType: string;
    itemDetails: {
        item: {
            actionType: string;
            producedItem: {
                id: number;
            };
        };
        type: string;
    };
}