Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Reduce data when getting bookings
Browse files Browse the repository at this point in the history
  • Loading branch information
flenny committed May 10, 2023
1 parent 529de67 commit 27d4298
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function getBookings(reference) {
PropertiesService.getScriptProperties().getProperty('SPREADSHEET_ID'))

return Object
.values(JSON.parse(getDataFromSheet(spreadsheet, BOOKINGS_SHEET_NAME)))
.values(JSON.parse(getDataFromSheet(spreadsheet, BOOKINGS_SHEET_NAME, true)))
.filter(booking => booking?.find(entry => entry === reference))
}
catch (error) { throw error }
Expand Down Expand Up @@ -212,12 +212,14 @@ function processForm(formObject) {
finally { lock.releaseLock() }
}

const getDataFromSheet = (spreadsheet, sheetName) => {
const getDataFromSheet = (spreadsheet, sheetName, ommitLastColumn) => {
const sheet = spreadsheet.getSheetByName(sheetName)
let numRows = sheet.getLastRow() - 1
if (numRows === 0) numRows = 1
let numColumns = sheet.getLastColumn()
if (ommitLastColumn) numColumns = numColumns - 1
return JSON.stringify(
sheet.getRange(2, 1, numRows, sheet.getLastColumn()).getValues()
sheet.getRange(2, 1, numRows, numColumns).getValues()
)
}

Expand Down

0 comments on commit 27d4298

Please sign in to comment.