Fix create trigger called twice (#3243)
* Fix create trigger called twice * Add Zapier update action * Add Zapier delete action * Update description * Add dropDown for ids
This commit is contained in:
@ -1,16 +1,10 @@
|
||||
import { Bundle, ZObject } from 'zapier-platform-core';
|
||||
import requestDb, { requestSchema } from '../utils/requestDb';
|
||||
import handleQueryParams from '../utils/handleQueryParams';
|
||||
import { capitalize } from '../utils/capitalize';
|
||||
import { computeInputFields } from '../utils/computeInputFields';
|
||||
|
||||
import { findObjectNamesSingularKey } from '../triggers/find_object_names_singular';
|
||||
|
||||
const recordInputFields = async (z: ZObject, bundle: Bundle) => {
|
||||
const schema = await requestSchema(z, bundle);
|
||||
const infos = schema.components.schemas[bundle.inputData.nameSingular];
|
||||
|
||||
return computeInputFields(infos);
|
||||
};
|
||||
import { capitalize } from '../utils/capitalize';
|
||||
import { recordInputFields } from '../utils/creates/creates.utils';
|
||||
import handleQueryParams from '../utils/handleQueryParams';
|
||||
import requestDb from '../utils/requestDb';
|
||||
|
||||
const perform = async (z: ZObject, bundle: Bundle) => {
|
||||
const data = bundle.inputData;
|
||||
@ -30,9 +24,9 @@ export const createRecordKey = 'create_record';
|
||||
|
||||
export default {
|
||||
display: {
|
||||
description: 'Creates a new Record in Twenty',
|
||||
description: 'Create a Record in Twenty.',
|
||||
hidden: false,
|
||||
label: 'Create New Record',
|
||||
label: 'Create Record',
|
||||
},
|
||||
key: createRecordKey,
|
||||
noun: 'Record',
|
||||
|
||||
56
packages/twenty-zapier/src/creates/delete_record.ts
Normal file
56
packages/twenty-zapier/src/creates/delete_record.ts
Normal file
@ -0,0 +1,56 @@
|
||||
import { Bundle, ZObject } from 'zapier-platform-core';
|
||||
|
||||
import { findObjectNamesPluralKey } from '../triggers/find_object_names_plural';
|
||||
import { listRecordIdsKey } from '../triggers/list_record_ids';
|
||||
import { capitalize } from '../utils/capitalize';
|
||||
import requestDb from '../utils/requestDb';
|
||||
|
||||
export const deleteRecordKey = 'delete_record';
|
||||
|
||||
const perform = async (z: ZObject, bundle: Bundle) => {
|
||||
const data = bundle.inputData;
|
||||
const nameSingular = data.nameSingular;
|
||||
const id = data.id;
|
||||
delete data.nameSingular;
|
||||
delete data.id;
|
||||
const query = `
|
||||
mutation delete${capitalize(nameSingular)} {
|
||||
delete${capitalize(nameSingular)}(
|
||||
id: "${id}"
|
||||
)
|
||||
{id}
|
||||
}`;
|
||||
return await requestDb(z, bundle, query);
|
||||
};
|
||||
|
||||
export default {
|
||||
display: {
|
||||
description: 'Delete a Record in Twenty.',
|
||||
hidden: false,
|
||||
label: 'Delete Record',
|
||||
},
|
||||
key: deleteRecordKey,
|
||||
noun: 'Record',
|
||||
operation: {
|
||||
inputFields: [
|
||||
{
|
||||
key: 'namePlural',
|
||||
label: 'Record Name',
|
||||
dynamic: `${findObjectNamesPluralKey}.namePlural`,
|
||||
required: true,
|
||||
altersDynamicFields: true,
|
||||
},
|
||||
{
|
||||
key: 'id',
|
||||
label: 'Id',
|
||||
type: 'string',
|
||||
dynamic: `${listRecordIdsKey}.id`,
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
sample: {
|
||||
id: '179ed459-79cf-41d9-ab85-96397fa8e936',
|
||||
},
|
||||
perform,
|
||||
},
|
||||
};
|
||||
56
packages/twenty-zapier/src/creates/update_record.ts
Normal file
56
packages/twenty-zapier/src/creates/update_record.ts
Normal file
@ -0,0 +1,56 @@
|
||||
import { Bundle, ZObject } from 'zapier-platform-core';
|
||||
|
||||
import { findObjectNamesSingularKey } from '../triggers/find_object_names_singular';
|
||||
import { capitalize } from '../utils/capitalize';
|
||||
import { recordInputFields } from '../utils/creates/creates.utils';
|
||||
import handleQueryParams from '../utils/handleQueryParams';
|
||||
import requestDb from '../utils/requestDb';
|
||||
|
||||
export const updateRecordKey = 'update_record';
|
||||
|
||||
const perform = async (z: ZObject, bundle: Bundle) => {
|
||||
const data = bundle.inputData;
|
||||
const nameSingular = data.nameSingular;
|
||||
const id = data.id;
|
||||
delete data.nameSingular;
|
||||
delete data.id;
|
||||
const query = `
|
||||
mutation update${capitalize(nameSingular)} {
|
||||
update${capitalize(nameSingular)}(
|
||||
data:{${handleQueryParams(data)}},
|
||||
id: "${id}"
|
||||
)
|
||||
{id}
|
||||
}`;
|
||||
return await requestDb(z, bundle, query);
|
||||
};
|
||||
|
||||
const updateRecordInputFields = async (z: ZObject, bundle: Bundle) => {
|
||||
return recordInputFields(z, bundle, true);
|
||||
};
|
||||
|
||||
export default {
|
||||
display: {
|
||||
description: 'Update a Record in Twenty.',
|
||||
hidden: false,
|
||||
label: 'Update Record',
|
||||
},
|
||||
key: updateRecordKey,
|
||||
noun: 'Record',
|
||||
operation: {
|
||||
inputFields: [
|
||||
{
|
||||
key: 'nameSingular',
|
||||
required: true,
|
||||
label: 'Record Name',
|
||||
dynamic: `${findObjectNamesSingularKey}.nameSingular`,
|
||||
altersDynamicFields: true,
|
||||
},
|
||||
updateRecordInputFields,
|
||||
],
|
||||
sample: {
|
||||
id: '179ed459-79cf-41d9-ab85-96397fa8e936',
|
||||
},
|
||||
perform,
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user