From 3e0a89f2516cdf46bf81365866994fcde7cc63ff Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Fri, 8 Mar 2024 17:03:07 -0500 Subject: [PATCH] Finish PATCH update for updating eclipse data. --- src/stories/solar-eclipse-2024/database.ts | 2 +- src/stories/solar-eclipse-2024/router.ts | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/stories/solar-eclipse-2024/database.ts b/src/stories/solar-eclipse-2024/database.ts index 74041ae..8288635 100644 --- a/src/stories/solar-eclipse-2024/database.ts +++ b/src/stories/solar-eclipse-2024/database.ts @@ -29,7 +29,7 @@ export const SolarEclipse2024Update = S.struct({ export type SolarEclipse2024DataT = S.Schema.To; export type SolarEclipse2024UpdateT = S.Schema.To; -export async function submitSolarEclipse2024Response(data: SolarEclipse2024DataT): Promise { +export async function submitSolarEclipse2024Data(data: SolarEclipse2024DataT): Promise { logger.verbose(`Attempting to submit solar eclipse 2024 measurement for user ${data.user_uuid}`); const dataWithCounts = { diff --git a/src/stories/solar-eclipse-2024/router.ts b/src/stories/solar-eclipse-2024/router.ts index a65cc55..c64356b 100644 --- a/src/stories/solar-eclipse-2024/router.ts +++ b/src/stories/solar-eclipse-2024/router.ts @@ -4,8 +4,9 @@ import { Router } from "express"; import { getAllSolarEclipse2024Data, getSolarEclipse2024Data, - submitSolarEclipse2024Response, + submitSolarEclipse2024Data, SolarEclipse2024Entry, + updateSolarEclipse2024Data, SolarEclipse2024Update, } from "./database"; @@ -21,7 +22,7 @@ router.put("/data", async (req, res) => { return; } - const response = await submitSolarEclipse2024Response(maybe.right); + const response = await submitSolarEclipse2024Data(maybe.right); if (response === null) { res.status(400); res.json({ error: "Error creating solar eclipse 2024 entry" }); @@ -58,6 +59,13 @@ router.patch("/data/:uuid", async (req, res) => { return; } + const success = await updateSolarEclipse2024Data(uuid, maybe.right); + if (!success) { + res.status(500).json({ error: "Error updating user data" }); + return; + } + res.json({ response }); + }); export default router;