upd: connected ke db

Deskripi:
- list error report general dan per apps
- update status
- update feedback

No Issues
This commit is contained in:
2026-04-14 12:05:34 +08:00
parent 14adaa8526
commit a0cafbf2e2
6 changed files with 963 additions and 180 deletions

View File

@@ -89,7 +89,7 @@ export function createApp() {
access_type: 'offline',
prompt: 'consent',
})
set.status = 302; set.headers['location'] =`https://accounts.google.com/o/oauth2/v2/auth?${params}`
set.status = 302; set.headers['location'] = `https://accounts.google.com/o/oauth2/v2/auth?${params}`
})
.get('/api/auth/callback/google', async ({ request, set }) => {
@@ -98,7 +98,7 @@ export function createApp() {
const origin = url.origin
if (!code) {
set.status = 302; set.headers['location'] ='/login?error=google_failed'
set.status = 302; set.headers['location'] = '/login?error=google_failed'
return
}
@@ -116,7 +116,7 @@ export function createApp() {
})
if (!tokenRes.ok) {
set.status = 302; set.headers['location'] ='/login?error=google_failed'
set.status = 302; set.headers['location'] = '/login?error=google_failed'
return
}
@@ -128,7 +128,7 @@ export function createApp() {
})
if (!userInfoRes.ok) {
set.status = 302; set.headers['location'] ='/login?error=google_failed'
set.status = 302; set.headers['location'] = '/login?error=google_failed'
return
}
@@ -382,6 +382,73 @@ export function createApp() {
return bug
})
.patch('/api/bugs/:id/feedback', async ({ params: { id }, request }) => {
const cookie = request.headers.get('cookie') ?? ''
const token = cookie.match(/session=([^;]+)/)?.[1]
let userId: string | undefined
if (token) {
const session = await prisma.session.findUnique({ where: { token } })
if (session && session.expiresAt > new Date()) {
userId = session.userId
}
}
const body = (await request.json()) as { feedBack: string }
const defaultAdmin = await prisma.user.findFirst({ where: { role: 'SUPER_ADMIN' } })
const actingUserId = userId || defaultAdmin?.id || undefined
const bug = await prisma.bug.update({
where: { id },
data: {
feedBack: body.feedBack,
},
})
if (actingUserId) {
await createSystemLog(actingUserId, 'UPDATE', `Updated bug report feedback - ${id}`)
}
return bug
})
.patch('/api/bugs/:id/status', async ({ params: { id }, request }) => {
const cookie = request.headers.get('cookie') ?? ''
const token = cookie.match(/session=([^;]+)/)?.[1]
let userId: string | undefined
if (token) {
const session = await prisma.session.findUnique({ where: { token } })
if (session && session.expiresAt > new Date()) {
userId = session.userId
}
}
const body = (await request.json()) as { status: string; description?: string }
const defaultAdmin = await prisma.user.findFirst({ where: { role: 'SUPER_ADMIN' } })
const actingUserId = userId || defaultAdmin?.id || undefined
const bug = await prisma.bug.update({
where: { id },
data: {
status: body.status as any,
logs: {
create: {
userId: actingUserId,
status: body.status as any,
description: body.description || `Status updated to ${body.status}`,
},
},
},
})
if (actingUserId) {
await createSystemLog(actingUserId, 'UPDATE', `Updated bug report status to ${body.status}-${id}`)
}
return bug
})
// ─── Example API ───────────────────────────────────
.get('/api/hello', () => ({
message: 'Hello, world!',