Browse Source

fix: data in http client webhook, condition correction

* Made data available in http client fields(params, body, headers)
* Fixed condition issue

closes #296, closes #237

Signed-off-by: Pranav C <61551451+pranavxc@users.noreply.github.com>
pull/306/head
Pranav C 3 years ago
parent
commit
e76ab03fc8
  1. 37
      packages/nocodb/src/lib/noco/common/BaseModel.ts

37
packages/nocodb/src/lib/noco/common/BaseModel.ts

@ -102,7 +102,7 @@ class BaseModel<T extends BaseApiBuilder<any>> extends BaseModelSql {
}) })
break; break;
case 'URL': case 'URL':
this.handleHttpWebHook(hook.notification?.payload) this.handleHttpWebHook(hook.notification?.payload, req, data)
break; break;
default: default:
if (this.webhookNotificationAdapters && hook.notification?.type && hook.notification?.type in this.webhookNotificationAdapters) { if (this.webhookNotificationAdapters && hook.notification?.type && hook.notification?.type in this.webhookNotificationAdapters) {
@ -121,26 +121,30 @@ class BaseModel<T extends BaseApiBuilder<any>> extends BaseModelSql {
} }
} }
private async handleHttpWebHook(apiMeta) { private async handleHttpWebHook(apiMeta, apiReq, data) {
try { try {
const req = this.axiosRequestMake(apiMeta); const req = this.axiosRequestMake(apiMeta, apiReq, data);
await require('axios')(req); await require('axios')(req);
} catch (e) { } catch (e) {
console.log(e) console.log(e)
} }
} }
private axiosRequestMake(apiMeta) { private axiosRequestMake(apiMeta, apiReq, data) {
if (apiMeta.body) { if (apiMeta.body) {
try { try {
apiMeta.body = JSON.parse(apiMeta.body); apiMeta.body = JSON.parse(apiMeta.body, (_key, value) => {
return typeof value === 'string' ? this.parseBody(value, apiReq, data, apiMeta) : value;
});
} catch (e) { } catch (e) {
console.log(e); console.log(e);
} }
} }
if (apiMeta.auth) { if (apiMeta.auth) {
try { try {
apiMeta.auth = JSON.parse(apiMeta.auth); apiMeta.auth = JSON.parse(apiMeta.auth, (_key, value) => {
return typeof value === 'string' ? this.parseBody(value, apiReq, data, apiMeta) : value;
});
} catch (e) { } catch (e) {
console.log(e); console.log(e);
} }
@ -149,7 +153,7 @@ class BaseModel<T extends BaseApiBuilder<any>> extends BaseModelSql {
const req = { const req = {
params: apiMeta.parameters ? apiMeta.parameters.reduce((paramsObj, param) => { params: apiMeta.parameters ? apiMeta.parameters.reduce((paramsObj, param) => {
if (param.name && param.enabled) { if (param.name && param.enabled) {
paramsObj[param.name] = param.value; paramsObj[param.name] = this.parseBody(param.value, apiReq, data, apiMeta);
} }
return paramsObj; return paramsObj;
}, {}) : {}, }, {}) : {},
@ -158,7 +162,7 @@ class BaseModel<T extends BaseApiBuilder<any>> extends BaseModelSql {
data: apiMeta.body, data: apiMeta.body,
headers: apiMeta.headers ? apiMeta.headers.reduce((headersObj, header) => { headers: apiMeta.headers ? apiMeta.headers.reduce((headersObj, header) => {
if (header.name && header.enabled) { if (header.name && header.enabled) {
headersObj[header.name] = header.value; headersObj[header.name] = this.parseBody(header.value, apiReq, data, apiMeta);
} }
return headersObj; return headersObj;
}, {}) : {}, }, {}) : {},
@ -186,31 +190,32 @@ class BaseModel<T extends BaseApiBuilder<any>> extends BaseModelSql {
const isValid = condition.reduce((valid, con) => { const isValid = condition.reduce((valid, con) => {
let res; let res;
const field = this.columnToAlias[con.field] ?? con.field;
switch (con.op as string) { switch (con.op as string) {
case 'is equal': case 'is equal':
res = data[con.field] === con.value; res = data[field] === con.value;
break; break;
case 'is not equal': case 'is not equal':
res = data[con.field] !== con.value; res = data[field] !== con.value;
break; break;
case 'is like': case 'is like':
res = data[con.field]?.toLowerCase()?.indexOf(con.value?.toLowerCase()) > -1; res = data[field]?.toLowerCase()?.indexOf(con.value?.toLowerCase()) > -1;
break; break;
case 'is not like': case 'is not like':
res = data[con.field]?.toLowerCase()?.indexOf(con.value?.toLowerCase()) === -1; res = data[field]?.toLowerCase()?.indexOf(con.value?.toLowerCase()) === -1;
break; break;
case 'is empty': case 'is empty':
res = data[con.field] === '' || data[con.field] === null || data[con.field] === undefined; res = data[field] === '' || data[field] === null || data[field] === undefined;
break; break;
case 'is not empty': case 'is not empty':
res = !(data[con.field] === '' || data[con.field] === null || data[con.field] === undefined); res = !(data[field] === '' || data[field] === null || data[field] === undefined);
break; break;
case 'is null': case 'is null':
res = res =
res = data[con.field] === null; res = data[field] === null;
break; break;
case 'is not null': case 'is not null':
res = data[con.field] !== null; res = data[field] !== null;
break; break;

Loading…
Cancel
Save