From c0cf6598e35f82a44e0bef2fb310cba8b04a2661 Mon Sep 17 00:00:00 2001 From: Josh Moore Date: Sun, 16 Jul 2023 22:07:07 -0600 Subject: [PATCH] feat: added existing check for SQL data put --- backend/data.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/data.ts b/backend/data.ts index 27a8b0a..f3998db 100644 --- a/backend/data.ts +++ b/backend/data.ts @@ -132,8 +132,8 @@ export const put = (sector: DataSector, key: NID, data: AssFile | AssUser): Prom } else { // ? SQL - // todo: check existing - await MySql.put('assfiles', key, data); + if (!(await MySql.get('assfiles', key))) await MySql.put('assfiles', key, data); + else return reject(new Error(`File key ${key} already exists`)) // todo: modify users SQL files property } @@ -156,8 +156,8 @@ export const put = (sector: DataSector, key: NID, data: AssFile | AssUser): Prom } else { // ? SQL - // todo: check existing - await MySql.put('assusers', key, data); + if (!(await MySql.get('assusers', key))) await MySql.put('assusers', key, data); + else return reject(new Error(`User key ${key} already exists`)); } }