2049 timebox 1j zapier integration 4 define and implement a first trigger for zapier app (#2132)
* Add create company trigger * Refactor * Add operation in subscribe * Add create hook api endpoint * Add import of hook module * Add a test for hook subscribe * Add delete hook api endpoint * Add delete hook test * Add findMany hook route --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
74
packages/twenty-zapier/src/triggers/company.ts
Normal file
74
packages/twenty-zapier/src/triggers/company.ts
Normal file
@ -0,0 +1,74 @@
|
||||
import { Bundle, ZObject } from 'zapier-platform-core';
|
||||
import requestDb from '../utils/requestDb';
|
||||
import handleQueryParams from '../utils/handleQueryParams';
|
||||
|
||||
const performSubscribe = async (z: ZObject, bundle: Bundle) => {
|
||||
const data = { targetUrl: bundle.targetUrl, operation: 'createOneCompany' };
|
||||
const result = await requestDb(
|
||||
z,
|
||||
bundle,
|
||||
`mutation createOneHook {createOneHook(data:{${handleQueryParams(
|
||||
data,
|
||||
)}}) {id}}`,
|
||||
);
|
||||
return result.data.createOneHook;
|
||||
};
|
||||
const performUnsubscribe = async (z: ZObject, bundle: Bundle) => {
|
||||
const data = { id: bundle.subscribeData?.id };
|
||||
const result = await requestDb(
|
||||
z,
|
||||
bundle,
|
||||
`mutation deleteOneHook {deleteOneHook(where:{${handleQueryParams(
|
||||
data,
|
||||
)}}) {id}}`,
|
||||
);
|
||||
return result.data.deleteOneHook;
|
||||
};
|
||||
const perform = (z: ZObject, bundle: Bundle) => {
|
||||
return [bundle.cleanedRequest];
|
||||
};
|
||||
const performList = async (z: ZObject, bundle: Bundle) => {
|
||||
const results = await requestDb(
|
||||
z,
|
||||
bundle,
|
||||
`query FindManyCompany {findManyCompany {
|
||||
id
|
||||
name
|
||||
domainName
|
||||
createdAt
|
||||
address
|
||||
employees
|
||||
linkedinUrl
|
||||
xUrl
|
||||
annualRecurringRevenue
|
||||
idealCustomerProfile
|
||||
}}`,
|
||||
);
|
||||
return results.data.findManyCompany;
|
||||
};
|
||||
export default {
|
||||
key: 'company',
|
||||
noun: 'Company',
|
||||
display: {
|
||||
label: 'New Company',
|
||||
description: 'Triggers when a new company is created.',
|
||||
},
|
||||
operation: {
|
||||
inputFields: [],
|
||||
type: 'hook',
|
||||
performSubscribe,
|
||||
performUnsubscribe,
|
||||
perform,
|
||||
performList,
|
||||
sample: {
|
||||
id: 'f75f6b2e-9442-4c72-aa95-47d8e5ec8cb3',
|
||||
createdAt: '2023-10-19 07:37:25.306',
|
||||
workspaceId: 'c8b070fc-c969-4ca5-837a-e7c3735734d2',
|
||||
},
|
||||
outputFields: [
|
||||
{ key: 'id', label: 'ID' },
|
||||
{ key: 'createdAt', label: 'Created At' },
|
||||
{ key: 'workspaceId', label: 'Workspace ID' },
|
||||
],
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user