'How can I compare a Google spreadsheets data with a firestore data?
I have this specific code:
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: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
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
})
// =========================== DUPLICIDADE ADMINISTRATIVA ===================================
const duplicitiesWithAdministrativeCharges = new Array()
const resultduplicitiesWithAdministrativeCharges = firestore.collection('Protocolos finalizados') //1lGPC1UuxVRplJCVfAXAPWeigjgx1ETyx1OpdtCCJoXo (Pagamentos finalizados)
.where("autosPF", "==", arbitramentoHonorários) // autosPF => Planilha Pagamentos finalizados / arbitramentoHonorários => Planilha de Criaão de filtros
.where("cpf_PF", "==", cpf) // cpf_PF => Planilha Pagamentos finalizados / cpf => Planilha de Criação de filtros
const resDuplicitiesWithAdministrativeCharges = await resultduplicitiesWithAdministrativeCharges.get()
if (resDuplicitiesWithAdministrativeCharges.size) {
resDuplicitiesWithAdministrativeCharges.forEach(doc => {
if (resDuplicitiesWithAdministrativeCharges.size == 1) {
functions.logger.log("Foi encontrada " + `${resDuplicitiesWithAdministrativeCharges.size} ` + "duplicidade administrativa referente a pessoa " + `${nome}.`)
functions.logger.log(doc.id) // NÃO MEXER
functions.logger.log(doc.data()) //NÃO MEXER
functions.logger.log('requerimento: ', doc.data().requerimento) // NÃO MEXER
functions.logger.log('mesPagamento: ', doc.data().mesPagamento) // NÃO MEXER
// Requerimento e mesPagamento devem vir da planilha de pagamentos finalizados
duplicitiesWithAdministrativeCharges.push(`${'arbitramentoHonorários'}: ${arbitramentoHonorários}`, `${'nome'}: ${nome}`, `${'requerimento'}: ${doc.data().requerimento}`, `${'mesPagamento'}: ${doc.data().mesPagamento}`)
functions.logger.log(duplicitiesWithAdministrativeCharges)//NÃO MEXER
} else if (resDuplicitiesWithAdministrativeCharges.size > 1) {
functions.logger.log("Foram encontradas " + `${resDuplicitiesWithAdministrativeCharges.size} ` + "duplicidades administrativa referente a pessoa " + `${nome}.`)
functions.logger.log(doc.id)
functions.logger.log('requerimento: ', doc.data().requerimento) // NÃO MEXER
functions.logger.log('mesPagamento: ', doc.data().mesPagamento) // NÃO MEXER
// Requerimento e mesPagamento devem vir da planilha de pagamentos finalizados
duplicitiesWithAdministrativeCharges.push(`${'arbitramentoHonorários'}: ${arbitramentoHonorários}`, `${'nome'}: ${nome}`, `${'requerimento'}: ${doc.data().requerimento}`, `${'mesPagamento'}: ${doc.data().mesPagamento}`)
functions.logger.log(duplicitiesWithAdministrativeCharges)//NÃO MEXER
}
})
}
else if (resDuplicitiesWithAdministrativeCharges.size <= 0){
functions.logger.log('Não há duplicidades administrativas nesta lista')
//console.log('Não há duplicidades administrativas nesta lista')
}
})
await Promise.all(generateDuplicities)
})
I want send the {duplicitiesWithAdministrativeCharges} functions.logger result´s to a google spread sheets.
The result´s need to be sended in this order to the spread sheet.
arbitramentoHonoráriosit will be in a specific columnArbitramento de honorários(column A(1))nomeit will be in a specific columnNome do autor(column B(1))doc.data().requerimentowill be in a specific columnRequerimento de pagamento(column C(1))doc.data().mesPagamentowill be in a specific columnListagem de pagamento(column D(1))
Does anyone know how I can send the result data from my code to another Google spreadsheet?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
