如何通过JSON处理查询数据?

时间:2018-09-25 18:57:17

标签: node.js

我正在使用第三方API(到目前为止,还不错,我得到了结果),但是由于我是新手,所以很难为前端(EJS)操纵这些结果** ... < / p>

系统应该做的是:

该站点是一个图形面板,我在其中使用第三方API(如果由前端使用,它将阻止源),并使用名为(CHARTJS)的图形插件填充JSON中接收的数据。在那里,因为应该在访问页面后立即使用API​​,并在使用后填充图形,但是对于我来说,要使用此JSON,我需要传递一些QS ...访问第一个图形的页面时这些QS是已经是自动的,并且可以由包含相同页面的表单来操纵,以便能够执行其他查询..

我完全迷失了,我希望得到一些帮助和解释..

CONTROLLERS / LOGIN / LOGIN.JS

module.exports.index = (_application, _request, _response) => {
    _response.render('login/index');
}

module.exports.check_login =  (_application, _request, _response) => {
    const JSON_MODEL = new _application.app.models.jsonDAO('fatVenda.xsjs', '\'BSC\'', '201807', 'vendaabs,vendam2');
    JSON_MODEL.request();

    console.log(JSON_MODEL.jsonData)

    const VENDA_MODEL = new _application.app.models.vendaDAO('', '', '', '');

    _response.render('home/home');

}

路线/登录/LOGIN.JS

module.exports = (_application) => {
    _application.get('/login', (_request, _response) => {
        _application.app.controllers.login.login.index(_application, _request, _response);
    });

    _application.post('/check_login', (_request, _response) => {
        _application.app.controllers.login.login.check_login(_application, _request, _response);
    });
}

MODELS / JSONDAO.JS

const REQUEST = require('request');

class JsonRequestDAO {
    constructor(_xjs, _shoppingID, _periodUntil, _kpi){
        this.xjs         = _xjs;
        this.shoppingID  = _shoppingID;
        this.periodUntil = _periodUntil;
        this.kpi         = _kpi;
    }

    request(){
        REQUEST.get({
            uri: `URL${this.xjs}`,
            json: true,
            qs: {
                Shop:       this.shoppingID,
                PeriodoAte: this.periodUntil,
                Kpi:        this.kpi
            },
            headers: {
                Authorization:   'Basic KEY',
                ApiKey:          'KEY', 
                'Cache-Control': 'no-cache',
                'Content-Type':  'application/json',
            }
        }, (_error, _response) => {
           (_response.statusCode == 200) ? _response.body : console.log(_error);
        });
    }
}

module.exports = () => { return JsonRequestDAO; }

MODELS / VENDADAO.JS

class VendaDAO {
    constructor(_shoppingName, _yearMonth, _competence, _sale, _salePercentage, _saleSquareMeter, _salePercentageSquareMeter){
        this.shoppingName              = _shoppingName;
        this.yearMonth                 = _yearMonth;
        this.competence                = _competence;
        this.sale                      = _sale;
        this.salePercentage            = _salePercentage;
        this.saleSquareMeter           = _saleSquareMeter;
        this.salePercentageSquareMeter = _salePercentageSquareMeter;
    }

    static get shoppingName()              { return this.shoppingName;              }
    static get yearMonth()                 { return this.yearMonth;                 }
    static get competence()                { return this.competence;                }
    static get sale()                      { return this.sale;                      }
    static get salePercentage()            { return this.salePercentage;            }
    static get saleSquareMeter()           { return this.saleSquareMeter;           }
    static get salePercentageSquareMeter() { return this.salePercentageSquareMeter; }
}

module.exports = () => {
    return VendaDAO;
}

enter image description here

0 个答案:

没有答案