Skip to content

Commit

Permalink
fix: using demo correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyLzq committed Jan 18, 2024
1 parent bb26d0e commit 77b1087
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/database/firebase/queries/realTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -65,19 +65,18 @@ const updateDate = ({
value,
demo = false
}: Update<string>) => {
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.')
}
)
}
)
}
Expand Down Expand Up @@ -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}`)
}
Expand Down

0 comments on commit 77b1087

Please sign in to comment.