Browse Source

feat(nocodb): add hookLogList

pull/5349/head
Wing-Kam Wong 2 years ago
parent
commit
a11516c4a9
  1. 22
      packages/nocodb/src/lib/controllers/hook.ctl.ts
  2. 6
      packages/nocodb/src/lib/services/hook.svc.ts

22
packages/nocodb/src/lib/controllers/hook.ctl.ts

@ -4,7 +4,7 @@ import { PagedResponseImpl } from '../meta/helpers/PagedResponse';
import ncMetaAclMw from '../meta/helpers/ncMetaAclMw'; import ncMetaAclMw from '../meta/helpers/ncMetaAclMw';
import { metaApiMetrics } from '../meta/helpers/apiMetrics'; import { metaApiMetrics } from '../meta/helpers/apiMetrics';
import { hookService } from '../services'; import { hookService } from '../services';
import type { HookListType, HookType } from 'nocodb-sdk'; import type { HookListType, HookLogListType, HookType } from 'nocodb-sdk';
import type { Request, Response } from 'express'; import type { Request, Response } from 'express';
export async function hookList( export async function hookList(
@ -63,12 +63,25 @@ export async function tableSampleData(req: Request, res: Response) {
); );
} }
export async function hookLogList(
req: Request<any, any, any>,
res: Response<HookLogListType>
) {
res.json(
new PagedResponseImpl(
await hookService.hookLogList({ tableId: req.params.hookId })
)
);
}
const router = Router({ mergeParams: true }); const router = Router({ mergeParams: true });
router.get( router.get(
'/api/v1/db/meta/tables/:tableId/hooks', '/api/v1/db/meta/tables/:tableId/hooks',
metaApiMetrics, metaApiMetrics,
ncMetaAclMw(hookList, 'hookList') ncMetaAclMw(hookList, 'hookList')
); );
router.post( router.post(
'/api/v1/db/meta/tables/:tableId/hooks/test', '/api/v1/db/meta/tables/:tableId/hooks/test',
metaApiMetrics, metaApiMetrics,
@ -94,4 +107,11 @@ router.get(
metaApiMetrics, metaApiMetrics,
catchError(tableSampleData) catchError(tableSampleData)
); );
router.get(
'/api/v1/db/meta/hooks/:hookId/logs',
metaApiMetrics,
ncMetaAclMw(hookLogList, 'hookLogList')
);
export default router; export default router;

6
packages/nocodb/src/lib/services/hook.svc.ts

@ -1,7 +1,7 @@
import { T } from 'nc-help'; import { T } from 'nc-help';
import { validatePayload } from '../meta/api/helpers'; import { validatePayload } from '../meta/api/helpers';
import { NcError } from '../meta/helpers/catchError'; import { NcError } from '../meta/helpers/catchError';
import { Hook, Model } from '../models'; import { Hook, HookLog, Model } from '../models';
import { invokeWebhook } from '../meta/helpers/webhookHelpers'; import { invokeWebhook } from '../meta/helpers/webhookHelpers';
import populateSamplePayload from '../meta/helpers/populateSamplePayload'; import populateSamplePayload from '../meta/helpers/populateSamplePayload';
import type { HookReqType, HookTestReqType } from 'nocodb-sdk'; import type { HookReqType, HookTestReqType } from 'nocodb-sdk';
@ -26,6 +26,10 @@ export async function hookList(param: { tableId: string }) {
return await Hook.list({ fk_model_id: param.tableId }); return await Hook.list({ fk_model_id: param.tableId });
} }
export async function hookLogList(param: { hookId: string }) {
return await HookLog.list({ fk_hook_id: param.hookId });
}
export async function hookCreate(param: { export async function hookCreate(param: {
tableId: string; tableId: string;
hook: HookReqType; hook: HookReqType;

Loading…
Cancel
Save