Browse Source

feat: export/import webhooks

Signed-off-by: mertmit <mertmit99@gmail.com>
feat/export-nest
mertmit 2 years ago
parent
commit
f6742292a6
  1. 50
      packages/nocodb/src/modules/jobs/export-import/export.service.ts
  2. 48
      packages/nocodb/src/modules/jobs/export-import/import.service.ts
  3. 1
      packages/nocodb/src/modules/metas/metas.module.ts

50
packages/nocodb/src/modules/jobs/export-import/export.service.ts

@ -10,7 +10,7 @@ import {
} from '../../../helpers/exportImportHelpers'; } from '../../../helpers/exportImportHelpers';
import NcPluginMgrv2 from '../../../helpers/NcPluginMgrv2'; import NcPluginMgrv2 from '../../../helpers/NcPluginMgrv2';
import { NcError } from '../../../helpers/catchError'; import { NcError } from '../../../helpers/catchError';
import { Base, Model, Project } from '../../../models'; import { Base, Hook, Model, Project } from '../../../models';
import { DatasService } from '../../../services/datas.service'; import { DatasService } from '../../../services/datas.service';
import type { BaseModelSqlv2 } from '../../../db/BaseModelSqlv2'; import type { BaseModelSqlv2 } from '../../../db/BaseModelSqlv2';
import type { LinkToAnotherRecordColumn, View } from '../../../models'; import type { LinkToAnotherRecordColumn, View } from '../../../models';
@ -27,6 +27,7 @@ export class ExportService {
const { modelIds } = param; const { modelIds } = param;
const excludeViews = param?.excludeViews || false; const excludeViews = param?.excludeViews || false;
const excludeHooks = param?.excludeHooks || false;
const serializedModels = []; const serializedModels = [];
@ -182,6 +183,52 @@ export class ExportService {
} }
} }
const serializedHooks = [];
if (!excludeHooks) {
const hooks = await Hook.list({ fk_model_id: model.id });
for (const hook of hooks) {
idMap.set(hook.id, `${idMap.get(hook.fk_model_id)}::${hook.id}`);
const hookFilters = await hook.getFilters();
const export_filters = [];
if (hookFilters) {
for (const fl of hookFilters) {
const tempFl = {
id: `${idMap.get(hook.id)}::${fl.id}`,
fk_column_id: idMap.get(fl.fk_column_id),
fk_parent_id: fl.fk_parent_id,
is_group: fl.is_group,
logical_op: fl.logical_op,
comparison_op: fl.comparison_op,
comparison_sub_op: fl.comparison_sub_op,
value: fl.value,
};
if (tempFl.is_group) {
delete tempFl.comparison_op;
delete tempFl.comparison_sub_op;
delete tempFl.value;
}
export_filters.push(tempFl);
}
}
serializedHooks.push({
id: idMap.get(hook.id),
title: hook.title,
active: hook.active,
condition: hook.condition,
event: hook.event,
operation: hook.operation,
notification: hook.notification,
version: hook.version,
filters: export_filters,
});
}
}
serializedModels.push({ serializedModels.push({
model: { model: {
id: idMap.get(model.id), id: idMap.get(model.id),
@ -239,6 +286,7 @@ export class ExportService {
}), }),
view: view.view, view: view.view,
})), })),
hooks: serializedHooks,
}); });
} }

48
packages/nocodb/src/modules/jobs/export-import/import.service.ts

@ -23,6 +23,7 @@ import { GridsService } from '../../../services/grids.service';
import { FormsService } from '../../../services/forms.service'; import { FormsService } from '../../../services/forms.service';
import { GalleriesService } from '../../../services/galleries.service'; import { GalleriesService } from '../../../services/galleries.service';
import { KanbansService } from '../../../services/kanbans.service'; import { KanbansService } from '../../../services/kanbans.service';
import { HooksService } from '../../../services/hooks.service';
import NcPluginMgrv2 from '../../../helpers/NcPluginMgrv2'; import NcPluginMgrv2 from '../../../helpers/NcPluginMgrv2';
import { BulkDataAliasService } from '../../../services/bulk-data-alias.service'; import { BulkDataAliasService } from '../../../services/bulk-data-alias.service';
import type { ViewCreateReqType } from 'nocodb-sdk'; import type { ViewCreateReqType } from 'nocodb-sdk';
@ -43,6 +44,7 @@ export class ImportService {
private galleriesService: GalleriesService, private galleriesService: GalleriesService,
private kanbansService: KanbansService, private kanbansService: KanbansService,
private bulkDataService: BulkDataAliasService, private bulkDataService: BulkDataAliasService,
private hooksService: HooksService,
) {} ) {}
async importModels(param: { async importModels(param: {
@ -50,8 +52,8 @@ export class ImportService {
projectId: string; projectId: string;
baseId: string; baseId: string;
data: data:
| { models: { model: any; views: any[] }[] } | { models: { model: any; views: any[]; hooks?: any[] }[] }
| { model: any; views: any[] }[]; | { model: any; views: any[]; hooks?: any[] }[];
req: any; req: any;
externalModels?: Model[]; externalModels?: Model[];
}) { }) {
@ -936,6 +938,48 @@ export class ImportService {
} }
} }
// create hooks
for (const data of param.data) {
if (!data?.hooks) break;
const modelData = data.model;
const hookData = data.hooks;
const table = tableReferences.get(modelData.id);
for (const hook of hookData) {
const { filters, ...rest } = hook;
const hookData = withoutId({
...rest,
});
const hk = await this.hooksService.hookCreate({
tableId: table.id,
hook: {
...hookData,
},
});
if (!hk) continue;
idMap.set(hook.id, hk.id);
// create filters
for (const fl of filters) {
const fg = await this.filtersService.hookFilterCreate({
hookId: hk.id,
filter: withoutId({
...fl,
fk_column_id: idMap.get(fl.fk_column_id),
fk_parent_id: idMap.get(fl.fk_parent_id),
}),
});
idMap.set(fl.id, fg.id);
}
}
}
return idMap; return idMap;
} }

1
packages/nocodb/src/modules/metas/metas.module.ts

@ -170,6 +170,7 @@ import { DatasModule } from '../datas/datas.module';
ProjectsService, ProjectsService,
AttachmentsService, AttachmentsService,
ProjectUsersService, ProjectUsersService,
HooksService,
], ],
}) })
export class MetasModule {} export class MetasModule {}

Loading…
Cancel
Save