Browse Source

fix: email me broken backend logic

pull/3364/head
Wing-Kam Wong 2 years ago
parent
commit
fc60ba6542
  1. 43
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts
  2. 9
      packages/nocodb/src/lib/meta/helpers/webhookHelpers.ts

43
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

@ -1930,6 +1930,46 @@ class BaseModelSqlv2 {
if (hookName === 'After.insert' && view.type === ViewTypes.FORM) {
try {
const formView = await view.getView<FormView>();
const { columns } = await FormView.getWithInfo(formView.fk_view_id);
const allColumns = await this.model.getColumns();
const fieldById = columns.reduce(
(o: Record<string, any>, f: Record<string, any>) => ({
...o,
[f.fk_column_id]: f,
}),
{}
);
let order = 1;
const filteredColumns = allColumns
?.map((c: Record<string, any>) => ({
...c,
fk_column_id: c.id,
fk_view_id: formView.fk_view_id,
...(fieldById[c.id] ? fieldById[c.id] : {}),
order: (fieldById[c.id] && fieldById[c.id].order) || order++,
id: fieldById[c.id] && fieldById[c.id].id,
}))
.sort(
(a: Record<string, any>, b: Record<string, any>) =>
a.order - b.order
)
.filter(
(f: Record<string, any>) =>
f.show &&
f.uidt !== UITypes.Rollup &&
f.uidt !== UITypes.Lookup &&
f.uidt !== UITypes.Formula &&
f.uidt !== UITypes.SpecificDBType
)
.sort(
(a: Record<string, any>, b: Record<string, any>) =>
a.order - b.order
)
.map((c: Record<string, any>) => ({
...c,
required: !!(c.required || 0),
}));
const emails = Object.entries(JSON.parse(formView?.email) || {})
.filter((a) => a[1])
.map((a) => a[0]);
@ -1937,9 +1977,8 @@ class BaseModelSqlv2 {
const transformedData = _transformSubmittedFormDataForEmail(
data,
formView,
await this.model.getColumns()
filteredColumns
);
// todo: notification template
(await NcPluginMgrv2.emailAdapter())?.mailSend({
to: emails.join(','),
subject: 'NocoDB Form',

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

@ -1,7 +1,6 @@
import Handlebars from 'handlebars';
import Model from '../../models/Model';
import NcPluginMgrv2 from './NcPluginMgrv2';
import Column from '../../models/Column';
import Hook from '../../models/Hook';
import Filter from '../../models/Filter';
import HookLog from '../../models/HookLog';
@ -268,16 +267,11 @@ export function _transformSubmittedFormDataForEmail(
// @ts-ignore
formView,
// @ts-ignore
columns: Column[]
columns: Record<string, any>[]
) {
const transformedData = { ...data };
for (const col of columns) {
if (!formView.query_params?.showFields?.[col.title]) {
delete transformedData[col.title];
continue;
}
if (col.uidt === 'Attachment') {
if (typeof transformedData[col.title] === 'string') {
transformedData[col.title] = JSON.parse(transformedData[col.title]);
@ -301,6 +295,7 @@ export function _transformSubmittedFormDataForEmail(
transformedData[col.title] = JSON.stringify(transformedData[col.title]);
}
}
return transformedData;
}
function parseHrtimeToMilliSeconds(hrtime) {

Loading…
Cancel
Save