From ce7012de3a64c922249b04ed0b71d49cff799d90 Mon Sep 17 00:00:00 2001 From: jusax23 Date: Wed, 29 Mar 2023 11:11:59 +0200 Subject: [PATCH] instert fix fix --- src/api/acts/admin.ts | 3 ++- src/api/acts/rooms.ts | 3 ++- src/sys/settings.ts | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/api/acts/admin.ts b/src/api/acts/admin.ts index 89011e1..06be2b9 100644 --- a/src/api/acts/admin.ts +++ b/src/api/acts/admin.ts @@ -143,9 +143,10 @@ export const addOTA: Act = { }, func: async (client: Client, data: any, aws: (code: string, data: any) => void) => { try { - await insert(signupOTA.token, signupOTA.expires, signupOTA.usesLeft) + let resp = await insert(signupOTA.token, signupOTA.expires, signupOTA.usesLeft) .add(data.token, data.expires, data.usesLeft) .query(db); + if(resp.affectedRows == 0) throw new Error("insertion fail"); } catch (error) { await update(signupOTA) .set(signupOTA.expires, data.expires) diff --git a/src/api/acts/rooms.ts b/src/api/acts/rooms.ts index 70f9e84..9d1bd47 100644 --- a/src/api/acts/rooms.ts +++ b/src/api/acts/rooms.ts @@ -384,9 +384,10 @@ export const addRoomOTA: Act = { // or change it, primary key is room and token let roomID = await client.isRoomAdmin(data.room, ROOM_RIGHTS.OTA); if (roomID == -1) return void aws("error", "roomAdmin"); try { - await insert(roomOTAs.roomID, roomOTAs.token, roomOTAs.name, roomOTAs.expires, roomOTAs.usesLeft) + let resp = await insert(roomOTAs.roomID, roomOTAs.token, roomOTAs.name, roomOTAs.expires, roomOTAs.usesLeft) .add(roomID, data.token, data.name, data.expires, data.usesLeft) .query(db); + if (resp.affectedRows == 0) throw new Error("insertion fail"); } catch (error) { await update(roomOTAs) .set(roomOTAs.expires, data.expires) diff --git a/src/sys/settings.ts b/src/sys/settings.ts index 62f54c3..dc11a6e 100644 --- a/src/sys/settings.ts +++ b/src/sys/settings.ts @@ -19,9 +19,10 @@ export const getSettings = async (type: string) => { export const setSettings = async (type: string, data: string) => { try { - await insert(settings.type, settings.data) + let resp = await insert(settings.type, settings.data) .add(type, data) .query(db); + if (resp.affectedRows == 0) throw new Error("insertion fail"); } catch (error) { await update(settings) .set(settings.data, data)