Skip to content

Instantly share code, notes, and snippets.

@a0viedo
Created July 23, 2020 18:48
Show Gist options
  • Save a0viedo/d4b2aea3016fbdaf40ae7038e35a6046 to your computer and use it in GitHub Desktop.
Save a0viedo/d4b2aea3016fbdaf40ae7038e35a6046 to your computer and use it in GitHub Desktop.
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