feat(pipedrive): add create organization action

This commit is contained in:
Rıdvan Akca
2023-10-18 15:29:42 +03:00
committed by Ali BARIN
parent fb1f520096
commit 0772308bf5
5 changed files with 131 additions and 1 deletions

View File

@@ -0,0 +1,85 @@
import defineAction from '../../../../helpers/define-action';
function filterProvidedFields(body: Record<string, unknown>) {
return Object.keys(body).reduce<Record<string, unknown>>((result, key) => {
if (body[key]) {
result[key] = body[key];
}
return result;
}, {});
}
export default defineAction({
name: 'Create organization',
key: 'createOrganization',
description: 'Creates a new organization.',
arguments: [
{
label: 'Name',
key: 'name',
type: 'string' as const,
required: true,
description: '',
variables: true,
},
{
label: 'Owner',
key: 'ownerId',
type: 'dropdown' as const,
required: false,
description: '',
variables: true,
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listUsers',
},
],
},
},
{
label: 'Label',
key: 'labelId',
type: 'dropdown' as const,
required: false,
description: '',
variables: true,
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listOrganizationLabelField',
},
],
},
},
],
async run($) {
const { name, ownerId, labelId } = $.step.parameters;
const fields = {
name: name,
owner_id: ownerId,
label: labelId,
};
const body = filterProvidedFields(fields);
const {
data: { data },
} = await $.http.post(
`${$.auth.data.apiDomain}/api/v1/organizations`,
body
);
$.setActionItem({
raw: data,
});
},
});

View File

@@ -2,5 +2,12 @@ import createActivity from './create-activity';
import createDeal from './create-deal';
import createLead from './create-lead';
import createNote from './create-note';
import createOrganization from './create-organization';
export default [createActivity, createDeal, createLead, createNote];
export default [
createActivity,
createDeal,
createLead,
createNote,
createOrganization,
];

View File

@@ -4,6 +4,7 @@ import listDeals from './list-deals';
import listLeads from './list-leads';
import listLeadLabels from './list-lead-labels';
import listOrganizations from './list-organizations';
import listOrganizationLabelField from './list-organization-label-field';
import listPersons from './list-persons';
import listUsers from './list-users';
@@ -14,6 +15,7 @@ export default [
listLeads,
listLeadLabels,
listOrganizations,
listOrganizationLabelField,
listPersons,
listUsers,
];

View File

@@ -0,0 +1,34 @@
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
export default {
name: 'List organization label field',
key: 'listOrganizationLabelField',
async run($: IGlobalVariable) {
const labelFields: {
data: IJSONObject[];
} = {
data: [],
};
const { data } = await $.http.get(
`${$.auth.data.apiDomain}/api/v1/organizationFields`
);
const labelField = data.data.filter(
(field: IJSONObject) => field.key === 'label'
);
const labelOptions = labelField[0].options;
if (labelOptions?.length) {
for (const label of labelOptions) {
labelFields.data.push({
value: label.id,
name: label.label,
});
}
}
return labelFields;
},
};

View File

@@ -9,6 +9,8 @@ items:
desc: Creates a new lead.
- name: Create note
desc: Creates a new note.
- name: Create organization
desc: Creates a new organization.
---
<script setup>