67 lines
2.6 KiB
JavaScript
Raw Permalink 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
Дополнительный модуль: Публикация аналитических данных (OLAPP)
*/
//------------------------------
// Подключение внешних библиотек
//------------------------------
const { ServerError } = require("./../core/server_errors"); //Типовая ошибка
const { SERR_APP_SERVER_BEFORE, SERR_DB_SERVER } = require("./../core/constants"); //Общесистемные константы
//------------
// Тело модуля
//------------
//Обработчик "До" для полученного сообщения
const before = async prms => {
//Если передан идентификатор публикации
if (prms.options.qs && prms.options.qs.STOKEN && prms.options.qs.NPREVIEW && prms.options.qs.NACTUAL_CHECK) {
//И есть подключение к БД
if (prms.dbConn.bConnected) {
let olappExtractData = await prms.dbConn.executeStored({
sName: "PKG_EXS_EXT_OLAPP_RUN.EXTRACT",
inPrms: {
STOKEN: prms.options.qs.STOKEN,
NPREVIEW: prms.options.qs.NPREVIEW,
NACTUAL_CHECK: prms.options.qs.NACTUAL_CHECK
},
outPrms: {
RCDATA: prms.dbConn.connector.DT_CURSOR
}
});
//Установим заголовок ответа и начнём выдачу данных
prms.res.set({
"content-type": "application/json;charset=utf-8"
});
prms.res.write("[");
if (olappExtractData)
if (olappExtractData.RCDATA) {
let cnt = 1;
olappExtractData.RCDATA.map(row => {
prms.res.write(Buffer.from(`${cnt > 1 ? "," : ""}${JSON.stringify(row)}`));
cnt++;
});
}
//Завершаем передачу
prms.res.write("]");
prms.res.end();
//Дальше обрабатывать не надо
return {
bStopPropagation: true
};
} else {
throw new ServerError(SERR_DB_SERVER, "Нет подключения к БД");
}
} else {
throw new ServerError(SERR_APP_SERVER_BEFORE, "Запрос к серверу сформирован некорректно");
}
};
//-----------------
// Интерфейс модуля
//-----------------
exports.before = before;