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) {
// extend in the future - currently only support records
const scope = 'records';
if (hook.version === 'v2') {
// extend in the future - currently only support records
const scope = 'records';
return {
type: `${scope}.${hook.event}.${hook.operation}`,
id: uuidv4(),
data: {
table_id: model.id,
table_name: model.title,
view_id: view.id,
view_name: view.title,
...(prevData && {
[hook.operation === 'delete' ? 'deleted_rows' : 'previous_rows']: [
prevData,
],
}),
...(newData && { rows: [newData] }),
},
};
return {
type: `${scope}.${hook.event}.${hook.operation}`,
id: uuidv4(),
data: {
table_id: model.id,
table_name: model.title,
view_id: view.id,
view_name: view.title,
...(prevData && {
[hook.operation === 'delete' ? 'deleted_rows' : 'previous_rows']: [
prevData,
],
}),
...(newData && { rows: [newData] }),
},
};
}
// for v1, keep it as it is
return newData;
}
export async function handleHttpWebHook(

Loading…
Cancel
Save