8130 creating a new company in twenty doesnt activate on zapier (#8166)
- fix webhook.operation format change from august 2024 not spread in twenty-zapier - added a comment so it does not happen again - add a fix for the new webhook.operations column that would produce another issue
This commit is contained in:
@ -1,13 +1,14 @@
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
import { Command } from 'nest-commander';
|
||||
import { Repository } from 'typeorm';
|
||||
import { ObjectLiteral, Repository } from 'typeorm';
|
||||
import chalk from 'chalk';
|
||||
|
||||
import { ActiveWorkspacesCommandRunner } from 'src/database/commands/active-workspaces.command';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
|
||||
import { BaseCommandOptions } from 'src/database/commands/base.command';
|
||||
import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository';
|
||||
|
||||
@Command({
|
||||
name: 'upgrade-0.32:copy-webhook-operation-into-operations',
|
||||
@ -43,11 +44,21 @@ export class CopyWebhookOperationIntoOperationsCommand extends ActiveWorkspacesC
|
||||
|
||||
for (const webhook of webhooks) {
|
||||
if ('operation' in webhook) {
|
||||
let newOperation = webhook.operation;
|
||||
|
||||
const [firstWebhookPart, lastWebhookPart] = newOperation.split('.');
|
||||
|
||||
if (['created', 'updated', 'deleted'].includes(firstWebhookPart)) {
|
||||
newOperation = `${lastWebhookPart}.${firstWebhookPart}`;
|
||||
}
|
||||
|
||||
await webhookRepository.update(webhook.id, {
|
||||
operations: [webhook.operation],
|
||||
operation: newOperation,
|
||||
operations: [newOperation],
|
||||
});
|
||||
|
||||
this.logger.log(
|
||||
chalk.yellow(`Copied webhook operation to operations`),
|
||||
chalk.yellow(`Handled webhook operation updates for ${webhook.id}`),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,6 +42,9 @@ export class CallWebhookJobsJob {
|
||||
|
||||
@Process(CallWebhookJobsJob.name)
|
||||
async handle(data: CallWebhookJobsJobData): Promise<void> {
|
||||
// If you change that function, double check it does not break Zapier
|
||||
// trigger in packages/twenty-zapier/src/triggers/trigger_record.ts
|
||||
|
||||
const webhookRepository =
|
||||
await this.twentyORMGlobalManager.getRepositoryForWorkspace<WebhookWorkspaceEntity>(
|
||||
data.workspaceId,
|
||||
|
||||
@ -21,7 +21,8 @@ export default {
|
||||
noun: 'Record',
|
||||
display: {
|
||||
label: 'Record Trigger',
|
||||
description: 'Triggers when a Record is created, updated or deleted.',
|
||||
description:
|
||||
'Triggers when a Record is created, updated, deleted or destroyed.',
|
||||
},
|
||||
operation: {
|
||||
inputFields: [
|
||||
@ -40,6 +41,7 @@ export default {
|
||||
[Operation.create]: Operation.create,
|
||||
[Operation.update]: Operation.update,
|
||||
[Operation.delete]: Operation.delete,
|
||||
[Operation.destroy]: Operation.destroy,
|
||||
},
|
||||
altersDynamicFields: true,
|
||||
},
|
||||
|
||||
@ -11,6 +11,7 @@ export enum Operation {
|
||||
create = 'create',
|
||||
update = 'update',
|
||||
delete = 'delete',
|
||||
destroy = 'destroy',
|
||||
}
|
||||
|
||||
export const subscribe = async (
|
||||
@ -18,18 +19,36 @@ export const subscribe = async (
|
||||
bundle: Bundle,
|
||||
operation: Operation,
|
||||
) => {
|
||||
const data = {
|
||||
targetUrl: bundle.targetUrl,
|
||||
operation: `${operation}.${bundle.inputData.nameSingular}`,
|
||||
};
|
||||
const result = await requestDb(
|
||||
z,
|
||||
bundle,
|
||||
`mutation createWebhook {createWebhook(data:{${handleQueryParams(
|
||||
data,
|
||||
)}}) {id}}`,
|
||||
);
|
||||
return result.data.createWebhook;
|
||||
try {
|
||||
const data = {
|
||||
targetUrl: bundle.targetUrl,
|
||||
operations: [`${bundle.inputData.nameSingular}.${operation}`],
|
||||
};
|
||||
const result = await requestDb(
|
||||
z,
|
||||
bundle,
|
||||
`mutation createWebhook {createWebhook(data:{${handleQueryParams(
|
||||
data,
|
||||
)}}) {id}}`,
|
||||
);
|
||||
return result.data.createWebhook;
|
||||
} catch (e) {
|
||||
// Remove that catch code when VERSION 0.32 is deployed
|
||||
// probably removable after 01/11/2024
|
||||
// (ie: when operations column exists in all active workspace schemas)
|
||||
const data = {
|
||||
targetUrl: bundle.targetUrl,
|
||||
operation: `${bundle.inputData.nameSingular}.${operation}`,
|
||||
};
|
||||
const result = await requestDb(
|
||||
z,
|
||||
bundle,
|
||||
`mutation createWebhook {createWebhook(data:{${handleQueryParams(
|
||||
data,
|
||||
)}}) {id}}`,
|
||||
);
|
||||
return result.data.createWebhook;
|
||||
}
|
||||
};
|
||||
|
||||
export const performUnsubscribe = async (z: ZObject, bundle: Bundle) => {
|
||||
|
||||
Reference in New Issue
Block a user