Loop taking only the first IONIC record 3

0

I need to compare the offline records individually, with the records of my webservice, if it exists it does Update, otherwise it does Insert. But my SQL query only gets on the first record, and it is falling on my IF and Else simultaneously. Here is the function and return below:

syncPayment(token, codven): Promise<string[]> {
    return new Promise ((resolve, reject) => {
        this.getDB()
        .then((db: SQLiteObject) => {

            this.dataSync = this.http.get(syncURLPayment+'/'+token+'/'+codven, {headers: this.returnHeaders()});
            this.dataSync
            .subscribe(data => {

                var sqlInsert = 'INSERT INTO dadf109 (CODIGO, DESCRI, TIPOCO, TAXMAX, INDACR, TIPIND, VALENT, PARA01, SINCRO, DATINT) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';

                for (var i of data.data) {
                    var codigo    = i.CODIGO;
                    var sqlSelect = "SELECT codigo, descri, tipoco, sincro, datint FROM dadf109 WHERE codigo = ?";

                    db.executeSql(sqlSelect, [codigo])
                    .then((result: any) => {
                        if(result.rows.length > 0){
                            // check date of change, and update row
                            /*if(node.DATINT != i.DATALT) {
                                var sqlUpd = 'UPDATE dadf109 SET codigo = ?, descri = ?, tipoco = ?, sincro = ?, datint = ? WHERE codigo = ?';

                                var arrayUpd = [i.codigo, i.descri, i.tipoco, 'S', i.DATALT, i.codigo];

                                db.executeSql(sqlUpd, arrayUpd)
                                .then(() => resolve('OK'))
                                .catch(e => reject(e))
                            }*/
                            console.log('if' + sqlSelect + codigo);
                        } else {
                            /*var ist = [i.CODIGO, i.DESCRI, i.TIPOCO, i.TAXMAX, i.INDACR, i.TIPIND, i.VALENT, i.PARA01, 'S', i.DATALT];

                            db.executeSql(sqlInsert, ist)
                            .then(() => resolve('OK'))
                            .catch(e => reject(e))*/
                            console.log('else' + sqlSelect + codigo);
                        }
                    });
                }
                resolve()
            });
        }).catch(e => console.log(e));
    });
}

    
asked by anonymous 27.11.2018 / 14:26

0 answers