Refactor time entry and user
This commit is contained in:
@@ -107,7 +107,7 @@ export class Harvest implements INodeType {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Time Entries',
|
name: 'Time Entries',
|
||||||
value: 'timeEntry',
|
value: 'time_entries',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'User',
|
name: 'User',
|
||||||
@@ -161,7 +161,7 @@ export class Harvest implements INodeType {
|
|||||||
body = {};
|
body = {};
|
||||||
qs = {};
|
qs = {};
|
||||||
|
|
||||||
if (resource === 'timeEntry') {
|
if (resource === 'time_entries') {
|
||||||
if (operation === 'get') {
|
if (operation === 'get') {
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// get
|
// get
|
||||||
@@ -170,7 +170,7 @@ export class Harvest implements INodeType {
|
|||||||
requestMethod = 'GET';
|
requestMethod = 'GET';
|
||||||
const id = this.getNodeParameter('id', i) as string;
|
const id = this.getNodeParameter('id', i) as string;
|
||||||
|
|
||||||
endpoint = `time_entries/${id}`;
|
endpoint = `${resource}/${id}`;
|
||||||
|
|
||||||
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
||||||
returnData.push(responseData);
|
returnData.push(responseData);
|
||||||
@@ -179,7 +179,7 @@ export class Harvest implements INodeType {
|
|||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// getAll
|
// 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);
|
returnData.push.apply(returnData, responseData);
|
||||||
|
|
||||||
} else if (operation === 'createByStartEnd') {
|
} else if (operation === 'createByStartEnd') {
|
||||||
@@ -188,7 +188,7 @@ export class Harvest implements INodeType {
|
|||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
|
||||||
requestMethod = 'POST';
|
requestMethod = 'POST';
|
||||||
endpoint = 'time_entries';
|
endpoint = resource;
|
||||||
|
|
||||||
body.project_id = this.getNodeParameter('projectId', i) as string;
|
body.project_id = this.getNodeParameter('projectId', i) as string;
|
||||||
body.task_id = this.getNodeParameter('taskId', i) as string;
|
body.task_id = this.getNodeParameter('taskId', i) as string;
|
||||||
@@ -206,7 +206,7 @@ export class Harvest implements INodeType {
|
|||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
|
||||||
requestMethod = 'POST';
|
requestMethod = 'POST';
|
||||||
endpoint = 'time_entries';
|
endpoint = resource;
|
||||||
|
|
||||||
body.project_id = this.getNodeParameter('projectId', i) as string;
|
body.project_id = this.getNodeParameter('projectId', i) as string;
|
||||||
body.task_id = this.getNodeParameter('taskId', i) as string;
|
body.task_id = this.getNodeParameter('taskId', i) as string;
|
||||||
@@ -225,7 +225,7 @@ export class Harvest implements INodeType {
|
|||||||
|
|
||||||
requestMethod = 'DELETE';
|
requestMethod = 'DELETE';
|
||||||
const id = this.getNodeParameter('id', i) as string;
|
const id = this.getNodeParameter('id', i) as string;
|
||||||
endpoint = `time_entries/${id}`;
|
endpoint = `${resource}/${id}`;
|
||||||
|
|
||||||
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
||||||
returnData.push(responseData);
|
returnData.push(responseData);
|
||||||
@@ -236,7 +236,7 @@ export class Harvest implements INodeType {
|
|||||||
|
|
||||||
requestMethod = 'DELETE';
|
requestMethod = 'DELETE';
|
||||||
const id = this.getNodeParameter('id', i) as string;
|
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);
|
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
||||||
returnData.push(responseData);
|
returnData.push(responseData);
|
||||||
@@ -248,7 +248,7 @@ export class Harvest implements INodeType {
|
|||||||
|
|
||||||
requestMethod = 'PATCH';
|
requestMethod = 'PATCH';
|
||||||
const id = this.getNodeParameter('id', i) as string;
|
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);
|
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
||||||
returnData.push(responseData);
|
returnData.push(responseData);
|
||||||
@@ -260,7 +260,7 @@ export class Harvest implements INodeType {
|
|||||||
|
|
||||||
requestMethod = 'PATCH';
|
requestMethod = 'PATCH';
|
||||||
const id = this.getNodeParameter('id', i) as string;
|
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);
|
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
||||||
returnData.push(responseData);
|
returnData.push(responseData);
|
||||||
@@ -272,7 +272,7 @@ export class Harvest implements INodeType {
|
|||||||
|
|
||||||
requestMethod = 'PATCH';
|
requestMethod = 'PATCH';
|
||||||
const id = this.getNodeParameter('id', i) as string;
|
const id = this.getNodeParameter('id', i) as string;
|
||||||
endpoint = `time_entries/${id}`;
|
endpoint = `${resource}/${id}`;
|
||||||
|
|
||||||
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
||||||
|
|
||||||
@@ -397,9 +397,10 @@ export class Harvest implements INodeType {
|
|||||||
|
|
||||||
requestMethod = 'POST';
|
requestMethod = 'POST';
|
||||||
endpoint = resource;
|
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;
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||||
@@ -416,8 +417,8 @@ export class Harvest implements INodeType {
|
|||||||
requestMethod = 'POST';
|
requestMethod = 'POST';
|
||||||
endpoint = resource;
|
endpoint = resource;
|
||||||
|
|
||||||
const additionalFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
||||||
Object.assign(body, additionalFields);
|
Object.assign(qs, updateFields);
|
||||||
|
|
||||||
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint, body);
|
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint, body);
|
||||||
returnData.push(responseData);
|
returnData.push(responseData);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { INodeProperties } from "n8n-workflow";
|
import { INodeProperties } from "n8n-workflow";
|
||||||
|
export const resource = [ 'time_entries' ]
|
||||||
export const timeEntryOperations = [
|
export const timeEntryOperations = [
|
||||||
{
|
{
|
||||||
displayName: 'Operation',
|
displayName: 'Operation',
|
||||||
@@ -7,9 +7,7 @@ export const timeEntryOperations = [
|
|||||||
type: 'options',
|
type: 'options',
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource,
|
||||||
'timeEntry',
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
options: [
|
options: [
|
||||||
@@ -75,9 +73,7 @@ export const timeEntryFields = [
|
|||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource,
|
||||||
'timeEntry',
|
|
||||||
],
|
|
||||||
operation: [
|
operation: [
|
||||||
'getAll',
|
'getAll',
|
||||||
],
|
],
|
||||||
@@ -92,9 +88,7 @@ export const timeEntryFields = [
|
|||||||
type: 'number',
|
type: 'number',
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource,
|
||||||
'timeEntry',
|
|
||||||
],
|
|
||||||
operation: [
|
operation: [
|
||||||
'getAll',
|
'getAll',
|
||||||
],
|
],
|
||||||
@@ -118,9 +112,7 @@ export const timeEntryFields = [
|
|||||||
default: {},
|
default: {},
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: [
|
resource,
|
||||||
'timeEntry',
|
|
||||||
],
|
|
||||||
operation: [
|
operation: [
|
||||||
'getAll',
|
'getAll',
|
||||||
],
|
],
|
||||||
@@ -203,9 +195,7 @@ export const timeEntryFields = [
|
|||||||
operation: [
|
operation: [
|
||||||
'get',
|
'get',
|
||||||
],
|
],
|
||||||
resource: [
|
resource,
|
||||||
'timeEntry',
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
description: 'The ID of the time entry you are retrieving.',
|
description: 'The ID of the time entry you are retrieving.',
|
||||||
@@ -225,9 +215,7 @@ export const timeEntryFields = [
|
|||||||
operation: [
|
operation: [
|
||||||
'delete',
|
'delete',
|
||||||
],
|
],
|
||||||
resource: [
|
resource,
|
||||||
'timeEntry',
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
description: 'The ID of the time entry you are deleting.',
|
description: 'The ID of the time entry you are deleting.',
|
||||||
@@ -247,9 +235,7 @@ export const timeEntryFields = [
|
|||||||
operation: [
|
operation: [
|
||||||
'deleteExternal',
|
'deleteExternal',
|
||||||
],
|
],
|
||||||
resource: [
|
resource,
|
||||||
'timeEntry',
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
description: 'The ID of the time entry whose external reference you are deleting.',
|
description: 'The ID of the time entry whose external reference you are deleting.',
|
||||||
@@ -269,9 +255,7 @@ export const timeEntryFields = [
|
|||||||
operation: [
|
operation: [
|
||||||
'stopTime',
|
'stopTime',
|
||||||
],
|
],
|
||||||
resource: [
|
resource,
|
||||||
'timeEntry',
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
description: 'Stop a running time entry. Stopping a time entry is only possible if it’s currently running.',
|
description: 'Stop a running time entry. Stopping a time entry is only possible if it’s currently running.',
|
||||||
@@ -291,9 +275,7 @@ export const timeEntryFields = [
|
|||||||
operation: [
|
operation: [
|
||||||
'restartTime',
|
'restartTime',
|
||||||
],
|
],
|
||||||
resource: [
|
resource,
|
||||||
'timeEntry',
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
description: 'Restart a stopped time entry. Restarting a time entry is only possible if it isn’t currently running.',
|
description: 'Restart a stopped time entry. Restarting a time entry is only possible if it isn’t currently running.',
|
||||||
@@ -313,9 +295,7 @@ export const timeEntryFields = [
|
|||||||
operation: [
|
operation: [
|
||||||
'update',
|
'update',
|
||||||
],
|
],
|
||||||
resource: [
|
resource,
|
||||||
'timeEntry',
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
description: 'The ID of the time entry to update.',
|
description: 'The ID of the time entry to update.',
|
||||||
@@ -330,9 +310,7 @@ export const timeEntryFields = [
|
|||||||
operation: [
|
operation: [
|
||||||
'update',
|
'update',
|
||||||
],
|
],
|
||||||
resource: [
|
resource,
|
||||||
'timeEntry',
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
default: {},
|
default: {},
|
||||||
@@ -385,9 +363,7 @@ export const timeEntryFields = [
|
|||||||
operation: [
|
operation: [
|
||||||
'createByDuration',
|
'createByDuration',
|
||||||
],
|
],
|
||||||
resource: [
|
resource,
|
||||||
'timeEntry',
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
default: '',
|
default: '',
|
||||||
@@ -403,9 +379,7 @@ export const timeEntryFields = [
|
|||||||
operation: [
|
operation: [
|
||||||
'createByDuration',
|
'createByDuration',
|
||||||
],
|
],
|
||||||
resource: [
|
resource,
|
||||||
'timeEntry',
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
default: '',
|
default: '',
|
||||||
@@ -421,9 +395,7 @@ export const timeEntryFields = [
|
|||||||
operation: [
|
operation: [
|
||||||
'createByDuration',
|
'createByDuration',
|
||||||
],
|
],
|
||||||
resource: [
|
resource,
|
||||||
'timeEntry',
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
default: '',
|
default: '',
|
||||||
@@ -440,9 +412,7 @@ export const timeEntryFields = [
|
|||||||
operation: [
|
operation: [
|
||||||
'createByDuration',
|
'createByDuration',
|
||||||
],
|
],
|
||||||
resource: [
|
resource,
|
||||||
'timeEntry',
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
default: {},
|
default: {},
|
||||||
@@ -486,9 +456,7 @@ export const timeEntryFields = [
|
|||||||
operation: [
|
operation: [
|
||||||
'createByStartEnd',
|
'createByStartEnd',
|
||||||
],
|
],
|
||||||
resource: [
|
resource,
|
||||||
'timeEntry',
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
default: '',
|
default: '',
|
||||||
@@ -504,9 +472,7 @@ export const timeEntryFields = [
|
|||||||
operation: [
|
operation: [
|
||||||
'createByStartEnd',
|
'createByStartEnd',
|
||||||
],
|
],
|
||||||
resource: [
|
resource,
|
||||||
'timeEntry',
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
default: '',
|
default: '',
|
||||||
@@ -522,9 +488,7 @@ export const timeEntryFields = [
|
|||||||
operation: [
|
operation: [
|
||||||
'createByStartEnd',
|
'createByStartEnd',
|
||||||
],
|
],
|
||||||
resource: [
|
resource,
|
||||||
'timeEntry',
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
default: '',
|
default: '',
|
||||||
@@ -541,9 +505,7 @@ export const timeEntryFields = [
|
|||||||
operation: [
|
operation: [
|
||||||
'createByStartEnd',
|
'createByStartEnd',
|
||||||
],
|
],
|
||||||
resource: [
|
resource,
|
||||||
'timeEntry',
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
default: {},
|
default: {},
|
||||||
|
|||||||
@@ -365,9 +365,7 @@ export const userFields = [
|
|||||||
operation: [
|
operation: [
|
||||||
'update',
|
'update',
|
||||||
],
|
],
|
||||||
resource: [
|
resource
|
||||||
'timeEntry',
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
default: {},
|
default: {},
|
||||||
|
|||||||
Reference in New Issue
Block a user