pass array as parameter to query query, express

0

Well, I would like to basically pass an array through the url to the red.params of express.router, I tried to do it in some ways:

router.get('/:[ids]?', function (req, res, next) { portfolioModel.deleteArray(req.params.array, function (erro, retorno) {

I need help! Please.

function that receives callback:

static deleteArray(ids, callback){
        var str = "DELETE FROM tbl_portfolio WHERE id IN ( ";
        new Promise(resolve =>{
            for (i = 0; i < ids.length; i++)
                if (i == (ids.length - 1))
                    str += "?"
                else
                    str += "?, "
            str += ")";
                resolve(str);
        }).then(result =>{
            db.query(str, ids, callback);
        })
    }

function that sends the callback:

router.get('/:[ids]?', function (req, res, next) {

    portfolioModel.deleteArray(req.params.array, function (erro, retorno) {

        let resposta = new RespostaClass();

        if (erro) {
            resposta.erro = true;
            resposta.msg = 'Ocorreu um erro';
            console.log('erro', erro);
        } else {
            resposta.dados = retorno;
        }

        res.json(resposta);

    })

})
    
asked by anonymous 10.12.2018 / 18:28

0 answers