Browse Source

feat(nocodb): construct hook data based on version

pull/5349/head
Wing-Kam Wong 2 years ago
parent
commit
267373591f
  1. 41
      packages/nocodb/src/lib/meta/helpers/webhookHelpers.ts

41
packages/nocodb/src/lib/meta/helpers/webhookHelpers.ts

@ -136,25 +136,30 @@ export async function validateCondition(filters: Filter[], data: any) {
} }
export function constructWebHookData(hook, model, view, prevData, newData) { export function constructWebHookData(hook, model, view, prevData, newData) {
// extend in the future - currently only support records if (hook.version === 'v2') {
const scope = 'records'; // extend in the future - currently only support records
const scope = 'records';
return { return {
type: `${scope}.${hook.event}.${hook.operation}`, type: `${scope}.${hook.event}.${hook.operation}`,
id: uuidv4(), id: uuidv4(),
data: { data: {
table_id: model.id, table_id: model.id,
table_name: model.title, table_name: model.title,
view_id: view.id, view_id: view.id,
view_name: view.title, view_name: view.title,
...(prevData && { ...(prevData && {
[hook.operation === 'delete' ? 'deleted_rows' : 'previous_rows']: [ [hook.operation === 'delete' ? 'deleted_rows' : 'previous_rows']: [
prevData, prevData,
], ],
}), }),
...(newData && { rows: [newData] }), ...(newData && { rows: [newData] }),
}, },
}; };
}
// for v1, keep it as it is
return newData;
} }
export async function handleHttpWebHook( export async function handleHttpWebHook(

Loading…
Cancel
Save