mirror of https://github.com/buster-so/buster.git
Update report to start supporting a version number
This commit is contained in:
parent
eaaeca332c
commit
fce52b5b2b
|
@ -1,13 +1,20 @@
|
|||
import { checkPermission } from '@buster/access-controls';
|
||||
import { getReport, getReportMetadata } from '@buster/database/queries';
|
||||
import type { GetReportResponse } from '@buster/server-shared/reports';
|
||||
import {
|
||||
GetReportParamsSchema,
|
||||
GetReportQuerySchema,
|
||||
type GetReportResponse,
|
||||
} from '@buster/server-shared/reports';
|
||||
import { zValidator } from '@hono/zod-validator';
|
||||
import { Hono } from 'hono';
|
||||
import { HTTPException } from 'hono/http-exception';
|
||||
import { standardErrorHandler } from '../../../../utils/response';
|
||||
|
||||
export async function getReportHandler(
|
||||
reportId: string,
|
||||
user: { id: string }
|
||||
user: { id: string },
|
||||
_password?: string,
|
||||
_version_number?: number
|
||||
): Promise<GetReportResponse> {
|
||||
// Get report metadata for access control
|
||||
let reportData: Awaited<ReturnType<typeof getReportMetadata>>;
|
||||
|
@ -49,17 +56,29 @@ export async function getReportHandler(
|
|||
}
|
||||
|
||||
const app = new Hono()
|
||||
.get('/', async (c) => {
|
||||
const reportId = c.req.param('id');
|
||||
const user = c.get('busterUser');
|
||||
.get(
|
||||
'/',
|
||||
zValidator('param', GetReportParamsSchema),
|
||||
zValidator('query', GetReportQuerySchema),
|
||||
async (c) => {
|
||||
const { id: reportId } = c.req.valid('param');
|
||||
const query = c.req.valid('query');
|
||||
const { password, version_number } = query;
|
||||
const user = c.get('busterUser');
|
||||
|
||||
if (!reportId) {
|
||||
throw new HTTPException(404, { message: 'Report ID is required' });
|
||||
if (!reportId) {
|
||||
throw new HTTPException(404, { message: 'Report ID is required' });
|
||||
}
|
||||
|
||||
const response: GetReportResponse = await getReportHandler(
|
||||
reportId,
|
||||
user,
|
||||
password,
|
||||
version_number
|
||||
);
|
||||
return c.json(response);
|
||||
}
|
||||
|
||||
const response: GetReportResponse = await getReportHandler(reportId, user);
|
||||
return c.json(response);
|
||||
})
|
||||
)
|
||||
.onError(standardErrorHandler);
|
||||
|
||||
export default app;
|
||||
|
|
Loading…
Reference in New Issue