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 { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
|
||||||
import { Command } from 'nest-commander';
|
import { Command } from 'nest-commander';
|
||||||
import { Repository } from 'typeorm';
|
import { ObjectLiteral, Repository } from 'typeorm';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
|
|
||||||
import { ActiveWorkspacesCommandRunner } from 'src/database/commands/active-workspaces.command';
|
import { ActiveWorkspacesCommandRunner } from 'src/database/commands/active-workspaces.command';
|
||||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||||
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
|
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
|
||||||
import { BaseCommandOptions } from 'src/database/commands/base.command';
|
import { BaseCommandOptions } from 'src/database/commands/base.command';
|
||||||
|
import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository';
|
||||||
|
|
||||||
@Command({
|
@Command({
|
||||||
name: 'upgrade-0.32:copy-webhook-operation-into-operations',
|
name: 'upgrade-0.32:copy-webhook-operation-into-operations',
|
||||||
@ -43,11 +44,21 @@ export class CopyWebhookOperationIntoOperationsCommand extends ActiveWorkspacesC
|
|||||||
|
|
||||||
for (const webhook of webhooks) {
|
for (const webhook of webhooks) {
|
||||||
if ('operation' in webhook) {
|
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, {
|
await webhookRepository.update(webhook.id, {
|
||||||
operations: [webhook.operation],
|
operation: newOperation,
|
||||||
|
operations: [newOperation],
|
||||||
});
|
});
|
||||||
|
|
||||||
this.logger.log(
|
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)
|
@Process(CallWebhookJobsJob.name)
|
||||||
async handle(data: CallWebhookJobsJobData): Promise<void> {
|
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 =
|
const webhookRepository =
|
||||||
await this.twentyORMGlobalManager.getRepositoryForWorkspace<WebhookWorkspaceEntity>(
|
await this.twentyORMGlobalManager.getRepositoryForWorkspace<WebhookWorkspaceEntity>(
|
||||||
data.workspaceId,
|
data.workspaceId,
|
||||||
|
|||||||
@ -21,7 +21,8 @@ export default {
|
|||||||
noun: 'Record',
|
noun: 'Record',
|
||||||
display: {
|
display: {
|
||||||
label: 'Record Trigger',
|
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: {
|
operation: {
|
||||||
inputFields: [
|
inputFields: [
|
||||||
@ -40,6 +41,7 @@ export default {
|
|||||||
[Operation.create]: Operation.create,
|
[Operation.create]: Operation.create,
|
||||||
[Operation.update]: Operation.update,
|
[Operation.update]: Operation.update,
|
||||||
[Operation.delete]: Operation.delete,
|
[Operation.delete]: Operation.delete,
|
||||||
|
[Operation.destroy]: Operation.destroy,
|
||||||
},
|
},
|
||||||
altersDynamicFields: true,
|
altersDynamicFields: true,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -11,6 +11,7 @@ export enum Operation {
|
|||||||
create = 'create',
|
create = 'create',
|
||||||
update = 'update',
|
update = 'update',
|
||||||
delete = 'delete',
|
delete = 'delete',
|
||||||
|
destroy = 'destroy',
|
||||||
}
|
}
|
||||||
|
|
||||||
export const subscribe = async (
|
export const subscribe = async (
|
||||||
@ -18,18 +19,36 @@ export const subscribe = async (
|
|||||||
bundle: Bundle,
|
bundle: Bundle,
|
||||||
operation: Operation,
|
operation: Operation,
|
||||||
) => {
|
) => {
|
||||||
const data = {
|
try {
|
||||||
targetUrl: bundle.targetUrl,
|
const data = {
|
||||||
operation: `${operation}.${bundle.inputData.nameSingular}`,
|
targetUrl: bundle.targetUrl,
|
||||||
};
|
operations: [`${bundle.inputData.nameSingular}.${operation}`],
|
||||||
const result = await requestDb(
|
};
|
||||||
z,
|
const result = await requestDb(
|
||||||
bundle,
|
z,
|
||||||
`mutation createWebhook {createWebhook(data:{${handleQueryParams(
|
bundle,
|
||||||
data,
|
`mutation createWebhook {createWebhook(data:{${handleQueryParams(
|
||||||
)}}) {id}}`,
|
data,
|
||||||
);
|
)}}) {id}}`,
|
||||||
return result.data.createWebhook;
|
);
|
||||||
|
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) => {
|
export const performUnsubscribe = async (z: ZObject, bundle: Bundle) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user