Refactor time entry and user

This commit is contained in:
trojanh
2020-01-31 19:02:14 +05:30
parent b4394ec122
commit 9ff78410ef
3 changed files with 38 additions and 77 deletions

View File

@@ -107,7 +107,7 @@ export class Harvest implements INodeType {
},
{
name: 'Time Entries',
value: 'timeEntry',
value: 'time_entries',
},
{
name: 'User',
@@ -161,7 +161,7 @@ export class Harvest implements INodeType {
body = {};
qs = {};
if (resource === 'timeEntry') {
if (resource === 'time_entries') {
if (operation === 'get') {
// ----------------------------------
// get
@@ -170,7 +170,7 @@ export class Harvest implements INodeType {
requestMethod = 'GET';
const id = this.getNodeParameter('id', i) as string;
endpoint = `time_entries/${id}`;
endpoint = `${resource}/${id}`;
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
returnData.push(responseData);
@@ -179,7 +179,7 @@ export class Harvest implements INodeType {
// ----------------------------------
// getAll
// ----------------------------------
const responseData: IDataObject[] = await getAllResource.call(this, 'time_entries', i);
const responseData: IDataObject[] = await getAllResource.call(this, resource, i);
returnData.push.apply(returnData, responseData);
} else if (operation === 'createByStartEnd') {
@@ -188,7 +188,7 @@ export class Harvest implements INodeType {
// ----------------------------------
requestMethod = 'POST';
endpoint = 'time_entries';
endpoint = resource;
body.project_id = this.getNodeParameter('projectId', i) as string;
body.task_id = this.getNodeParameter('taskId', i) as string;
@@ -206,7 +206,7 @@ export class Harvest implements INodeType {
// ----------------------------------
requestMethod = 'POST';
endpoint = 'time_entries';
endpoint = resource;
body.project_id = this.getNodeParameter('projectId', i) as string;
body.task_id = this.getNodeParameter('taskId', i) as string;
@@ -225,7 +225,7 @@ export class Harvest implements INodeType {
requestMethod = 'DELETE';
const id = this.getNodeParameter('id', i) as string;
endpoint = `time_entries/${id}`;
endpoint = `${resource}/${id}`;
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
returnData.push(responseData);
@@ -236,7 +236,7 @@ export class Harvest implements INodeType {
requestMethod = 'DELETE';
const id = this.getNodeParameter('id', i) as string;
endpoint = `time_entries/${id}/external_reference`;
endpoint = `${resource}/${id}/external_reference`;
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
returnData.push(responseData);
@@ -248,7 +248,7 @@ export class Harvest implements INodeType {
requestMethod = 'PATCH';
const id = this.getNodeParameter('id', i) as string;
endpoint = `time_entries/${id}/restart`;
endpoint = `${resource}/${id}/restart`;
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
returnData.push(responseData);
@@ -260,7 +260,7 @@ export class Harvest implements INodeType {
requestMethod = 'PATCH';
const id = this.getNodeParameter('id', i) as string;
endpoint = `time_entries/${id}/stop`;
endpoint = `${resource}/${id}/stop`;
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
returnData.push(responseData);
@@ -272,7 +272,7 @@ export class Harvest implements INodeType {
requestMethod = 'PATCH';
const id = this.getNodeParameter('id', i) as string;
endpoint = `time_entries/${id}`;
endpoint = `${resource}/${id}`;
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
@@ -397,9 +397,10 @@ export class Harvest implements INodeType {
requestMethod = 'POST';
endpoint = resource;
['first_name', 'last_name', 'email'].forEach(val => {
body[val] = this.getNodeParameter(val, i) as string;
})
body.first_name = this.getNodeParameter('first_name', i) as string;
body.last_name = this.getNodeParameter('last_name', i) as string;
body.email = this.getNodeParameter('email', i) as string;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
@@ -416,8 +417,8 @@ export class Harvest implements INodeType {
requestMethod = 'POST';
endpoint = resource;
const additionalFields = this.getNodeParameter('updateFields', i) as IDataObject;
Object.assign(body, additionalFields);
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
Object.assign(qs, updateFields);
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint, body);
returnData.push(responseData);

View File

@@ -1,5 +1,5 @@
import { INodeProperties } from "n8n-workflow";
export const resource = [ 'time_entries' ]
export const timeEntryOperations = [
{
displayName: 'Operation',
@@ -7,9 +7,7 @@ export const timeEntryOperations = [
type: 'options',
displayOptions: {
show: {
resource: [
'timeEntry',
],
resource,
},
},
options: [
@@ -75,9 +73,7 @@ export const timeEntryFields = [
type: 'boolean',
displayOptions: {
show: {
resource: [
'timeEntry',
],
resource,
operation: [
'getAll',
],
@@ -92,9 +88,7 @@ export const timeEntryFields = [
type: 'number',
displayOptions: {
show: {
resource: [
'timeEntry',
],
resource,
operation: [
'getAll',
],
@@ -118,9 +112,7 @@ export const timeEntryFields = [
default: {},
displayOptions: {
show: {
resource: [
'timeEntry',
],
resource,
operation: [
'getAll',
],
@@ -203,9 +195,7 @@ export const timeEntryFields = [
operation: [
'get',
],
resource: [
'timeEntry',
],
resource,
},
},
description: 'The ID of the time entry you are retrieving.',
@@ -225,9 +215,7 @@ export const timeEntryFields = [
operation: [
'delete',
],
resource: [
'timeEntry',
],
resource,
},
},
description: 'The ID of the time entry you are deleting.',
@@ -247,9 +235,7 @@ export const timeEntryFields = [
operation: [
'deleteExternal',
],
resource: [
'timeEntry',
],
resource,
},
},
description: 'The ID of the time entry whose external reference you are deleting.',
@@ -269,9 +255,7 @@ export const timeEntryFields = [
operation: [
'stopTime',
],
resource: [
'timeEntry',
],
resource,
},
},
description: 'Stop a running time entry. Stopping a time entry is only possible if its currently running.',
@@ -291,9 +275,7 @@ export const timeEntryFields = [
operation: [
'restartTime',
],
resource: [
'timeEntry',
],
resource,
},
},
description: 'Restart a stopped time entry. Restarting a time entry is only possible if it isnt currently running.',
@@ -313,9 +295,7 @@ export const timeEntryFields = [
operation: [
'update',
],
resource: [
'timeEntry',
],
resource,
},
},
description: 'The ID of the time entry to update.',
@@ -330,9 +310,7 @@ export const timeEntryFields = [
operation: [
'update',
],
resource: [
'timeEntry',
],
resource,
},
},
default: {},
@@ -385,9 +363,7 @@ export const timeEntryFields = [
operation: [
'createByDuration',
],
resource: [
'timeEntry',
],
resource,
},
},
default: '',
@@ -403,9 +379,7 @@ export const timeEntryFields = [
operation: [
'createByDuration',
],
resource: [
'timeEntry',
],
resource,
},
},
default: '',
@@ -421,9 +395,7 @@ export const timeEntryFields = [
operation: [
'createByDuration',
],
resource: [
'timeEntry',
],
resource,
},
},
default: '',
@@ -440,9 +412,7 @@ export const timeEntryFields = [
operation: [
'createByDuration',
],
resource: [
'timeEntry',
],
resource,
},
},
default: {},
@@ -486,9 +456,7 @@ export const timeEntryFields = [
operation: [
'createByStartEnd',
],
resource: [
'timeEntry',
],
resource,
},
},
default: '',
@@ -504,9 +472,7 @@ export const timeEntryFields = [
operation: [
'createByStartEnd',
],
resource: [
'timeEntry',
],
resource,
},
},
default: '',
@@ -522,9 +488,7 @@ export const timeEntryFields = [
operation: [
'createByStartEnd',
],
resource: [
'timeEntry',
],
resource,
},
},
default: '',
@@ -541,9 +505,7 @@ export const timeEntryFields = [
operation: [
'createByStartEnd',
],
resource: [
'timeEntry',
],
resource,
},
},
default: {},

View File

@@ -365,9 +365,7 @@ export const userFields = [
operation: [
'update',
],
resource: [
'timeEntry',
],
resource
},
},
default: {},