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 * Returns the cell values
*/ */

View File

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