Add clear functionality to Google Sheet-Node

This commit is contained in:
Jan Oberhauser 2019-11-02 22:29:52 +01:00
parent d6134ec405
commit ac88d25e1b
2 changed files with 49 additions and 0 deletions

View file

@ -45,6 +45,27 @@ export class GoogleSheet {
}
/**
* Clears values from a sheet
*
* @param {string} range
* @returns {Promise<object>}
* @memberof GoogleSheet
*/
async clearData(range: string): Promise<object> {
const client = await this.getAuthenticationClient();
const response = await Sheets.spreadsheets.values.clear(
{
auth: client,
spreadsheetId: this.id,
range,
}
);
return response.data;
}
/**
* Returns the cell values
*/

View file

@ -47,6 +47,11 @@ export class GoogleSheets implements INodeType {
value: 'append',
description: 'Appends the data to a Sheet',
},
{
name: 'Clear',
value: 'clear',
description: 'Clears data from a Sheet',
},
{
name: 'Lookup',
value: 'lookup',
@ -172,6 +177,7 @@ export class GoogleSheets implements INodeType {
hide: {
operation: [
'append',
'clear',
],
rawData: [
true
@ -193,6 +199,9 @@ export class GoogleSheets implements INodeType {
},
displayOptions: {
hide: {
operation: [
'clear',
],
rawData: [
true
],
@ -266,6 +275,16 @@ export class GoogleSheets implements INodeType {
type: 'collection',
placeholder: 'Add Option',
default: {},
displayOptions: {
show: {
operation: [
'append',
'lookup',
'read',
'update',
],
},
},
options: [
{
displayName: 'Return All Matches',
@ -425,6 +444,15 @@ export class GoogleSheets implements INodeType {
// TODO: Should add this data somewhere
// TODO: Should have something like add metadata which does not get passed through
return this.prepareOutputData(items);
} else if (operation === 'clear') {
// ----------------------------------
// clear
// ----------------------------------
await sheet.clearData(range);
const items = this.getInputData();
return this.prepareOutputData(items);
} else if (operation === 'lookup') {
// ----------------------------------