Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[N8N-2888] SeaTable: Add time zone to credentials, make trigger query tz aware #2726

Merged
merged 4 commits into from
Mar 13, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/nodes-base/credentials/SeaTableApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import {
ICredentialType,
INodeProperties,
INodePropertyOptions,
} from 'n8n-workflow';

import * as moment from 'moment-timezone';

// Get options for timezones
const timezones: INodePropertyOptions[] = moment.tz.countries().reduce( (timezones: INodePropertyOptions[], country: string) => {
const zonesForCountry = moment.tz.zonesForCountry(country).map(zone => ({value: zone, name: zone}));
return timezones.concat(zonesForCountry);
}, []);

export class SeaTableApi implements ICredentialType {
name = 'seaTableApi';
displayName = 'SeaTable API';
Expand Down Expand Up @@ -44,5 +53,14 @@ export class SeaTableApi implements ICredentialType {
type: 'string',
default: '',
},
{
displayName: 'Time Zone',
name: 'timezone',
type: 'options',
default: 'Europe/Berlin',
options: [
...timezones,
],
},
];
}
17 changes: 12 additions & 5 deletions packages/nodes-base/nodes/SeaTable/SeaTableTrigger.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
} from 'n8n-core';

import {
IDataObject,
ILoadOptionsFunctions,
INodeExecutionData,
INodePropertyOptions,
Expand Down Expand Up @@ -108,13 +109,12 @@ export class SeaTableTrigger implements INodeType {
const simple = this.getNodeParameter('simple') as boolean;
const event = this.getNodeParameter('event') as string;
const ctx: ICtx = {};
const credentials = await this.getCredentials('seaTableApi') as IDataObject;

const timezone = credentials.timezone as string || 'Europe/Berlin';
const now = moment().utc().format();

const startDate = webhookData.lastTimeChecked as string || now;

const endDate = now;

webhookData.lastTimeChecked = endDate;

let rows;
Expand All @@ -126,8 +126,15 @@ export class SeaTableTrigger implements INodeType {
if (this.getMode() === 'manual') {
rows = await seaTableApiRequest.call(this, ctx, 'POST', endpoint, { sql: `SELECT * FROM ${tableName} LIMIT 1` }) as IRowResponse;
} else {
rows = await seaTableApiRequest.call(this, ctx, 'POST', endpoint,
{ sql: `SELECT * FROM ${tableName} WHERE ${filterField} BETWEEN "${moment(startDate).utc().format('YYYY-MM-D HH:mm:ss')}" AND "${moment(endDate).utc().format('YYYY-MM-D HH:mm:ss')}"` }) as IRowResponse;
rows = (await seaTableApiRequest.call(this, ctx, 'POST', endpoint, {
sql: `SELECT * FROM ${tableName}
WHERE ${filterField} BETWEEN "${moment(startDate)
.tz(timezone)
.format('YYYY-MM-D HH:mm:ss')}"
AND "${moment(endDate)
.tz(timezone)
.format('YYYY-MM-D HH:mm:ss')}"`,
})) as IRowResponse;
}

let response;
Expand Down