mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
Lint fix on trigger node
This commit is contained in:
parent
aab002c74f
commit
5f4ada49b9
|
@ -81,10 +81,9 @@ export class SeaTableTrigger implements INodeType {
|
||||||
'The name of SeaTable table to access. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
'The name of SeaTable table to access. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'View Name or ID (optional)',
|
displayName: 'View Name or ID',
|
||||||
name: 'viewName',
|
name: 'viewName',
|
||||||
type: 'options',
|
type: 'options',
|
||||||
required: false,
|
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
event: ['newRow', 'updatedRow'],
|
event: ['newRow', 'updatedRow'],
|
||||||
|
@ -95,10 +94,11 @@ export class SeaTableTrigger implements INodeType {
|
||||||
loadOptionsMethod: 'getTableViews',
|
loadOptionsMethod: 'getTableViews',
|
||||||
},
|
},
|
||||||
default: '',
|
default: '',
|
||||||
description: 'The name of SeaTable view to access. Choose from the list, or specify ...',
|
description:
|
||||||
|
'The name of SeaTable view to access. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Signature column',
|
displayName: 'Signature Column Name or ID',
|
||||||
name: 'assetColumn',
|
name: 'assetColumn',
|
||||||
type: 'options',
|
type: 'options',
|
||||||
required: true,
|
required: true,
|
||||||
|
@ -112,15 +112,16 @@ export class SeaTableTrigger implements INodeType {
|
||||||
loadOptionsMethod: 'getSignatureColumns',
|
loadOptionsMethod: 'getSignatureColumns',
|
||||||
},
|
},
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Select the digital-signature column that should be tracked.',
|
description:
|
||||||
|
'Select the digital-signature column that should be tracked. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Simplify output',
|
displayName: 'Simplify',
|
||||||
name: 'simple',
|
name: 'simple',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
default: true,
|
default: true,
|
||||||
description:
|
description:
|
||||||
'Simplified returns only the columns of your base. Non-simplified will return additional columns like _ctime (=creation time), _mtime (=modification time) etc.',
|
'Whether to return a simplified version of the response instead of the raw data',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: '"Fetch Test Event" returns max. three items of the last hour.',
|
displayName: '"Fetch Test Event" returns max. three items of the last hour.',
|
||||||
|
@ -137,8 +138,10 @@ export class SeaTableTrigger implements INodeType {
|
||||||
const webhookData = this.getWorkflowStaticData('node');
|
const webhookData = this.getWorkflowStaticData('node');
|
||||||
const event = this.getNodeParameter('event') as string;
|
const event = this.getNodeParameter('event') as string;
|
||||||
const tableName = this.getNodeParameter('tableName') as string;
|
const tableName = this.getNodeParameter('tableName') as string;
|
||||||
const viewName = (event != 'newAsset' ? this.getNodeParameter('viewName') : '') as string;
|
const viewName = (event !== 'newAsset' ? this.getNodeParameter('viewName') : '') as string;
|
||||||
const assetColumn = (event == 'newAsset' ? this.getNodeParameter('assetColumn') : '') as string;
|
const assetColumn = (
|
||||||
|
event === 'newAsset' ? this.getNodeParameter('assetColumn') : ''
|
||||||
|
) as string;
|
||||||
const simple = this.getNodeParameter('simple') as boolean;
|
const simple = this.getNodeParameter('simple') as boolean;
|
||||||
|
|
||||||
const ctx: ICtx = {};
|
const ctx: ICtx = {};
|
||||||
|
@ -149,24 +152,8 @@ export class SeaTableTrigger implements INodeType {
|
||||||
: (webhookData.lastTimeChecked as string);
|
: (webhookData.lastTimeChecked as string);
|
||||||
const endDate = (webhookData.lastTimeChecked = moment().utc().format());
|
const endDate = (webhookData.lastTimeChecked = moment().utc().format());
|
||||||
|
|
||||||
// this is working, even if the columns _mtime and _ctime have other names. Only relevant for newRow / updatedRow.
|
|
||||||
const filterField = event === 'newRow' ? '_ctime' : '_mtime';
|
const filterField = event === 'newRow' ? '_ctime' : '_mtime';
|
||||||
|
|
||||||
// Difference between getRows and SqlQuery:
|
|
||||||
// ====================
|
|
||||||
|
|
||||||
// getRows (if view is selected)
|
|
||||||
// getRows always gets up to 1.000 rows of the selected view.
|
|
||||||
// getRows delivers only the rows, not the metadata
|
|
||||||
// no possibility to filter for _ctime or _mtime with the API call.
|
|
||||||
// Problems, not yet solved:
|
|
||||||
// if a column is empty, the column is not returned!
|
|
||||||
// view with more than 1.000 rows will not work!
|
|
||||||
|
|
||||||
// SqlQuery (if no view is selected)
|
|
||||||
// SqlQuery returns up to 1.000. WHERE by time and ORDER BY _ctime or _mtime is possible.
|
|
||||||
// SqlQuery returns rows and metadata
|
|
||||||
|
|
||||||
let requestMeta: IGetMetadataResult;
|
let requestMeta: IGetMetadataResult;
|
||||||
let requestRows: IGetRowsResult;
|
let requestRows: IGetRowsResult;
|
||||||
let metadata: IDtableMetadataColumn[] = [];
|
let metadata: IDtableMetadataColumn[] = [];
|
||||||
|
@ -176,7 +163,7 @@ export class SeaTableTrigger implements INodeType {
|
||||||
const limit = this.getMode() === 'manual' ? 3 : 1000;
|
const limit = this.getMode() === 'manual' ? 3 : 1000;
|
||||||
|
|
||||||
// New Signature
|
// New Signature
|
||||||
if (event == 'newAsset') {
|
if (event === 'newAsset') {
|
||||||
const endpoint = '/dtable-db/api/v1/query/{{dtable_uuid}}/';
|
const endpoint = '/dtable-db/api/v1/query/{{dtable_uuid}}/';
|
||||||
sqlResult = await seaTableApiRequest.call(this, ctx, 'POST', endpoint, {
|
sqlResult = await seaTableApiRequest.call(this, ctx, 'POST', endpoint, {
|
||||||
sql: `SELECT _id, _ctime, _mtime, \`${assetColumn}\` FROM ${tableName} WHERE \`${assetColumn}\` IS NOT NULL ORDER BY _mtime DESC LIMIT ${limit}`,
|
sql: `SELECT _id, _ctime, _mtime, \`${assetColumn}\` FROM ${tableName} WHERE \`${assetColumn}\` IS NOT NULL ORDER BY _mtime DESC LIMIT ${limit}`,
|
||||||
|
@ -188,15 +175,13 @@ export class SeaTableTrigger implements INodeType {
|
||||||
const assetColumnType = columnType?.type || null;
|
const assetColumnType = columnType?.type || null;
|
||||||
|
|
||||||
// remove unwanted entries
|
// remove unwanted entries
|
||||||
rows = sqlResult.results.filter(
|
rows = sqlResult.results.filter((obj) => new Date(obj._mtime) > new Date(startDate));
|
||||||
(obj) => new Date(obj['_mtime']) > new Date(startDate),
|
|
||||||
) as IRow[];
|
|
||||||
|
|
||||||
// split the objects into new lines (not necessary for digital-sign)
|
// split the objects into new lines (not necessary for digital-sign)
|
||||||
const newRows: any = [];
|
const newRows: any = [];
|
||||||
for (const row of rows) {
|
for (const row of rows) {
|
||||||
if (assetColumnType === 'digital-sign') {
|
if (assetColumnType === 'digital-sign') {
|
||||||
let signature = (row[assetColumn] as IColumnDigitalSignature) || [];
|
const signature = (row[assetColumn] as IColumnDigitalSignature) || [];
|
||||||
if (signature.sign_time) {
|
if (signature.sign_time) {
|
||||||
if (new Date(signature.sign_time) > new Date(startDate)) {
|
if (new Date(signature.sign_time) > new Date(startDate)) {
|
||||||
newRows.push(signature);
|
newRows.push(signature);
|
||||||
|
@ -223,26 +208,20 @@ export class SeaTableTrigger implements INodeType {
|
||||||
{
|
{
|
||||||
table_name: tableName,
|
table_name: tableName,
|
||||||
view_name: viewName,
|
view_name: viewName,
|
||||||
limit: limit,
|
limit,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
// I need only metadata of the selected table.
|
|
||||||
metadata =
|
metadata =
|
||||||
requestMeta.metadata.tables.find((table) => table.name === tableName)?.columns ?? [];
|
requestMeta.metadata.tables.find((table) => table.name === tableName)?.columns ?? [];
|
||||||
|
|
||||||
// remove unwanted rows that are too old (compare startDate with _ctime or _mtime)
|
// remove unwanted rows that are too old (compare startDate with _ctime or _mtime)
|
||||||
if (this.getMode() === 'manual') {
|
if (this.getMode() === 'manual') {
|
||||||
rows = requestRows.rows as IRow[];
|
rows = requestRows.rows;
|
||||||
} else {
|
} else {
|
||||||
rows = requestRows.rows.filter(
|
rows = requestRows.rows.filter((obj) => new Date(obj[filterField]) > new Date(startDate));
|
||||||
(obj) => new Date(obj[filterField]) > new Date(startDate),
|
|
||||||
) as IRow[];
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
|
||||||
// No view => use SQL-Query
|
|
||||||
else {
|
|
||||||
const endpoint = '/dtable-db/api/v1/query/{{dtable_uuid}}/';
|
const endpoint = '/dtable-db/api/v1/query/{{dtable_uuid}}/';
|
||||||
const sqlQuery = `SELECT * FROM \`${tableName}\` WHERE ${filterField} BETWEEN "${moment(
|
const sqlQuery = `SELECT * FROM \`${tableName}\` WHERE ${filterField} BETWEEN "${moment(
|
||||||
startDate,
|
startDate,
|
||||||
|
@ -254,20 +233,16 @@ export class SeaTableTrigger implements INodeType {
|
||||||
convert_keys: true,
|
convert_keys: true,
|
||||||
});
|
});
|
||||||
metadata = sqlResult.metadata as IDtableMetadataColumn[];
|
metadata = sqlResult.metadata as IDtableMetadataColumn[];
|
||||||
rows = sqlResult.results as IRow[];
|
rows = sqlResult.results;
|
||||||
}
|
}
|
||||||
|
|
||||||
// =========================================
|
const collaboratorsResult: ICollaboratorsResult = await seaTableApiRequest.call(
|
||||||
// => now I have rows and metadata.
|
|
||||||
|
|
||||||
// lets get the collaborators
|
|
||||||
let collaboratorsResult: ICollaboratorsResult = await seaTableApiRequest.call(
|
|
||||||
this,
|
this,
|
||||||
ctx,
|
ctx,
|
||||||
'GET',
|
'GET',
|
||||||
'/dtable-server/api/v1/dtables/{{dtable_uuid}}/related-users/',
|
'/dtable-server/api/v1/dtables/{{dtable_uuid}}/related-users/',
|
||||||
);
|
);
|
||||||
let collaborators: ICollaborator[] = collaboratorsResult.user_list || [];
|
const collaborators: ICollaborator[] = collaboratorsResult.user_list || [];
|
||||||
|
|
||||||
if (Array.isArray(rows) && rows.length > 0) {
|
if (Array.isArray(rows) && rows.length > 0) {
|
||||||
// remove columns starting with _ if simple;
|
// remove columns starting with _ if simple;
|
||||||
|
|
Loading…
Reference in a new issue