upd: bug list
Deskripsi: - tampilan list bug error - tampilan tambah bug - connected to database; list and create No Issues
This commit is contained in:
90
src/app.ts
90
src/app.ts
@@ -260,6 +260,96 @@ export function createApp() {
|
||||
})
|
||||
})
|
||||
|
||||
.get('/api/bugs', async ({ query }) => {
|
||||
const page = Number(query.page) || 1
|
||||
const limit = Number(query.limit) || 20
|
||||
const search = (query.search as string) || ''
|
||||
const app = query.app as any
|
||||
const status = query.status as any
|
||||
|
||||
const where: any = {}
|
||||
if (search) {
|
||||
where.OR = [
|
||||
{ description: { contains: search, mode: 'insensitive' } },
|
||||
{ device: { contains: search, mode: 'insensitive' } },
|
||||
{ os: { contains: search, mode: 'insensitive' } },
|
||||
{ affectedVersion: { contains: search, mode: 'insensitive' } },
|
||||
]
|
||||
}
|
||||
if (app && app !== 'all') {
|
||||
where.app = app
|
||||
}
|
||||
if (status && status !== 'all') {
|
||||
where.status = status
|
||||
}
|
||||
|
||||
const [bugs, total] = await Promise.all([
|
||||
prisma.bug.findMany({
|
||||
where,
|
||||
include: {
|
||||
user: { select: { id: true, name: true, email: true, image: true } },
|
||||
images: true,
|
||||
logs: {
|
||||
include: { user: { select: { id: true, name: true, image: true } } },
|
||||
orderBy: { createdAt: 'desc' },
|
||||
},
|
||||
},
|
||||
orderBy: { createdAt: 'desc' },
|
||||
skip: (page - 1) * limit,
|
||||
take: limit,
|
||||
}),
|
||||
prisma.bug.count({ where }),
|
||||
])
|
||||
|
||||
return {
|
||||
data: bugs,
|
||||
totalPages: Math.ceil(total / limit),
|
||||
totalItems: total,
|
||||
}
|
||||
})
|
||||
|
||||
.post('/api/bugs', async ({ request, set }) => {
|
||||
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 any
|
||||
const bug = await prisma.bug.create({
|
||||
data: {
|
||||
app: body.app,
|
||||
affectedVersion: body.affectedVersion,
|
||||
device: body.device,
|
||||
os: body.os,
|
||||
status: body.status || 'OPEN',
|
||||
source: body.source || 'USER',
|
||||
description: body.description,
|
||||
stackTrace: body.stackTrace,
|
||||
userId: userId,
|
||||
images: body.imageUrl ? {
|
||||
create: {
|
||||
imageUrl: body.imageUrl
|
||||
}
|
||||
} : undefined,
|
||||
logs: {
|
||||
create: {
|
||||
userId: userId || (await prisma.user.findFirst({ where: { role: 'SUPER_ADMIN' } }))?.id || '',
|
||||
status: body.status || 'OPEN',
|
||||
description: 'Bug reported initially.',
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
return bug
|
||||
})
|
||||
|
||||
// ─── Example API ───────────────────────────────────
|
||||
.get('/api/hello', () => ({
|
||||
message: 'Hello, world!',
|
||||
|
||||
Reference in New Issue
Block a user