-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
integrated frontend & backend for log history
- Loading branch information
1 parent
4cc1919
commit c7a814f
Showing
9 changed files
with
93 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import express from "express"; | ||
import auth from "../middlewares/auth.js"; | ||
import { getUserLogs } from "../services/logs-service.js"; | ||
|
||
const router = express.Router(); | ||
|
||
router.get("", auth, async (req, res) => { | ||
const userLogs = await getUserLogs(req); | ||
if (userLogs.error) { | ||
res.status(500).json({ error: userLogs.error }); | ||
} else { | ||
res.status(200).json({ data: userLogs }); | ||
} | ||
}) | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import getTable from "../utils/get-table.js"; | ||
import { getUserLogbooks } from "./logbooks-service.js"; | ||
|
||
export async function getUserLogs(req) { | ||
try { | ||
const supabase = req.supabase; | ||
const userLogbooks = await getUserLogbooks(req); | ||
if (userLogbooks.error) { | ||
throw new Error(userLogbooks.error) | ||
} | ||
const logs = []; | ||
for (const logbook of userLogbooks) { | ||
const logbookLogs = await getTable(supabase, logbook.type, "logbook_id", logbook.id, "collection"); | ||
logs.push(...logbookLogs) | ||
} | ||
return logs; | ||
} catch (error) { | ||
return { error: error.message }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** Formats date from "YYYY-MM-DD HH:MM:SS.ssssss+TZ" to "YYYY-MM-DD" */ | ||
export default function formatDate(date) { | ||
const createdDate = new Date(date); | ||
return createdDate.toLocaleDateString('en-CA'); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** Formats a given log type to a more readable display name */ | ||
export default function formatType(type) { | ||
let formattedType; | ||
switch (type) { | ||
case "adult_cardiac_logs": | ||
formattedType = "Cardiac Surgery - Adult"; | ||
break; | ||
case "congenital_surgery_logs": | ||
formattedType = "Cardiac Surgery - Congenital"; | ||
break; | ||
case "general_surgery_logs": | ||
formattedType = "General Surgery"; | ||
break; | ||
case "gyn_logs": | ||
formattedType = "Obstetrics/Gynecology"; | ||
break; | ||
case "ob_logs": | ||
formattedType = "Obstetrics/Gynecology"; | ||
break; | ||
default: | ||
formattedType = "Unknown Type"; | ||
break; | ||
} | ||
return formattedType; | ||
} |