I’m trying send some data from firebase to google sheets. I used the method push() to insert the data into a variable and call it in “resource {values: duplicitiesWithJudicialCharges}”.
I know that have more than one value, but in my google sheet it’s apearing just one line.
From what I’ve observed, the last value erases the previous one and sticks to the first line. I would like all the values in the rows to appear in sequence.
import * as functions from 'firebase-functions'
import { google } from 'googleapis'
import { initializeApp } from 'firebase-admin/app'
const serviceAccount = require('../sheets_updater_service_account.json')
const sheets = google.sheets('v4')
import { getFirestore } from "firebase-admin/firestore"
initializeApp()
const firestore = getFirestore()
module.exports.readAndUpdateAdministrativeSheet = functions.https.onRequest(async (request, response) => {
// =========================== AUTENTICAÇÃO FIREBASE ===================================
const jwtClient = new google.auth.JWT({
email: serviceAccount.client_email,
key: serviceAccount.private_key,
scopes: ['https://www.googleapis.com/auth/spreadsheets']
})
await jwtClient.authorize()
// ================= CONEXÃO COM A PLANILHA CRIAÇÃO DE FILTROS =========================
const { data } = await sheets.spreadsheets.values.get({
auth: jwtClient,
spreadsheetId: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
range: `Listagem de pagamento!A2:X6`,
})
// ========= CRIAÇÃO DE BANCO DE DADOS DA COLEÇÃO LISTAGEM DE PAGAMENTO ================
const generateDuplicities = data.values!.map(async row => {
const [idade, nome, cpf, cpf_x, numeroRequerimento, arbitramentoHonorários,
valorArbitrado, valorDeferido, valorComplementar, status, resultado, codigoBanco,
banco, agencia, conta, dataDoRequerimento, dataRequerimento, dataStatus,
comarca, vara, ato, assistidos, email, telefone] = row
firestore.collection("Listagem de pagamento").doc(numeroRequerimento).set({
idade, nome, cpf, cpf_x, numeroRequerimento, arbitramentoHonorários,
valorArbitrado, valorDeferido, valorComplementar, status, resultado, codigoBanco,
banco, agencia, conta, dataDoRequerimento, dataRequerimento, dataStatus, comarca, vara, ato,
assistidos, email, telefone
})
const resultduplicitiesWithJudicialCharges = firestore.collection("Processos judiciais").where("documentosDosautores", "==", cpf)
const duplicitiesWithJudicialCharges = new Array()
resultduplicitiesWithJudicialCharges.get().then((querySnapshot) => {
querySnapshot.forEach((parentDoc) => {
//functions.logger.log(parentDoc.id, " => ", parentDoc.data())
parentDoc.ref.collection("fee-arbitrations - Base de Execução").where('arbitramentoDeHonoráriosBE', '==', arbitramentoHonorários).get().then((querySnapshot) => {
querySnapshot.forEach(async (childDoc) => {
//duplicitiesWithJudicialCharges.push(`${'arbitramentoHonorários'}: ${arbitramentoHonorários}`, `${'nome'}: ${nome}`, `${'processoBE'}: ${childDoc.data().processoBE}`)
await duplicitiesWithJudicialCharges.push(`${arbitramentoHonorários}`, `${nome}`, `${childDoc.data().processoBE}`)
functions.logger.log(duplicitiesWithJudicialCharges)
// let res = [duplicitiesWithJudicialCharges]
// functions.logger.log(res)
const updateOptions = {
auth: jwtClient,
spreadsheetId: '1j9-R6gRj46Lxs0Zlj9LDTv37Hv-hW339Nph6dRI2W9c',
//range: 'grpr!A12',
range: '3. Duplicidades judiciais!A2:H1000',
valueInputOption: 'USER_ENTERED',
resource: { values: [duplicitiesWithJudicialCharges] },
}
await google.sheets({ version: 'v4', auth: jwtClient }).spreadsheets.values.clear({
range: '3. Duplicidades judiciais!A2:H1000', // SEMPRE QUE FOR QUERER DELETAR, VERIFIQUE A AS LINHAS E COLUNAS QUE POSSUEM VALOR
spreadsheetId: '1j9-R6gRj46Lxs0Zlj9LDTv37Hv-hW339Nph6dRI2W9c',
// Request body metadata
requestBody: {
// request body parameters
// {}
},
});
await google.sheets({ version: 'v4', auth: jwtClient }).spreadsheets.values.update(updateOptions)
})
})
})
})
})
await Promise.all(generateDuplicities)
})
Does anyone knows where is the problem?