From c079971a7b13eedec18b0885930700c4469827e0 Mon Sep 17 00:00:00 2001 From: Peace Date: Thu, 17 Oct 2024 00:05:29 +0200 Subject: [PATCH] fix: cast getParent and getChildren to Beans --- server/model/monitor.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 7f9185be2..e5580a2e8 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -1629,10 +1629,10 @@ class Monitor extends BeanModel { /** * Gets Parent of the monitor * @param {number} monitorID ID of monitor to get - * @returns {Promise>} Parent + * @returns {Promise} Parent */ static async getParent(monitorID) { - return await R.getRow(` + const result = await R.getRow(` SELECT parent.* FROM monitor parent LEFT JOIN monitor child ON child.parent = parent.id @@ -1640,20 +1640,25 @@ class Monitor extends BeanModel { `, [ monitorID, ]); + + if (!result) { + return null; + } + return R.convertToBean("monitor", result); } /** * Gets all Children of the monitor * @param {number} monitorID ID of monitor to get - * @returns {Promise>} Children + * @returns {Promise} Children */ static async getChildren(monitorID) { - return await R.getAll(` + return R.convertToBeans("monitor", await R.getAll(` SELECT * FROM monitor WHERE parent = ? `, [ monitorID, - ]); + ])); } /**