Fixed hardcoded id in /me query (whoops)
This commit is contained in:
@@ -32,9 +32,27 @@ router.get('/', async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/me', (req, res) => {
|
router.get('/me', async (req, res) => {
|
||||||
console.log(req.user);
|
console.log(req.user);
|
||||||
res.json(req.user);
|
if (req.user === undefined)
|
||||||
|
return res.sendStatus(401)
|
||||||
|
|
||||||
|
try {
|
||||||
|
const LOAData = await pool.query(
|
||||||
|
`SELECT *
|
||||||
|
FROM leave_of_absences
|
||||||
|
WHERE member_id = ?
|
||||||
|
AND deleted = 0
|
||||||
|
AND UTC_TIMESTAMP() BETWEEN start_date AND end_date;`, req.user.id)
|
||||||
|
const userWithLOA = {
|
||||||
|
...req.user,
|
||||||
|
loa: LOAData
|
||||||
|
};
|
||||||
|
res.json(userWithLOA);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching LOA data:', error);
|
||||||
|
return res.status(500).json({ error: 'Failed to fetch user data' });
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
router.get('/:id', async (req, res) => {
|
router.get('/:id', async (req, res) => {
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import {
|
|||||||
} from './components/ui/dropdown-menu';
|
} from './components/ui/dropdown-menu';
|
||||||
import { onMounted } from 'vue';
|
import { onMounted } from 'vue';
|
||||||
import { useUserStore } from './stores/user';
|
import { useUserStore } from './stores/user';
|
||||||
|
import Alert from './components/ui/alert/Alert.vue';
|
||||||
|
import AlertDescription from './components/ui/alert/AlertDescription.vue';
|
||||||
|
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
|
|
||||||
@@ -30,6 +32,15 @@ async function logout() {
|
|||||||
|
|
||||||
userStore.user = null;
|
userStore.user = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatDate(dateStr) {
|
||||||
|
if (!dateStr) return "";
|
||||||
|
return new Date(dateStr).toLocaleDateString("en-US", {
|
||||||
|
year: "numeric",
|
||||||
|
month: "short",
|
||||||
|
day: "numeric",
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -85,7 +96,7 @@ async function logout() {
|
|||||||
<DropdownMenuTrigger class="cursor-pointer">
|
<DropdownMenuTrigger class="cursor-pointer">
|
||||||
<p>{{ userStore.user.name }}</p>
|
<p>{{ userStore.user.name }}</p>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent>
|
<DropdownMenuContent>
|
||||||
<DropdownMenuItem>My Profile</DropdownMenuItem>
|
<DropdownMenuItem>My Profile</DropdownMenuItem>
|
||||||
<DropdownMenuItem>Settings</DropdownMenuItem>
|
<DropdownMenuItem>Settings</DropdownMenuItem>
|
||||||
<DropdownMenuItem>
|
<DropdownMenuItem>
|
||||||
@@ -101,6 +112,12 @@ async function logout() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Separator></Separator>
|
<Separator></Separator>
|
||||||
|
<Alert class="m-2 mx-auto w-5xl" variant="info">
|
||||||
|
<AlertDescription class="flex flex-row items-center text-nowrap gap-5 mx-auto">
|
||||||
|
<p>You are on LOA until <strong>{{ formatDate(userStore.user?.loa?.[0].end_date) }}</strong></p>
|
||||||
|
<Button variant="secondary">End LOA</Button>
|
||||||
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
|
||||||
<RouterView></RouterView>
|
<RouterView></RouterView>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user