P8-ExchangeService/modules/parus_test.js
2018-12-18 15:45:44 +03:00

47 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
Сервис интеграции ПП Парус 8 с WEB API
Дополнительный модуль: тестовый модуль для ПМИ
*/
//------------------------------
// Подключение внешних библиотек
//------------------------------
const js2xmlparser = require("js2xmlparser"); //Конвертация JSON в XML
//------------
// Тело модуля
//------------
//Формирование запроса к тестовому стенду на получение сведений о контрагенте
const beforeAgentInfo = async prms => {
//Считаем параметры запроса из тела сообщения
let sPayLoad = prms.queue.blMsg.toString();
//Вернем конвертированное в XML-сообщение (потребуется для использования при разборе ответа) и параметры для соединения
return {
options: {
url: `${prms.service.sSrvRoot}/${prms.function.sFnURL}?CPRMS=${sPayLoad}`
},
blMsg: new Buffer(js2xmlparser.parse("MSG", JSON.parse(sPayLoad)))
};
};
//Обработка ответа тестового стенда на запрос сведений о контрагенте
const afterAgentInfo = async prms => {
let r = JSON.parse(prms.serverResp);
if (r.STATE === 0) {
throw Error(r.MSG);
} else {
return {
blResp: new Buffer(js2xmlparser.parse("AGENT", r))
};
}
};
//-----------------
// Интерфейс модуля
//-----------------
exports.beforeAgentInfo = beforeAgentInfo;
exports.afterAgentInfo = afterAgentInfo;