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 | 18x 18x 18x 18x 18x 18x 72x 72x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 1x 4x | import CoreFormsEnum from '@orchesty/nodejs-sdk/dist/lib/Application/Base/CoreFormsEnum';
import { ApplicationInstall } from '@orchesty/nodejs-sdk/dist/lib/Application/Database/ApplicationInstall';
import AConnector from '@orchesty/nodejs-sdk/dist/lib/Connector/AConnector';
import { HttpMethods } from '@orchesty/nodejs-sdk/dist/lib/Transport/HttpMethods';
import ProcessDto from '@orchesty/nodejs-sdk/dist/lib/Utils/ProcessDto';
import { StatusCodes } from 'http-status-codes';
import { checkErrorInResponse, ICO, jsonToXml, xmlToJson } from '../PohodaApplication';
export default abstract class APohodaConnector<IInput, IOutput, IResponse extends object> extends AConnector {
public constructor(private readonly timeout = 120_000) {
super();
}
protected abstract getSchema(): string;
protected abstract createItemData(dto: ProcessDto<IInput>): Promise<object>;
protected abstract getItemData(data: IResponse): IOutput;
public async processAction(dto: ProcessDto<IInput>): Promise<ProcessDto<IOutput>> {
const applicationInstall = await this.getApplicationInstallFromProcess(dto);
const requestDto = (await this.getApplication().getRequestDto(
dto,
applicationInstall,
HttpMethods.POST,
'xml',
jsonToXml(await this.createData(dto, applicationInstall)),
)).setTimeout(this.timeout);
const responseDto = await this.getSender().send(requestDto, [StatusCodes.OK]);
const response = xmlToJson<IBaseResponse<IResponse>>(responseDto.getBuffer());
const { responsePack } = response;
checkErrorInResponse(responsePack);
const { responsePackItem } = responsePack;
checkErrorInResponse(responsePackItem);
return dto.setNewJsonData(this.getItemData(responsePackItem));
}
protected async createData(dto: ProcessDto<IInput>, applicationInstall: ApplicationInstall): Promise<object> {
const ico = applicationInstall.getSettings()[CoreFormsEnum.AUTHORIZATION_FORM][ICO];
return {
/* eslint-disable @typescript-eslint/naming-convention */
'data:dataPack': {
'@_xmlns:data': 'http://www.stormware.cz/schema/version_2/data.xsd',
'@_xmlns:filter': 'http://www.stormware.cz/schema/version_2/filter.xsd',
'@_xmlns:itemData': this.getSchema(),
'@_id': 'Orchesty',
'@_ico': ico,
'@_application': 'Orchesty',
'@_note': 'Orchesty',
'@_version': '2.0',
...await this.getCustomDataPackAttributes(dto),
'data:dataPackItem': {
'@_id': 'Orchesty',
'@_version': '2.0',
...await this.getCustomDataPackItemAttributes(dto),
...await this.createItemData(dto),
},
},
/* eslint-enable @typescript-eslint/naming-convention */
};
}
// 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/no-unused-vars, @typescript-eslint/require-await
protected async getCustomDataPackItemAttributes(dto: ProcessDto<IInput>): Promise<object> {
return {};
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/require-await
protected async getCustomRequestAttributes(dto: ProcessDto<IInput>): Promise<object> {
return {};
}
}
interface IBaseResponse<IResponse> {
responsePack: {
responsePackItem: IResponse;
};
}
|