wazuh-kibana-app/public/services/csv-request.js
2018-08-20 09:00:50 +02:00

41 lines
1.2 KiB
JavaScript

/*
* Wazuh app - API request service
* Copyright (C) 2018 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
import { uiModules } from 'ui/modules'
const app = uiModules.get('app/wazuh', []);
class CSVRequest {
/**
* Constructor
* @param {*} genericReq Service to make requests to our server
*/
constructor(genericReq) {
this.genericReq = genericReq;
}
/**
* It fetchs data from /api/wazuh-api/csv route using the below parameters.
* @param {string} path Wazuh API route
* @param {number|string} id Elasticsearch document ID
* @param {*} filters Array of Wazuh API filters. Optional
*/
async fetch(path, id, filters = null) {
try {
const output = await this.genericReq.request('POST','/api/wazuh-api/csv',{ path, id, filters });
return output.data;
} catch (error) {
return Promise.reject(error);
}
}
}
app.service('csvReq', CSVRequest);