2023-01-27 03:22:44 -08:00
import type { INodeProperties } from 'n8n-workflow' ;
2022-08-30 02:25:06 -07:00
2022-11-22 04:43:28 -08:00
import {
dueDatePreSendAction ,
taskPostReceiceAction ,
taskUpdatePreSendAction ,
} from '../GenericFunctions' ;
2022-08-30 02:25:06 -07:00
export const taskOperations : INodeProperties [ ] = [
{
displayName : 'Operation' ,
name : 'operation' ,
type : 'options' ,
noDataExpression : true ,
displayOptions : {
show : {
resource : [ 'task' ] ,
} ,
} ,
options : [
{
name : 'Create' ,
value : 'create' ,
routing : {
request : {
method : 'POST' ,
2024-06-03 02:09:05 -07:00
url : '=/contacts/{{$parameter.contactId}}/tasks/' ,
2022-08-30 02:25:06 -07:00
} ,
output : {
postReceive : [ taskPostReceiceAction ] ,
} ,
} ,
action : 'Create a task' ,
} ,
{
name : 'Delete' ,
value : 'delete' ,
routing : {
request : {
method : 'DELETE' ,
2024-06-03 02:09:05 -07:00
url : '=/contacts/{{$parameter.contactId}}/tasks/{{$parameter.taskId}}/' ,
2022-08-30 02:25:06 -07:00
} ,
output : {
postReceive : [
{
type : 'set' ,
properties : {
value : '={{ { "success": true } }}' ,
} ,
} ,
] ,
} ,
} ,
action : 'Delete a task' ,
} ,
{
name : 'Get' ,
value : 'get' ,
routing : {
request : {
method : 'GET' ,
2024-06-03 02:09:05 -07:00
url : '=/contacts/{{$parameter.contactId}}/tasks/{{$parameter.taskId}}/' ,
2022-08-30 02:25:06 -07:00
} ,
output : {
postReceive : [ taskPostReceiceAction ] ,
} ,
} ,
action : 'Get a task' ,
} ,
{
2022-09-07 07:51:14 -07:00
name : 'Get Many' ,
2022-08-30 02:25:06 -07:00
value : 'getAll' ,
routing : {
request : {
method : 'GET' ,
2024-06-03 02:09:05 -07:00
url : '=/contacts/{{$parameter.contactId}}/tasks/' ,
2022-08-30 02:25:06 -07:00
} ,
output : {
postReceive : [
{
type : 'rootProperty' ,
properties : {
property : 'tasks' ,
} ,
} ,
taskPostReceiceAction ,
] ,
} ,
} ,
2022-09-08 08:10:13 -07:00
action : 'Get many tasks' ,
2022-08-30 02:25:06 -07:00
} ,
{
name : 'Update' ,
value : 'update' ,
routing : {
request : {
method : 'PUT' ,
2024-06-03 02:09:05 -07:00
url : '=/contacts/{{$parameter.contactId}}/tasks/{{$parameter.taskId}}/' ,
2022-08-30 02:25:06 -07:00
} ,
send : {
preSend : [ taskUpdatePreSendAction ] ,
} ,
output : {
postReceive : [ taskPostReceiceAction ] ,
} ,
} ,
action : 'Update a task' ,
} ,
] ,
default : 'create' ,
} ,
] ;
const createProperties : INodeProperties [ ] = [
{
2024-06-03 02:09:05 -07:00
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-wrong-for-dynamic-options
displayName : 'Contact Email or ID' ,
2022-08-30 02:25:06 -07:00
name : 'contactId' ,
2024-06-03 02:09:05 -07:00
type : 'options' ,
typeOptions : {
loadOptionsMethod : 'getContacts' ,
} ,
2022-08-30 02:25:06 -07:00
displayOptions : {
show : {
resource : [ 'task' ] ,
operation : [ 'create' ] ,
} ,
} ,
default : '' ,
required : true ,
2024-06-03 02:09:05 -07:00
description :
'Contact the task belongs to. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.' ,
2022-08-30 02:25:06 -07:00
} ,
{
displayName : 'Title' ,
name : 'title' ,
type : 'string' ,
required : true ,
default : '' ,
displayOptions : {
show : {
resource : [ 'task' ] ,
operation : [ 'create' ] ,
} ,
} ,
routing : {
send : {
type : 'body' ,
property : 'title' ,
} ,
} ,
} ,
{
displayName : 'Due Date' ,
name : 'dueDate' ,
type : 'dateTime' ,
required : true ,
default : '' ,
displayOptions : {
show : {
resource : [ 'task' ] ,
operation : [ 'create' ] ,
} ,
} ,
routing : {
send : {
type : 'body' ,
property : 'dueDate' ,
preSend : [ dueDatePreSendAction ] ,
} ,
} ,
} ,
2024-06-03 02:09:05 -07:00
{
displayName : 'Completed' ,
name : 'completed' ,
type : 'boolean' ,
required : true ,
default : false ,
displayOptions : {
show : {
resource : [ 'task' ] ,
operation : [ 'create' ] ,
} ,
} ,
routing : {
send : {
type : 'body' ,
property : 'completed' ,
} ,
} ,
} ,
2022-08-30 02:25:06 -07:00
{
displayName : 'Additional Fields' ,
name : 'additionalFields' ,
type : 'collection' ,
placeholder : 'Add Field' ,
default : { } ,
displayOptions : {
show : {
resource : [ 'task' ] ,
operation : [ 'create' ] ,
} ,
} ,
options : [
{
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-wrong-for-dynamic-options
displayName : 'Assigned To' ,
name : 'assignedTo' ,
type : 'options' ,
default : '' ,
description :
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>' ,
typeOptions : {
loadOptionsMethod : 'getUsers' ,
} ,
routing : {
send : {
type : 'body' ,
property : 'assignedTo' ,
} ,
} ,
} ,
{
2024-06-03 02:09:05 -07:00
displayName : 'Body' ,
name : 'body' ,
2022-08-30 02:25:06 -07:00
type : 'string' ,
default : '' ,
routing : {
send : {
type : 'body' ,
2024-06-03 02:09:05 -07:00
property : 'body' ,
2022-08-30 02:25:06 -07:00
} ,
} ,
} ,
] ,
} ,
] ;
const deleteProperties : INodeProperties [ ] = [
{
2024-06-03 02:09:05 -07:00
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-wrong-for-dynamic-options
displayName : 'Contact Email or ID' ,
2022-08-30 02:25:06 -07:00
name : 'contactId' ,
2024-06-03 02:09:05 -07:00
type : 'options' ,
typeOptions : {
loadOptionsMethod : 'getContacts' ,
} ,
2022-08-30 02:25:06 -07:00
displayOptions : {
show : {
resource : [ 'task' ] ,
operation : [ 'delete' ] ,
} ,
} ,
default : '' ,
required : true ,
2024-06-03 02:09:05 -07:00
description :
'Contact the task belongs to. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.' ,
2022-08-30 02:25:06 -07:00
} ,
{
displayName : 'Task ID' ,
name : 'taskId' ,
type : 'string' ,
required : true ,
displayOptions : {
show : {
resource : [ 'task' ] ,
operation : [ 'delete' ] ,
} ,
} ,
default : '' ,
} ,
] ;
const getProperties : INodeProperties [ ] = [
{
2024-06-03 02:09:05 -07:00
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-wrong-for-dynamic-options
displayName : 'Contact Email or ID' ,
2022-08-30 02:25:06 -07:00
name : 'contactId' ,
2024-06-03 02:09:05 -07:00
type : 'options' ,
typeOptions : {
loadOptionsMethod : 'getContacts' ,
} ,
2022-08-30 02:25:06 -07:00
displayOptions : {
show : {
resource : [ 'task' ] ,
operation : [ 'get' ] ,
} ,
} ,
default : '' ,
required : true ,
2024-06-03 02:09:05 -07:00
description :
'Contact the task belongs to. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.' ,
2022-08-30 02:25:06 -07:00
} ,
{
displayName : 'Task ID' ,
name : 'taskId' ,
type : 'string' ,
required : true ,
displayOptions : {
show : {
resource : [ 'task' ] ,
operation : [ 'get' ] ,
} ,
} ,
default : '' ,
} ,
] ;
const getAllProperties : INodeProperties [ ] = [
{
2024-06-03 02:09:05 -07:00
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-wrong-for-dynamic-options
displayName : 'Contact Email or ID' ,
2022-08-30 02:25:06 -07:00
name : 'contactId' ,
2024-06-03 02:09:05 -07:00
type : 'options' ,
typeOptions : {
loadOptionsMethod : 'getContacts' ,
} ,
2022-08-30 02:25:06 -07:00
displayOptions : {
show : {
resource : [ 'task' ] ,
operation : [ 'getAll' ] ,
} ,
} ,
default : '' ,
required : true ,
2024-06-03 02:09:05 -07:00
description :
'Contact the task belongs to. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.' ,
2022-08-30 02:25:06 -07:00
} ,
{
displayName : 'Return All' ,
name : 'returnAll' ,
type : 'boolean' ,
displayOptions : {
show : {
resource : [ 'task' ] ,
operation : [ 'getAll' ] ,
} ,
} ,
default : false ,
description : 'Whether to return all results or only up to a given limit' ,
} ,
{
displayName : 'Limit' ,
name : 'limit' ,
type : 'number' ,
displayOptions : {
show : {
resource : [ 'task' ] ,
operation : [ 'getAll' ] ,
returnAll : [ false ] ,
} ,
} ,
typeOptions : {
minValue : 1 ,
maxValue : 100 ,
} ,
default : 20 ,
routing : {
send : {
type : 'query' ,
property : 'limit' ,
} ,
} ,
description : 'Max number of results to return' ,
} ,
] ;
const updateProperties : INodeProperties [ ] = [
{
2024-06-03 02:09:05 -07:00
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-wrong-for-dynamic-options
displayName : 'Contact Email or ID' ,
2022-08-30 02:25:06 -07:00
name : 'contactId' ,
2024-06-03 02:09:05 -07:00
type : 'options' ,
typeOptions : {
loadOptionsMethod : 'getContacts' ,
} ,
2022-08-30 02:25:06 -07:00
displayOptions : {
show : {
resource : [ 'task' ] ,
operation : [ 'update' ] ,
} ,
} ,
default : '' ,
required : true ,
2024-06-03 02:09:05 -07:00
description :
'Contact the task belongs to. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.' ,
2022-08-30 02:25:06 -07:00
} ,
{
displayName : 'Task ID' ,
name : 'taskId' ,
type : 'string' ,
displayOptions : {
show : {
resource : [ 'task' ] ,
operation : [ 'update' ] ,
} ,
} ,
default : '' ,
required : true ,
} ,
{
displayName : 'Update Fields' ,
name : 'updateFields' ,
type : 'collection' ,
placeholder : 'Add Field' ,
default : { } ,
displayOptions : {
show : {
resource : [ 'task' ] ,
operation : [ 'update' ] ,
} ,
} ,
options : [
{
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-wrong-for-dynamic-options
displayName : 'Assigned To' ,
name : 'assignedTo' ,
type : 'options' ,
default : '' ,
description :
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>' ,
typeOptions : {
loadOptionsMethod : 'getUsers' ,
} ,
routing : {
send : {
type : 'body' ,
property : 'assignedTo' ,
} ,
} ,
} ,
{
2024-06-03 02:09:05 -07:00
displayName : 'Completed' ,
name : 'completed' ,
type : 'boolean' ,
default : false ,
2022-08-30 02:25:06 -07:00
routing : {
send : {
type : 'body' ,
2024-06-03 02:09:05 -07:00
property : 'completed' ,
2022-08-30 02:25:06 -07:00
} ,
} ,
} ,
{
2024-06-03 02:09:05 -07:00
displayName : 'Body' ,
name : 'body' ,
type : 'string' ,
2022-08-30 02:25:06 -07:00
default : '' ,
routing : {
send : {
type : 'body' ,
2024-06-03 02:09:05 -07:00
property : 'body' ,
2022-08-30 02:25:06 -07:00
} ,
} ,
} ,
{
2024-06-03 02:09:05 -07:00
displayName : 'Due Date' ,
name : 'dueDate' ,
type : 'dateTime' ,
default : '' ,
2022-08-30 02:25:06 -07:00
routing : {
send : {
type : 'body' ,
2024-06-03 02:09:05 -07:00
property : 'dueDate' ,
preSend : [ dueDatePreSendAction ] ,
2022-08-30 02:25:06 -07:00
} ,
} ,
} ,
{
displayName : 'Title' ,
name : 'title' ,
type : 'string' ,
default : '' ,
routing : {
send : {
type : 'body' ,
property : 'title' ,
} ,
} ,
} ,
] ,
} ,
] ;
export const taskFields : INodeProperties [ ] = [
. . . createProperties ,
. . . updateProperties ,
. . . deleteProperties ,
. . . getProperties ,
. . . getAllProperties ,
] ;