mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-12 08:30:59 +01:00
33 lines
858 B
TypeScript
33 lines
858 B
TypeScript
|
import { WebsiteActive, NextApiRequestQueryBody } from 'lib/types';
|
||
|
import { canViewWebsite } from 'lib/auth';
|
||
|
import { useAuth, useCors } from 'lib/middleware';
|
||
|
import { NextApiResponse } from 'next';
|
||
|
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||
|
import { getWebsiteDateRange } from 'queries';
|
||
|
|
||
|
export interface WebsiteDateRangeRequestQuery {
|
||
|
id: string;
|
||
|
}
|
||
|
|
||
|
export default async (
|
||
|
req: NextApiRequestQueryBody<WebsiteDateRangeRequestQuery>,
|
||
|
res: NextApiResponse<WebsiteActive>,
|
||
|
) => {
|
||
|
await useCors(req, res);
|
||
|
await useAuth(req, res);
|
||
|
|
||
|
const { id: websiteId } = req.query;
|
||
|
|
||
|
if (req.method === 'GET') {
|
||
|
if (!(await canViewWebsite(req.auth, websiteId))) {
|
||
|
return unauthorized(res);
|
||
|
}
|
||
|
|
||
|
const result = await getWebsiteDateRange(websiteId);
|
||
|
|
||
|
return ok(res, result);
|
||
|
}
|
||
|
|
||
|
return methodNotAllowed(res);
|
||
|
};
|