Fix UI and API call for each operations

This commit is contained in:
trojanh 2020-01-29 12:34:52 +05:30
parent 7b50a4bcfd
commit a852af6530
11 changed files with 291 additions and 46 deletions

View file

@ -24,7 +24,7 @@ export const clientOperations = [
description: 'Get data of all clients',
},
],
default: 'create',
default: 'getAll',
description: 'The operation to perform.',
},

View file

@ -1,6 +1,6 @@
import { INodeProperties } from "n8n-workflow";
export const clientOperations = [
export const companyOperations = [
{
displayName: 'Operation',
name: 'operation',

View file

@ -24,7 +24,7 @@ export const contactOperations = [
description: 'Get data of all contacts',
},
],
default: 'create',
default: 'getAll',
description: 'The operation to perform.',
},
@ -115,7 +115,7 @@ export const contactFields = [
/* contact:get */
/* -------------------------------------------------------------------------- */
{
displayName: 'Client Id',
displayName: 'Contact Id',
name: 'id',
type: 'string',
default: '',

View file

@ -0,0 +1,164 @@
import { INodeProperties } from "n8n-workflow";
export const estimateOperations = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
displayOptions: {
show: {
resource: [
'estimate',
],
},
},
options: [
{
name: 'Get',
value: 'get',
description: 'Get data of an estimate',
},
{
name: 'Get All',
value: 'getAll',
description: 'Get data of all estimates',
},
],
default: 'getAll',
description: 'The operation to perform.',
},
] as INodeProperties[];
export const estimateFields = [
/* -------------------------------------------------------------------------- */
/* estimate:getAll */
/* -------------------------------------------------------------------------- */
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
resource: [
'estimate',
],
operation: [
'getAll',
],
},
},
default: false,
description: 'Returns a list of your estimates.',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
resource: [
'estimate',
],
operation: [
'getAll',
],
returnAll: [
false,
],
},
},
typeOptions: {
minValue: 1,
maxValue: 100,
},
default: 100,
description: 'How many results to return.',
},
{
displayName: 'Filters',
name: 'filters',
type: 'collection',
placeholder: 'Add Filter',
default: {},
displayOptions: {
show: {
resource: [
'estimate',
],
operation: [
'getAll',
],
},
},
options: [
{
displayName: 'Client ID',
name: 'client_id',
type: 'string',
default: '',
description: 'Only return time entries belonging to the client with the given ID.',
},
{
displayName: 'Updated Since',
name: 'updated_since',
type: 'string',
default: '',
description: 'Only return time entries that have been updated since the given date and time.',
},
{
displayName: 'From',
name: 'from',
type: 'dateTime',
default: '',
description: 'Only return time entries with a spent_date on or after the given date.',
},
{
displayName: 'To',
name: 'to',
type: 'dateTime',
default: '',
description: 'Only return time entries with a spent_date on or before the given date.',
},
{
displayName: 'State',
name: 'state',
type: 'string',
default: '',
description: 'Only return estimates with a state matching the value provided. Options: draft, sent, accepted, or declined.',
},
{
displayName: 'Page',
name: 'page',
type: 'string',
default: '',
description: 'The page number to use in pagination. For instance, if you make a list request and receive 100 records, your subsequent call can include page=2 to retrieve the next page of the list. (Default: 1)',
}
]
},
/* -------------------------------------------------------------------------- */
/* estimate:get */
/* -------------------------------------------------------------------------- */
{
displayName: 'Estimate Id',
name: 'id',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'get',
],
resource: [
'estimate',
],
},
},
description: 'The ID of the estimate you are retrieving.',
}
] as INodeProperties[];

View file

