2023-01-27 03:22:44 -08:00
|
|
|
import type {
|
2023-03-09 09:13:15 -08:00
|
|
|
IExecuteFunctions,
|
2020-11-03 14:33:10 -08:00
|
|
|
IDataObject,
|
|
|
|
ILoadOptionsFunctions,
|
|
|
|
INodeExecutionData,
|
|
|
|
INodePropertyOptions,
|
|
|
|
INodeType,
|
|
|
|
INodeTypeDescription,
|
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
2024-01-15 06:45:33 -08:00
|
|
|
import moment from 'moment-timezone';
|
2022-08-17 08:50:24 -07:00
|
|
|
import { orbitApiRequest, orbitApiRequestAllItems, resolveIdentities } from './GenericFunctions';
|
2020-11-03 14:33:10 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { activityFields, activityOperations } from './ActivityDescription';
|
2020-11-03 14:33:10 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { memberFields, memberOperations } from './MemberDescription';
|
2020-11-03 14:33:10 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { noteFields, noteOperations } from './NoteDescription';
|
2020-11-03 14:33:10 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { postFields, postOperations } from './PostDescription';
|
2020-11-03 14:33:10 -08:00
|
|
|
|
2023-02-27 19:39:43 -08:00
|
|
|
import type { IRelation } from './Interfaces';
|
2020-11-03 14:33:10 -08:00
|
|
|
|
|
|
|
export class Orbit implements INodeType {
|
|
|
|
description: INodeTypeDescription = {
|
|
|
|
displayName: 'Orbit',
|
|
|
|
name: 'orbit',
|
|
|
|
icon: 'file:orbit.svg',
|
|
|
|
group: ['output'],
|
|
|
|
version: 1,
|
|
|
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
|
|
|
description: 'Consume Orbit API',
|
|
|
|
defaults: {
|
|
|
|
name: 'Orbit',
|
|
|
|
},
|
|
|
|
inputs: ['main'],
|
|
|
|
outputs: ['main'],
|
|
|
|
credentials: [
|
|
|
|
{
|
|
|
|
name: 'orbitApi',
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
properties: [
|
|
|
|
{
|
|
|
|
displayName: 'Resource',
|
|
|
|
name: 'resource',
|
|
|
|
type: 'options',
|
2022-05-20 14:47:24 -07:00
|
|
|
noDataExpression: true,
|
2020-11-03 14:33:10 -08:00
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'Activity',
|
|
|
|
value: 'activity',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Member',
|
|
|
|
value: 'member',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Note',
|
|
|
|
value: 'note',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Post',
|
|
|
|
value: 'post',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
default: 'member',
|
|
|
|
},
|
|
|
|
// ACTIVITY
|
|
|
|
...activityOperations,
|
|
|
|
...activityFields,
|
|
|
|
// MEMBER
|
|
|
|
...memberOperations,
|
|
|
|
...memberFields,
|
|
|
|
// NOTE
|
|
|
|
...noteOperations,
|
|
|
|
...noteFields,
|
|
|
|
// POST
|
|
|
|
...postOperations,
|
|
|
|
...postFields,
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
methods = {
|
|
|
|
loadOptions: {
|
2022-08-17 08:50:24 -07:00
|
|
|
async getWorkspaces(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
2020-11-03 14:33:10 -08:00
|
|
|
const returnData: INodePropertyOptions[] = [];
|
2022-08-17 08:50:24 -07:00
|
|
|
const workspaces = await orbitApiRequest.call(this, 'GET', '/workspaces');
|
2020-11-03 14:33:10 -08:00
|
|
|
for (const workspace of workspaces.data) {
|
|
|
|
returnData.push({
|
|
|
|
name: workspace.attributes.name,
|
2022-02-26 02:49:30 -08:00
|
|
|
value: workspace.attributes.slug,
|
2020-11-03 14:33:10 -08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
2022-08-17 08:50:24 -07:00
|
|
|
async getActivityTypes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
2020-11-03 14:33:10 -08:00
|
|
|
const returnData: INodePropertyOptions[] = [];
|
2022-08-17 08:50:24 -07:00
|
|
|
const { data } = await orbitApiRequest.call(this, 'GET', '/activity_types');
|
2020-11-03 14:33:10 -08:00
|
|
|
for (const activityType of data) {
|
|
|
|
returnData.push({
|
|
|
|
name: activityType.attributes.short_name,
|
|
|
|
value: activityType.id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
|
|
const items = this.getInputData();
|
2022-08-30 08:55:33 -07:00
|
|
|
const returnData: INodeExecutionData[] = [];
|
2022-04-22 09:29:51 -07:00
|
|
|
const length = items.length;
|
2020-11-03 14:33:10 -08:00
|
|
|
const qs: IDataObject = {};
|
|
|
|
let responseData;
|
2022-12-02 03:53:59 -08:00
|
|
|
const resource = this.getNodeParameter('resource', 0);
|
|
|
|
const operation = this.getNodeParameter('operation', 0);
|
2020-11-03 14:33:10 -08:00
|
|
|
for (let i = 0; i < length; i++) {
|
2021-07-19 23:58:54 -07:00
|
|
|
try {
|
|
|
|
if (resource === 'activity') {
|
|
|
|
if (operation === 'create') {
|
|
|
|
const workspaceId = this.getNodeParameter('workspaceId', i) as string;
|
|
|
|
const memberId = this.getNodeParameter('memberId', i) as string;
|
|
|
|
const title = this.getNodeParameter('title', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
const body: IDataObject = {
|
|
|
|
title,
|
|
|
|
};
|
|
|
|
if (additionalFields.description) {
|
|
|
|
body.description = additionalFields.description as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.link) {
|
|
|
|
body.link = additionalFields.link as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.linkText) {
|
|
|
|
body.link_text = additionalFields.linkText as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.activityType) {
|
|
|
|
body.activity_type = additionalFields.activityType as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.key) {
|
|
|
|
body.key = additionalFields.key as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.occurredAt) {
|
|
|
|
body.occurred_at = additionalFields.occurredAt as string;
|
|
|
|
}
|
2020-11-03 14:33:10 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await orbitApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
`/${workspaceId}/members/${memberId}/activities`,
|
|
|
|
body,
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = responseData.data;
|
|
|
|
}
|
|
|
|
if (operation === 'getAll') {
|
|
|
|
const workspaceId = this.getNodeParameter('workspaceId', i) as string;
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
2022-11-18 07:29:44 -08:00
|
|
|
const filters = this.getNodeParameter('filters', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
let endpoint = `/${workspaceId}/activities`;
|
|
|
|
if (filters.memberId) {
|
|
|
|
endpoint = `/${workspaceId}/members/${filters.memberId}/activities`;
|
|
|
|
}
|
2022-12-02 12:54:28 -08:00
|
|
|
if (returnAll) {
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await orbitApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'data',
|
|
|
|
'GET',
|
|
|
|
endpoint,
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
qs.limit = this.getNodeParameter('limit', 0);
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await orbitApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'data',
|
|
|
|
'GET',
|
|
|
|
endpoint,
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = responseData.splice(0, qs.limit);
|
|
|
|
}
|
2020-11-03 14:33:10 -08:00
|
|
|
}
|
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
if (resource === 'member') {
|
|
|
|
if (operation === 'upsert') {
|
|
|
|
const workspaceId = this.getNodeParameter('workspaceId', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
const member: IDataObject = {};
|
|
|
|
const identity: IDataObject = {};
|
|
|
|
if (additionalFields.bio) {
|
|
|
|
member.bio = additionalFields.bio as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.birthday) {
|
|
|
|
member.birthday = moment(additionalFields.birthday as string).format('MM-DD-YYYY');
|
|
|
|
}
|
|
|
|
if (additionalFields.company) {
|
|
|
|
member.company = additionalFields.company as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.location) {
|
|
|
|
member.location = additionalFields.location as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.name) {
|
|
|
|
member.name = additionalFields.name as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.bio) {
|
|
|
|
member.bio = additionalFields.bio as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.pronouns) {
|
|
|
|
member.pronouns = additionalFields.pronouns as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.shippingAddress) {
|
|
|
|
member.shipping_address = additionalFields.shippingAddress as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.slug) {
|
|
|
|
member.slug = additionalFields.slug as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.tagsToAdd) {
|
|
|
|
member.tags_to_add = additionalFields.tagsToAdd as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.tagList) {
|
|
|
|
member.tag_list = additionalFields.tagList as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.tshirt) {
|
|
|
|
member.tshirt = additionalFields.tshirt as string;
|
|
|
|
}
|
|
|
|
if (additionalFields.hasOwnProperty('teammate')) {
|
|
|
|
member.teammate = additionalFields.teammate as boolean;
|
|
|
|
}
|
|
|
|
if (additionalFields.url) {
|
|
|
|
member.url = additionalFields.url as string;
|
|
|
|
}
|
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
const data = (this.getNodeParameter('identityUi', i) as IDataObject)
|
|
|
|
.identityValue as IDataObject;
|
2021-07-19 23:58:54 -07:00
|
|
|
if (data) {
|
|
|
|
if (['github', 'twitter', 'discourse'].includes(data.source as string)) {
|
|
|
|
identity.source = data.source as string;
|
|
|
|
const searchBy = data.searchBy as string;
|
|
|
|
if (searchBy === 'id') {
|
|
|
|
identity.uid = data.id as string;
|
|
|
|
} else {
|
|
|
|
identity.username = data.username as string;
|
|
|
|
}
|
|
|
|
if (data.source === 'discourse') {
|
|
|
|
identity.source_host = data.host as string;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//it's email
|
|
|
|
identity.email = data.email as string;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await orbitApiRequest.call(this, 'POST', `/${workspaceId}/members`, {
|
|
|
|
member,
|
|
|
|
identity,
|
|
|
|
});
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = responseData.data;
|
|
|
|
}
|
|
|
|
if (operation === 'delete') {
|
|
|
|
const workspaceId = this.getNodeParameter('workspaceId', i) as string;
|
|
|
|
const memberId = this.getNodeParameter('memberId', i) as string;
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await orbitApiRequest.call(
|
|
|
|
this,
|
|
|
|
'DELETE',
|
|
|
|
`/${workspaceId}/members/${memberId}`,
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = { success: true };
|
|
|
|
}
|
|
|
|
if (operation === 'get') {
|
|
|
|
const workspaceId = this.getNodeParameter('workspaceId', i) as string;
|
|
|
|
const memberId = this.getNodeParameter('memberId', i) as string;
|
|
|
|
const resolve = this.getNodeParameter('resolveIdentities', 0) as boolean;
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await orbitApiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
|
|
|
`/${workspaceId}/members/${memberId}`,
|
|
|
|
);
|
2022-12-02 12:54:28 -08:00
|
|
|
if (resolve) {
|
2023-02-27 19:39:43 -08:00
|
|
|
resolveIdentities(responseData as IRelation);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
responseData = responseData.data;
|
|
|
|
}
|
|
|
|
if (operation === 'getAll') {
|
|
|
|
const workspaceId = this.getNodeParameter('workspaceId', i) as string;
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', 0);
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(qs, options);
|
|
|
|
qs.resolveIdentities = this.getNodeParameter('resolveIdentities', 0) as boolean;
|
2022-12-02 12:54:28 -08:00
|
|
|
if (returnAll) {
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await orbitApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'data',
|
|
|
|
'GET',
|
|
|
|
`/${workspaceId}/members`,
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
qs.limit = this.getNodeParameter('limit', 0);
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await orbitApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'data',
|
|
|
|
'GET',
|
|
|
|
`/${workspaceId}/members`,
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = responseData.splice(0, qs.limit);
|
|
|
|
}
|
2020-11-03 14:33:10 -08:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'lookup') {
|
|
|
|
const workspaceId = this.getNodeParameter('workspaceId', i) as string;
|
|
|
|
const source = this.getNodeParameter('source', i) as string;
|
2020-11-03 14:33:10 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (['github', 'twitter', 'discourse'].includes(source)) {
|
|
|
|
qs.source = this.getNodeParameter('source', i) as string;
|
|
|
|
const searchBy = this.getNodeParameter('searchBy', i) as string;
|
2020-11-03 14:33:10 -08:00
|
|
|
if (searchBy === 'id') {
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.uid = this.getNodeParameter('id', i) as string;
|
2020-11-03 14:33:10 -08:00
|
|
|
} else {
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.username = this.getNodeParameter('username', i) as string;
|
2020-11-03 14:33:10 -08:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
if (source === 'discourse') {
|
|
|
|
qs.source_host = this.getNodeParameter('host', i) as string;
|
2020-11-03 14:33:10 -08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//it's email
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.email = this.getNodeParameter('email', i) as string;
|
2020-11-03 14:33:10 -08:00
|
|
|
}
|
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await orbitApiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
|
|
|
`/${workspaceId}/members/find`,
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = responseData.data;
|
|
|
|
}
|
|
|
|
if (operation === 'update') {
|
|
|
|
const workspaceId = this.getNodeParameter('workspaceId', i) as string;
|
|
|
|
const memberId = this.getNodeParameter('memberId', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const updateFields = this.getNodeParameter('updateFields', i);
|
2022-08-17 08:50:24 -07:00
|
|
|
const body: IDataObject = {};
|
2021-07-19 23:58:54 -07:00
|
|
|
if (updateFields.bio) {
|
|
|
|
body.bio = updateFields.bio as string;
|
|
|
|
}
|
|
|
|
if (updateFields.birthday) {
|
|
|
|
body.birthday = moment(updateFields.birthday as string).format('MM-DD-YYYY');
|
|
|
|
}
|
|
|
|
if (updateFields.company) {
|
|
|
|
body.company = updateFields.company as string;
|
|
|
|
}
|
|
|
|
if (updateFields.location) {
|
|
|
|
body.location = updateFields.location as string;
|
|
|
|
}
|
|
|
|
if (updateFields.name) {
|
|
|
|
body.name = updateFields.name as string;
|
|
|
|
}
|
|
|
|
if (updateFields.bio) {
|
|
|
|
body.bio = updateFields.bio as string;
|
|
|
|
}
|
|
|
|
if (updateFields.pronouns) {
|
|
|
|
body.pronouns = updateFields.pronouns as string;
|
|
|
|
}
|
|
|
|
if (updateFields.shippingAddress) {
|
|
|
|
body.shipping_address = updateFields.shippingAddress as string;
|
|
|
|
}
|
|
|
|
if (updateFields.slug) {
|
|
|
|
body.slug = updateFields.slug as string;
|
|
|
|
}
|
|
|
|
if (updateFields.tagsToAdd) {
|
|
|
|
body.tags_to_add = updateFields.tagsToAdd as string;
|
|
|
|
}
|
|
|
|
if (updateFields.tagList) {
|
|
|
|
body.tag_list = updateFields.tagList as string;
|
|
|
|
}
|
|
|
|
if (updateFields.tshirt) {
|
|
|
|
body.tshirt = updateFields.tshirt as string;
|
|
|
|
}
|
|
|
|
if (updateFields.hasOwnProperty('teammate')) {
|
|
|
|
body.teammate = updateFields.teammate as boolean;
|
|
|
|
}
|
|
|
|
if (updateFields.url) {
|
|
|
|
body.url = updateFields.url as string;
|
|
|
|
}
|
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await orbitApiRequest.call(
|
|
|
|
this,
|
|
|
|
'PUT',
|
|
|
|
`/${workspaceId}/members/${memberId}`,
|
|
|
|
body,
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = { success: true };
|
2020-11-03 14:33:10 -08:00
|
|
|
}
|
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
if (resource === 'note') {
|
|
|
|
if (operation === 'create') {
|
|
|
|
const workspaceId = this.getNodeParameter('workspaceId', i) as string;
|
|
|
|
const memberId = this.getNodeParameter('memberId', i) as string;
|
|
|
|
const note = this.getNodeParameter('note', i) as string;
|
2020-11-03 14:33:10 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await orbitApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
`/${workspaceId}/members/${memberId}/notes`,
|
|
|
|
{ body: note },
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = responseData.data;
|
|
|
|
}
|
|
|
|
if (operation === 'getAll') {
|
|
|
|
const workspaceId = this.getNodeParameter('workspaceId', i) as string;
|
|
|
|
const memberId = this.getNodeParameter('memberId', i) as string;
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.resolveMember = this.getNodeParameter('resolveMember', 0) as boolean;
|
2022-12-02 12:54:28 -08:00
|
|
|
if (returnAll) {
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await orbitApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'data',
|
|
|
|
'GET',
|
|
|
|
`/${workspaceId}/members/${memberId}/notes`,
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2020-11-03 14:33:10 -08:00
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
qs.limit = this.getNodeParameter('limit', 0);
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await orbitApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'data',
|
|
|
|
'GET',
|
|
|
|
`/${workspaceId}/members/${memberId}/notes`,
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = responseData.splice(0, qs.limit);
|
2020-11-03 14:33:10 -08:00
|
|
|
}
|
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'update') {
|
|
|
|
const workspaceId = this.getNodeParameter('workspaceId', i) as string;
|
|
|
|
const memberId = this.getNodeParameter('memberId', i) as string;
|
|
|
|
const noteId = this.getNodeParameter('noteId', i) as string;
|
|
|
|
const note = this.getNodeParameter('note', i) as string;
|
2020-11-03 14:33:10 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await orbitApiRequest.call(
|
|
|
|
this,
|
|
|
|
'PUT',
|
|
|
|
`/${workspaceId}/members/${memberId}/notes/${noteId}`,
|
|
|
|
{ body: note },
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = { success: true };
|
2020-11-03 14:33:10 -08:00
|
|
|
}
|
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
if (resource === 'post') {
|
|
|
|
if (operation === 'create') {
|
|
|
|
const workspaceId = this.getNodeParameter('workspaceId', i) as string;
|
|
|
|
const memberId = this.getNodeParameter('memberId', i) as string;
|
|
|
|
const url = this.getNodeParameter('url', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
const body: IDataObject = {
|
|
|
|
type: 'post',
|
|
|
|
activity_type: 'post',
|
|
|
|
url,
|
|
|
|
};
|
|
|
|
if (additionalFields.publishedAt) {
|
|
|
|
body.occurred_at = additionalFields.publishedAt as string;
|
|
|
|
delete body.publishedAt;
|
|
|
|
}
|
2020-11-03 14:33:10 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await orbitApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
`/${workspaceId}/members/${memberId}/activities/`,
|
|
|
|
body,
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = responseData.data;
|
|
|
|
}
|
|
|
|
if (operation === 'getAll') {
|
|
|
|
const workspaceId = this.getNodeParameter('workspaceId', i) as string;
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
2022-11-18 07:29:44 -08:00
|
|
|
const filters = this.getNodeParameter('filters', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
let endpoint = `/${workspaceId}/activities`;
|
|
|
|
qs.type = 'content';
|
|
|
|
if (filters.memberId) {
|
|
|
|
endpoint = `/${workspaceId}/members/${filters.memberId}/activities`;
|
|
|
|
}
|
2022-12-02 12:54:28 -08:00
|
|
|
if (returnAll) {
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await orbitApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'data',
|
|
|
|
'GET',
|
|
|
|
endpoint,
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
qs.limit = this.getNodeParameter('limit', 0);
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await orbitApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'data',
|
|
|
|
'GET',
|
|
|
|
endpoint,
|
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = responseData.splice(0, qs.limit);
|
|
|
|
}
|
2020-11-03 14:33:10 -08:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'delete') {
|
|
|
|
const workspaceId = this.getNodeParameter('workspaceId', i) as string;
|
|
|
|
const memberId = this.getNodeParameter('memberId', i) as string;
|
|
|
|
const postId = this.getNodeParameter('postId', i) as string;
|
2020-11-03 14:33:10 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await orbitApiRequest.call(
|
|
|
|
this,
|
|
|
|
'DELETE',
|
|
|
|
`/${workspaceId}/members/${memberId}/activities/${postId}`,
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = { success: true };
|
2020-11-03 14:33:10 -08:00
|
|
|
}
|
|
|
|
}
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
2023-02-27 19:39:43 -08:00
|
|
|
this.helpers.returnJsonArray(responseData as IDataObject),
|
2022-08-30 08:55:33 -07:00
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} catch (error) {
|
|
|
|
if (this.continueOnFail()) {
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionErrorData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray({ error: error.message }),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionErrorData);
|
2021-07-19 23:58:54 -07:00
|
|
|
continue;
|
2020-11-03 14:33:10 -08:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
throw error;
|
2020-11-03 14:33:10 -08:00
|
|
|
}
|
|
|
|
}
|
2023-09-05 03:59:02 -07:00
|
|
|
return [returnData];
|
2020-11-03 14:33:10 -08:00
|
|
|
}
|
|
|
|
}
|