From a11516c4a9d6c7ff2c5fc4f595fd728193edc19e Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Fri, 24 Mar 2023 19:18:17 +0800 Subject: [PATCH] feat(nocodb): add hookLogList --- .../nocodb/src/lib/controllers/hook.ctl.ts | 22 ++++++++++++++++++- packages/nocodb/src/lib/services/hook.svc.ts | 6 ++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/nocodb/src/lib/controllers/hook.ctl.ts b/packages/nocodb/src/lib/controllers/hook.ctl.ts index 7e671d2ec1..7e158b878d 100644 --- a/packages/nocodb/src/lib/controllers/hook.ctl.ts +++ b/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 { metaApiMetrics } from '../meta/helpers/apiMetrics'; 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'; export async function hookList( @@ -63,12 +63,25 @@ export async function tableSampleData(req: Request, res: Response) { ); } +export async function hookLogList( + req: Request, + res: Response +) { + res.json( + new PagedResponseImpl( + await hookService.hookLogList({ tableId: req.params.hookId }) + ) + ); +} + const router = Router({ mergeParams: true }); + router.get( '/api/v1/db/meta/tables/:tableId/hooks', metaApiMetrics, ncMetaAclMw(hookList, 'hookList') ); + router.post( '/api/v1/db/meta/tables/:tableId/hooks/test', metaApiMetrics, @@ -94,4 +107,11 @@ router.get( metaApiMetrics, catchError(tableSampleData) ); + +router.get( + '/api/v1/db/meta/hooks/:hookId/logs', + metaApiMetrics, + ncMetaAclMw(hookLogList, 'hookLogList') +); + export default router; diff --git a/packages/nocodb/src/lib/services/hook.svc.ts b/packages/nocodb/src/lib/services/hook.svc.ts index 04d2dc5f96..ec5d32f669 100644 --- a/packages/nocodb/src/lib/services/hook.svc.ts +++ b/packages/nocodb/src/lib/services/hook.svc.ts @@ -1,7 +1,7 @@ import { T } from 'nc-help'; import { validatePayload } from '../meta/api/helpers'; import { NcError } from '../meta/helpers/catchError'; -import { Hook, Model } from '../models'; +import { Hook, HookLog, Model } from '../models'; import { invokeWebhook } from '../meta/helpers/webhookHelpers'; import populateSamplePayload from '../meta/helpers/populateSamplePayload'; 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 }); } +export async function hookLogList(param: { hookId: string }) { + return await HookLog.list({ fk_hook_id: param.hookId }); +} + export async function hookCreate(param: { tableId: string; hook: HookReqType;