From b48c943f9ca14910e80a6daa5c79dff7aa0e1b74 Mon Sep 17 00:00:00 2001 From: Pablo Pettinari Date: Fri, 11 Feb 2022 11:38:13 -0300 Subject: [PATCH] select working sheet by name --- vue-app/.env.example | 4 +++- vue-app/src/lambda/recipient.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/vue-app/.env.example b/vue-app/.env.example index ed8ba9ee7..161df5589 100644 --- a/vue-app/.env.example +++ b/vue-app/.env.example @@ -33,4 +33,6 @@ VUE_APP_OPERATOR= # Google Service Account credentials in JSON format GOOGLE_APPLICATION_CREDENTIALS= # Spreadsheet ID to send recipients data -VUE_APP_GOOGLE_SPREADSHEET_ID= \ No newline at end of file +VUE_APP_GOOGLE_SPREADSHEET_ID= +# Select the sheet's name to write the data, by default 'Raw' +GOOGLE_SHEET_NAME= \ No newline at end of file diff --git a/vue-app/src/lambda/recipient.js b/vue-app/src/lambda/recipient.js index 0bad9f37b..f4545ea37 100644 --- a/vue-app/src/lambda/recipient.js +++ b/vue-app/src/lambda/recipient.js @@ -1,5 +1,7 @@ import { GoogleSpreadsheet } from 'google-spreadsheet' +const GOOGLE_SHEET_NAME = process.env.GOOGLE_SHEET_NAME || 'Raw' + /** * Creates an object row from a RecipientApplicationData. A row is a key-value * object where the keys are composed by the concatenation of the nested keys. @@ -52,7 +54,7 @@ exports.handler = async function (event) { await doc.useServiceAccountAuth(creds) await doc.loadInfo() - const sheet = doc.sheetsByIndex[0] + const sheet = doc.sheetsByTitle[GOOGLE_SHEET_NAME] const row = recipientToRow(recipient) await sheet.addRow(row)