n8n-vikunja-nodes/nodes/Vikunja/Vikunja.node.ts

94 lines
2.1 KiB
TypeScript
Raw Normal View History

import {
ILoadOptionsFunctions,
INodeListSearchResult,
INodeType,
2023-10-24 14:05:41 +00:00
INodeTypeDescription,
2023-10-24 17:25:41 +00:00
} from 'n8n-workflow';
2023-10-23 11:38:52 +00:00
2023-10-24 17:25:41 +00:00
import { taskProperties } from './properties/Task';
import { projectProperties } from './properties/Project';
import { labelProperties } from './properties/Label';
import { searchAndMap } from './helper';
import { webhookProperties } from './properties/Webhook';
import { teamProperties } from './properties/Team';
2023-10-23 11:38:52 +00:00
export class Vikunja implements INodeType {
description: INodeTypeDescription = {
displayName: 'Vikunja',
name: 'Vikunja',
icon: 'file:vikunja.svg',
group: ['transform'],
version: 1,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
2023-10-24 17:25:41 +00:00
description: "Get data from Vikunja's API",
2023-10-23 11:38:52 +00:00
defaults: {
name: 'Vikunja',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'vikunjaApi',
required: true,
},
],
requestDefaults: {
2023-10-24 09:36:51 +00:00
baseURL: '={{$credentials.apiUrl.replace(new RegExp("/$"), "")}}',
2023-10-23 11:38:52 +00:00
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
},
properties: [
{
displayName: 'Resource',
name: 'resource',
type: 'options',
noDataExpression: true,
options: [
{
2023-10-24 17:25:41 +00:00
name: 'Label',
value: 'label',
2023-10-23 11:38:52 +00:00
},
{
name: 'Project',
value: 'project',
},
2023-10-24 15:01:39 +00:00
{
2023-10-24 17:25:41 +00:00
name: 'Task',
value: 'task',
2023-10-24 15:17:34 +00:00
},
2023-10-24 15:37:35 +00:00
{
name: 'Team',
value: 'team',
},
2023-10-24 17:25:41 +00:00
{
name: 'Webhook',
value: 'webhook',
},
2023-10-23 11:38:52 +00:00
],
default: 'task',
},
...taskProperties,
...projectProperties,
...labelProperties,
2023-10-24 15:17:34 +00:00
...webhookProperties,
2023-10-24 15:37:35 +00:00
...teamProperties,
2023-10-23 11:38:52 +00:00
],
2023-10-24 17:25:41 +00:00
};
2023-10-23 11:38:52 +00:00
methods = {
listSearch: {
2023-10-24 14:05:41 +00:00
searchProjects(this: ILoadOptionsFunctions): Promise<INodeListSearchResult> {
2023-10-24 17:25:41 +00:00
return searchAndMap(this, '/projects');
},
2023-10-24 11:22:37 +00:00
async searchLabels(this: ILoadOptionsFunctions): Promise<INodeListSearchResult> {
2023-10-24 17:25:41 +00:00
return searchAndMap(this, '/labels');
2023-10-24 14:05:41 +00:00
},
async searchTeams(this: ILoadOptionsFunctions): Promise<INodeListSearchResult> {
2023-10-24 17:25:41 +00:00
return searchAndMap(this, '/teams', 'name');
2023-10-24 11:22:37 +00:00
},
2023-10-24 10:52:21 +00:00
},
2023-10-24 17:25:41 +00:00
};
}