From 77b108758179157decafc8e78cd386066e019725 Mon Sep 17 00:00:00 2001 From: AnthonyLzq Date: Thu, 18 Jan 2024 00:00:34 -0500 Subject: [PATCH] fix: using demo correctly --- src/database/firebase/queries/realTime.ts | 27 ++++++++++++----------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/database/firebase/queries/realTime.ts b/src/database/firebase/queries/realTime.ts index 2a0952a..3a2ab31 100644 --- a/src/database/firebase/queries/realTime.ts +++ b/src/database/firebase/queries/realTime.ts @@ -14,7 +14,7 @@ const clientData = z.object({ pm2_5: z.number(), pressure: z.number(), temperature: z.number(), - demo: z.boolean().optional().default(false) + demo: z.boolean().optional() }) declare global { @@ -65,19 +65,18 @@ const updateDate = ({ value, demo = false }: Update) => { - if (demo) - db.ref(`/${MAIN_TOPIC}/${id}/${moduleId}/${sensorId}/demo`).set( - true, - error => { - if (error) realTimeDebug(`Error: ${error}`) - } - ) - - db.ref(`/${MAIN_TOPIC}/${id}/${moduleId}/${sensorId}/date`).set( - value, + db.ref(`/${MAIN_TOPIC}/${id}/${moduleId}/${sensorId}/demo`).set( + demo, error => { if (error) realTimeDebug(`Error: ${error}`) - else realTimeDebug('Date updated.') + else + db.ref(`/${MAIN_TOPIC}/${id}/${moduleId}/${sensorId}/date`).set( + value, + error => { + if (error) realTimeDebug(`Error: ${error}`) + else realTimeDebug('Date updated.') + } + ) } ) } @@ -155,8 +154,10 @@ const listenChangesInDate = ({ const data = await getData({ db, id, moduleId, sensorId }) if (data && !data.demo) { + const { demo: _, ...rest } = data + try { - await saveClientData(z.coerce.number().parse(sensorId), data) + await saveClientData(z.coerce.number().parse(sensorId), rest) } catch (error) { realTimeDebug(`Error: ${error}`) }