All files / src/Connector PohodaPostIssueConnector.ts

100% Statements 13/13
100% Branches 2/2
100% Functions 6/6
100% Lines 13/13

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  18x 18x   18x   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-issue-connector`;
 
export enum SourceAgendaType {
    RECEIVED_ORDER = 'receivedOrder',
    ISSUE = 'issueSlip',
}
 
export default class PohodaPostIssueConnector extends APohodaConnector<IInput, IOutput, IResponse> {
 
    public getName(): string {
        return NAME;
    }
 
    protected getSchema(): string {
        return 'http://www.stormware.cz/schema/version_2/vydejka.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:vydejka': {
                '@_version': '2.0',
                ...dto.getJsonData(),
            },
            /* eslint-enable @typescript-eslint/naming-convention */
        };
    }
 
    protected getItemData(data: IResponse): IOutput {
        checkErrorInResponse(data.vydejkaResponse.importDetails?.detail);
 
        return data.vydejkaResponse.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:links'?: {
        'type:link': {
            'type:sourceAgenda': SourceAgendaType;
            'type:sourceDocument': {
                'type:id': string;
            };
        };
    };
    'itemData:vydejkaHeader'?: {
        'itemData:partnerIdentity'?: {
            'type:address': {
                'type:company': string;
            };
        };
        'itemData:intNote'?: string;
    };
    'itemData:vydejkaDetail'?: {
        'itemData:vydejkaItem': {
            'itemData:quantity': number;
            'itemData:stockItem': {
                'type:stockItem': {
                    'type:id': number;
                };
            };
        }[];
    };
    /* eslint-enable @typescript-eslint/naming-convention */
}
 
export interface IResponse {
    vydejkaResponse: {
        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;
    };
}