mirror of https://github.com/TZGyn/shortener
added get shortener by id route
parent
064dc8c157
commit
7de2344824
@ -0,0 +1,20 @@
|
||||
import { db } from '$lib/db'
|
||||
import type { PageServerLoad } from './$types'
|
||||
|
||||
export const load = (async (event) => {
|
||||
const user = event.locals.userObject
|
||||
const shortenerId = event.params.id
|
||||
|
||||
const shortener = await db.query.shortener.findFirst({
|
||||
where: (shortener, { eq, and }) =>
|
||||
and(
|
||||
eq(shortener.code, shortenerId),
|
||||
eq(shortener.userId, user.id),
|
||||
),
|
||||
with: {
|
||||
visitor: true,
|
||||
},
|
||||
})
|
||||
|
||||
return { shortener }
|
||||
}) satisfies PageServerLoad
|
||||
@ -0,0 +1,7 @@
|
||||
<script lang="ts">
|
||||
import type { PageData } from './$types'
|
||||
|
||||
export let data: PageData
|
||||
</script>
|
||||
|
||||
{JSON.stringify(data.shortener)}
|
||||
Loading…
Reference in New Issue