stream day 3

This commit is contained in:
Zoe
2023-01-05 19:16:43 -06:00
parent c55cf2867b
commit 108bb6d6fb
11 changed files with 257 additions and 63 deletions

View File

@@ -0,0 +1,35 @@
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
export default defineEventHandler(async (event) => {
if (!event.context.user.authenticated) return {
message: 'You must be logged in to view a channel.'
}
if (!event.context.params.id) {
event.node.res.statusCode = 400;
return {
message: 'A channelId is required'
}
}
const channel = await prisma.channel.findFirst({
where: {
id: event.context.params.id
},
include: {
messages: true,
}
})
if (!channel) {
event.node.res.statusCode = 404;
return {
message: `Channel with id "${event.context.params.id}" not found`
}
}
return {
channel
}
})