Created
July 23, 2020 18:48
-
-
Save a0viedo/d4b2aea3016fbdaf40ae7038e35a6046 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports.write = async event => { | |
console.log('Starting write function'); | |
if(!event.body) { | |
return formatResponse(400, { message: 'body is missing' }); | |
} | |
const body = JSON.parse(event.body); | |
if(!body.cells || !Array.isArray(body.cells)) { | |
return formatResponse(400, { message: '"cells" should be an array' }) | |
} | |
// load up everything that's necessary to work with cells | |
await spreadsheetAuth(doc); | |
await doc.loadInfo(); | |
const sheet = doc.sheetsByIndex[0]; | |
await sheet.loadCells(); | |
for(const { identifier, content } of body.cells) { | |
const cell = sheet.getCellByA1(identifier); | |
cell.value = content; | |
} | |
await sheet.saveUpdatedCells(); | |
return formatResponse(200, { message: 'Cells saved successfully'}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment