From e2fc9224c757701031b4c2ce9fe1261db73fcd7f Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Sun, 21 Apr 2024 18:09:48 +0800 Subject: [PATCH] fix: fix a problem which custom domain canot direct save by domain check --- src/server/model/monitor/page/manager.ts | 5 ++++- src/server/trpc/routers/monitor.ts | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/server/model/monitor/page/manager.ts b/src/server/model/monitor/page/manager.ts index 62bb7c9..c7e891a 100644 --- a/src/server/model/monitor/page/manager.ts +++ b/src/server/model/monitor/page/manager.ts @@ -50,10 +50,13 @@ class MonitorPageManager { * check domain existed * if domain not been used, return true */ - async checkDomain(domain: string) { + async checkDomain(domain: string, excludeMonitorId?: string) { const res = await prisma.monitorStatusPage.findFirst({ where: { domain, + id: { + notIn: excludeMonitorId ? [excludeMonitorId] : [], + }, }, }); diff --git a/src/server/trpc/routers/monitor.ts b/src/server/trpc/routers/monitor.ts index ae89a74..d6dcc66 100644 --- a/src/server/trpc/routers/monitor.ts +++ b/src/server/trpc/routers/monitor.ts @@ -684,8 +684,8 @@ export const monitorRouter = router({ } } - if (domain && !(await monitorPageManager.checkDomain(domain))) { - throw new Error('This domain has been used'); + if (domain && !(await monitorPageManager.checkDomain(domain, id))) { + throw new Error('This domain has been used by others'); } const page = await prisma.monitorStatusPage.update({