@ -16,7 +16,7 @@ export const expenseOperations = [
{
name: 'Get',
value: 'get',
description: 'Get data of a expense',
description: 'Get data of an expense',
},
{
name: 'Get All',
@ -24,7 +24,7 @@ export const expenseOperations = [
description: 'Get data of all expenses',
},
],
default: 'create',
default: 'getAll',
description: 'The operation to perform.',
},
@ -157,7 +157,7 @@ export const expenseFields = [
/* expense:get */
/* -------------------------------------------------------------------------- */
{
displayName: 'Client Id',
displayName: 'Expense Id',
name: 'id',
type: 'string',
default: '',

View file

@ -10,6 +10,15 @@ import {
import { harvestApiRequest } from './GenericFunctions';
import { timeEntryOperations, timeEntryFields } from './TimeEntryDescription';
import { clientOperations, clientFields } from './ClientDescription';
import { companyOperations } from './CompanyDescription';
import { contactOperations, contactFields } from './ContactDescription';
import { expenseOperations, expenseFields } from './ExpenseDescription';
import { invoiceOperations, invoiceFields } from './InvoiceDescription';
import { projectOperations, projectFields } from './ProjectDescription';
import { taskOperations, taskFields } from './TaskDescription';
import { userOperations, userFields } from './UserDescription';
import { estimateOperations, estimateFields } from './EstimateDescription';
export class Harvest implements INodeType {
@ -47,33 +56,65 @@ export class Harvest implements INodeType {
name: "Client",
value: "client"
},
{ name: "Project",
value: "project"},
{ name: "Contact",
value: "contact"},
{ name: "Company",
value: "company"},
{ name: "Invoice",
value: "invoice"},
{ name: "Task",
value: "task"},
{ name: "User",
value: "user"},
{ name: "Expense",
value: "expense"},
{ name: "Estimates",
value: "estimate"}
{
name: "Project",
value: "project"
},
{
name: "Contact",
value: "contact"
},
{
name: "Company",
value: "company"
},
{
name: "Invoice",
value: "invoice"
},
{
name: "Task",
value: "task"
},
{
name: "User",
value: "user"
},
{
name: "Expense",
value: "expense"
},
{
name: "Estimates",
value: "estimate"
}
],
default: 'timeEntry',
default: 'user',
description: 'The resource to operate on.',
},
// operations
...clientOperations,
...companyOperations,
...contactOperations,
...estimateOperations,
...expenseOperations,
...invoiceOperations,
...projectOperations,
...taskOperations,
...timeEntryOperations,
...compa
...userOperations,
// fields
...timeEntryFields
...clientFields,
...contactFields,
...estimateFields,
...expenseFields,
...invoiceFields,
...projectFields,
...taskFields,
...timeEntryFields,
...userFields
]
};
@ -292,7 +333,7 @@ export class Harvest implements INodeType {
try {
let responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
returnData.push.apply(returnData, responseData.time_entries as IDataObject[]);
returnData.push.apply(returnData, responseData.clients as IDataObject[]);
} catch (error) {
throw error;
}
@ -334,7 +375,7 @@ export class Harvest implements INodeType {
try {
let responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
returnData.push.apply(returnData, responseData.time_entries as IDataObject[]);
returnData.push.apply(returnData, responseData.projects as IDataObject[]);
} catch (error) {
throw error;
}
@ -376,14 +417,14 @@ export class Harvest implements INodeType {
try {
let responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
returnData.push.apply(returnData, responseData.time_entries as IDataObject[]);
returnData.push.apply(returnData, responseData.users as IDataObject[]);
} catch (error) {
throw error;
}
} else if (operation === 'me') {
// ----------------------------------
// getAll
// me
// ----------------------------------
requestMethod = 'GET';
@ -392,7 +433,7 @@ export class Harvest implements INodeType {
try {
let responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
returnData.push.apply(responseData);
returnData.push(responseData);
} catch (error) {
throw error;
}
@ -434,7 +475,7 @@ export class Harvest implements INodeType {
try {
let responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
returnData.push.apply(returnData, responseData.time_entries as IDataObject[]);
returnData.push.apply(returnData, responseData.contacts as IDataObject[]);
} catch (error) {
throw error;
}
@ -449,8 +490,6 @@ export class Harvest implements INodeType {
// ----------------------------------
requestMethod = 'GET';
const id = this.getNodeParameter('id', i) as string;
endpoint = `company`;
try {
@ -497,7 +536,7 @@ export class Harvest implements INodeType {
try {
let responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
returnData.push.apply(returnData, responseData.time_entries as IDataObject[]);
returnData.push.apply(returnData, responseData.companies as IDataObject[]);
} catch (error) {
throw error;
}
@ -539,7 +578,7 @@ export class Harvest implements INodeType {
try {
let responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
returnData.push.apply(returnData, responseData.time_entries as IDataObject[]);
returnData.push.apply(returnData, responseData.invoices as IDataObject[]);
} catch (error) {
throw error;
}
@ -581,7 +620,49 @@ export class Harvest implements INodeType {
try {
let responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
returnData.push.apply(returnData, responseData.time_entries as IDataObject[]);
returnData.push.apply(returnData, responseData.expenses as IDataObject[]);
} catch (error) {
throw error;
}
} else {
throw new Error(`The resource "${resource}" is not known!`);
}
} else if (resource === 'estimate') {
if (operation === 'get') {
// ----------------------------------
// get
// ----------------------------------
requestMethod = 'GET';
const id = this.getNodeParameter('id', i) as string;
endpoint = `estimates/${id}`;
try {
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
returnData.push(responseData);
} catch (error) {
throw error;
}
} else if (operation === 'getAll') {
// ----------------------------------
// getAll
// ----------------------------------
requestMethod = 'GET';
endpoint = 'estimates';
const additionalFields = this.getNodeParameter('filters', i) as IDataObject;
const limit = this.getNodeParameter('limit', i) as string;
qs.per_page = limit;
Object.assign(qs, additionalFields);
try {
let responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
returnData.push.apply(returnData, responseData.estimates as IDataObject[]);
} catch (error) {
throw error;
}

View file

@ -24,7 +24,7 @@ export const invoiceOperations = [
description: 'Get data of all invoices',
},
],
default: 'create',
default: 'getAll',
description: 'The operation to perform.',
},
@ -168,7 +168,7 @@ export const invoiceFields = [
/* invoice:get */
/* -------------------------------------------------------------------------- */
{
displayName: 'Client Id',
displayName: 'Invoice Id',
name: 'id',
type: 'string',
default: '',

View file

@ -24,7 +24,7 @@ export const projectOperations = [
description: 'Get data of all projects',
},
],
default: 'create',
default: 'getAll',
description: 'The operation to perform.',
},
@ -130,7 +130,7 @@ export const projectFields = [
/* project:get */
/* -------------------------------------------------------------------------- */
{
displayName: 'Client Id',
displayName: 'Project Id',
name: 'id',
type: 'string',
default: '',

View file

@ -24,7 +24,7 @@ export const taskOperations = [
description: 'Get data of all tasks',
},
],
default: 'create',
default: 'getAll',
description: 'The operation to perform.',
},
@ -122,7 +122,7 @@ export const taskFields = [
/* task:get */
/* -------------------------------------------------------------------------- */
{
displayName: 'Client Id',
displayName: 'Task Id',
name: 'id',
type: 'string',
default: '',

View file

@ -59,7 +59,7 @@ export const timeEntryOperations = [
description: 'Update a time entry',
},
],
default: 'create',
default: 'getAll',
description: 'The operation to perform.',
},
] as INodeProperties[];

View file

@ -29,7 +29,7 @@ export const userOperations = [
description: 'Get data of all users',
},
],
default: 'create',
default: 'me',
description: 'The operation to perform.',
},
@ -127,7 +127,7 @@ export const userFields = [
/* user:get */
/* -------------------------------------------------------------------------- */
{
displayName: 'Client Id',
displayName: 'User Id',
name: 'id',
type: 'string',
default: '',