mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
refactor: Format nodes-base package (A-F) (#3800)
* 🔨 prettier formated nodes - A * 🔨 prettier formated nodes - B * ⚡ prettier formated nodes - C * ⚡ prettier formated nodes - D * ⚡ prettier formated nodes - E-F * 🎨 Adjust nodes-base formatting command (#3805) * Format additional files in nodes A-F (#3811) * ⚡ fixes * 🎨 Add Mindee to ignored dirs Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
This commit is contained in:
@@ -1,7 +1,4 @@
|
||||
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
} from 'n8n-core';
|
||||
import { IExecuteFunctions } from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
@@ -13,9 +10,7 @@ import {
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
set,
|
||||
} from 'lodash';
|
||||
import { set } from 'lodash';
|
||||
|
||||
import moment from 'moment-timezone';
|
||||
|
||||
@@ -60,9 +55,7 @@ export class DateTime implements INodeType {
|
||||
name: 'value',
|
||||
displayOptions: {
|
||||
show: {
|
||||
action: [
|
||||
'format',
|
||||
],
|
||||
action: ['format'],
|
||||
},
|
||||
},
|
||||
type: 'string',
|
||||
@@ -78,9 +71,7 @@ export class DateTime implements INodeType {
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
action: [
|
||||
'format',
|
||||
],
|
||||
action: ['format'],
|
||||
},
|
||||
},
|
||||
description: 'Name of the property to which to write the converted date',
|
||||
@@ -90,9 +81,7 @@ export class DateTime implements INodeType {
|
||||
name: 'custom',
|
||||
displayOptions: {
|
||||
show: {
|
||||
action: [
|
||||
'format',
|
||||
],
|
||||
action: ['format'],
|
||||
},
|
||||
},
|
||||
type: 'boolean',
|
||||
@@ -104,12 +93,8 @@ export class DateTime implements INodeType {
|
||||
name: 'toFormat',
|
||||
displayOptions: {
|
||||
show: {
|
||||
action: [
|
||||
'format',
|
||||
],
|
||||
custom: [
|
||||
true,
|
||||
],
|
||||
action: ['format'],
|
||||
custom: [true],
|
||||
},
|
||||
},
|
||||
type: 'string',
|
||||
@@ -123,12 +108,8 @@ export class DateTime implements INodeType {
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
action: [
|
||||
'format',
|
||||
],
|
||||
custom: [
|
||||
false,
|
||||
],
|
||||
action: ['format'],
|
||||
custom: [false],
|
||||
},
|
||||
},
|
||||
// eslint-disable-next-line n8n-nodes-base/node-param-options-type-unsorted-items
|
||||
@@ -177,9 +158,7 @@ export class DateTime implements INodeType {
|
||||
name: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
action: [
|
||||
'format',
|
||||
],
|
||||
action: ['format'],
|
||||
},
|
||||
},
|
||||
type: 'collection',
|
||||
@@ -201,7 +180,8 @@ export class DateTime implements INodeType {
|
||||
loadOptionsMethod: 'getTimezones',
|
||||
},
|
||||
default: 'UTC',
|
||||
description: 'The timezone to convert from. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
description:
|
||||
'The timezone to convert from. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
},
|
||||
{
|
||||
displayName: 'To Timezone Name or ID',
|
||||
@@ -211,7 +191,8 @@ export class DateTime implements INodeType {
|
||||
loadOptionsMethod: 'getTimezones',
|
||||
},
|
||||
default: 'UTC',
|
||||
description: 'The timezone to convert to. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
description:
|
||||
'The timezone to convert to. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -220,9 +201,7 @@ export class DateTime implements INodeType {
|
||||
name: 'value',
|
||||
displayOptions: {
|
||||
show: {
|
||||
action: [
|
||||
'calculate',
|
||||
],
|
||||
action: ['calculate'],
|
||||
},
|
||||
},
|
||||
type: 'string',
|
||||
@@ -235,9 +214,7 @@ export class DateTime implements INodeType {
|
||||
name: 'operation',
|
||||
displayOptions: {
|
||||
show: {
|
||||
action: [
|
||||
'calculate',
|
||||
],
|
||||
action: ['calculate'],
|
||||
},
|
||||
},
|
||||
type: 'options',
|
||||
@@ -264,9 +241,7 @@ export class DateTime implements INodeType {
|
||||
name: 'duration',
|
||||
displayOptions: {
|
||||
show: {
|
||||
action: [
|
||||
'calculate',
|
||||
],
|
||||
action: ['calculate'],
|
||||
},
|
||||
},
|
||||
type: 'number',
|
||||
@@ -283,9 +258,7 @@ export class DateTime implements INodeType {
|
||||
description: 'Time unit for Duration parameter above',
|
||||
displayOptions: {
|
||||
show: {
|
||||
action: [
|
||||
'calculate',
|
||||
],
|
||||
action: ['calculate'],
|
||||
},
|
||||
},
|
||||
type: 'options',
|
||||
@@ -339,9 +312,7 @@ export class DateTime implements INodeType {
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
action: [
|
||||
'calculate',
|
||||
],
|
||||
action: ['calculate'],
|
||||
},
|
||||
},
|
||||
description: 'Name of the output property to which to write the converted date',
|
||||
@@ -354,9 +325,7 @@ export class DateTime implements INodeType {
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
action: [
|
||||
'calculate',
|
||||
],
|
||||
action: ['calculate'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
@@ -365,7 +334,8 @@ export class DateTime implements INodeType {
|
||||
name: 'fromFormat',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Format for parsing the value as a date. If unrecognized, specify the <a href="https://docs.n8n.io/nodes/n8n-nodes-base.dateTime/#faqs">format</a> for the value.',
|
||||
description:
|
||||
'Format for parsing the value as a date. If unrecognized, specify the <a href="https://docs.n8n.io/nodes/n8n-nodes-base.dateTime/#faqs">format</a> for the value.',
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -401,7 +371,6 @@ export class DateTime implements INodeType {
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
try {
|
||||
|
||||
const action = this.getNodeParameter('action', 0) as string;
|
||||
item = items[i];
|
||||
|
||||
@@ -415,8 +384,15 @@ export class DateTime implements INodeType {
|
||||
if (currentDate === undefined) {
|
||||
continue;
|
||||
}
|
||||
if (options.fromFormat === undefined && !moment(currentDate as string | number).isValid()) {
|
||||
throw new NodeOperationError(this.getNode(), 'The date input format could not be recognized. Please set the "From Format" field', { itemIndex: i });
|
||||
if (
|
||||
options.fromFormat === undefined &&
|
||||
!moment(currentDate as string | number).isValid()
|
||||
) {
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'The date input format could not be recognized. Please set the "From Format" field',
|
||||
{ itemIndex: i },
|
||||
);
|
||||
}
|
||||
|
||||
if (Number.isInteger(currentDate as unknown as number)) {
|
||||
@@ -425,7 +401,11 @@ export class DateTime implements INodeType {
|
||||
if (options.fromTimezone || options.toTimezone) {
|
||||
const fromTimezone = options.fromTimezone || workflowTimezone;
|
||||
if (options.fromFormat) {
|
||||
newDate = moment.tz(currentDate as string, options.fromFormat as string, fromTimezone as string);
|
||||
newDate = moment.tz(
|
||||
currentDate as string,
|
||||
options.fromFormat as string,
|
||||
fromTimezone as string,
|
||||
);
|
||||
} else {
|
||||
newDate = moment.tz(currentDate as string, fromTimezone as string);
|
||||
}
|
||||
@@ -442,7 +422,7 @@ export class DateTime implements INodeType {
|
||||
// If either a source or a target timezone got defined the
|
||||
// timezone of the date has to be changed. If a target-timezone
|
||||
// is set use it else fall back to workflow timezone.
|
||||
newDate = newDate.tz(options.toTimezone as string || workflowTimezone);
|
||||
newDate = newDate.tz((options.toTimezone as string) || workflowTimezone);
|
||||
}
|
||||
|
||||
newDate = newDate.format(toFormat);
|
||||
@@ -476,7 +456,6 @@ export class DateTime implements INodeType {
|
||||
}
|
||||
|
||||
if (action === 'calculate') {
|
||||
|
||||
const dateValue = this.getNodeParameter('value', i) as string;
|
||||
const operation = this.getNodeParameter('operation', i) as 'add' | 'subtract';
|
||||
const duration = this.getNodeParameter('duration', i) as number;
|
||||
@@ -519,7 +498,6 @@ export class DateTime implements INodeType {
|
||||
|
||||
returnData.push(newItem);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({
|
||||
@@ -544,20 +522,29 @@ function parseDateByFormat(this: IExecuteFunctions, value: string, fromFormat: s
|
||||
const date = moment(value, fromFormat, true);
|
||||
if (moment(date).isValid()) return date;
|
||||
|
||||
throw new NodeOperationError(this.getNode(), 'Date input cannot be parsed. Please recheck the value and the "From Format" field.');
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'Date input cannot be parsed. Please recheck the value and the "From Format" field.',
|
||||
);
|
||||
}
|
||||
|
||||
function parseDateByDefault(this: IExecuteFunctions, value: string) {
|
||||
const isoValue = getIsoValue.call(this, value);
|
||||
if (moment(isoValue).isValid()) return moment(isoValue);
|
||||
|
||||
throw new NodeOperationError(this.getNode(), 'Unrecognized date input. Please specify a format in the "From Format" field.');
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'Unrecognized date input. Please specify a format in the "From Format" field.',
|
||||
);
|
||||
}
|
||||
|
||||
function getIsoValue(this: IExecuteFunctions, value: string) {
|
||||
try {
|
||||
return new Date(value).toISOString(); // may throw due to unpredictable input
|
||||
} catch (error) {
|
||||
throw new NodeOperationError(this.getNode(), 'Unrecognized date input. Please specify a format in the "From Format" field.');
|
||||
throw new NodeOperationError(
|
||||
this.getNode(),
|
||||
'Unrecognized date input. Please specify a format in the "From Format" field.',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user