umami/pages/api/me/websites.ts

25 lines
694 B
TypeScript
Raw Normal View History

2023-02-08 00:29:25 +00:00
import { useAuth, useCors } from 'lib/middleware';
2023-08-11 18:37:01 +00:00
import { NextApiRequestQueryBody, SearchFilter, WebsiteSearchFilterType } from 'lib/types';
2023-02-08 00:29:25 +00:00
import { NextApiResponse } from 'next';
import { methodNotAllowed } from 'next-basics';
import userWebsites from 'pages/api/users/[id]/websites';
2023-02-08 00:29:25 +00:00
2023-08-11 05:50:41 +00:00
export interface MyWebsitesRequestQuery extends SearchFilter<WebsiteSearchFilterType> {}
export default async (
req: NextApiRequestQueryBody<MyWebsitesRequestQuery, any>,
res: NextApiResponse,
) => {
2023-02-08 00:29:25 +00:00
await useCors(req, res);
await useAuth(req, res);
if (req.method === 'GET') {
req.query.id = req.auth.user.id;
2023-02-08 00:29:25 +00:00
return userWebsites(req, res);
2023-02-08 00:29:25 +00:00
}
return methodNotAllowed(res);
};