mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-16 02:05:04 +01:00
37 lines
893 B
TypeScript
37 lines
893 B
TypeScript
import { NextApiResponse } from 'next';
|
|
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
|
import { NextApiRequestQueryBody } from 'lib/types';
|
|
import { canViewTeam } from 'lib/auth';
|
|
import { useAuth } from 'lib/middleware';
|
|
import { getTeamWebsites } from 'queries/admin/team';
|
|
|
|
export interface TeamWebsiteRequestQuery {
|
|
id: string;
|
|
}
|
|
|
|
export interface TeamWebsiteRequestBody {
|
|
website_id: string;
|
|
team_website_id?: string;
|
|
}
|
|
|
|
export default async (
|
|
req: NextApiRequestQueryBody<TeamWebsiteRequestQuery, TeamWebsiteRequestBody>,
|
|
res: NextApiResponse,
|
|
) => {
|
|
await useAuth(req, res);
|
|
|
|
const { id: teamId } = req.query;
|
|
|
|
if (req.method === 'GET') {
|
|
if (!(await canViewTeam(req.auth, teamId))) {
|
|
return unauthorized(res);
|
|
}
|
|
|
|
const websites = await getTeamWebsites(teamId);
|
|
|
|
return ok(res, websites);
|
|
}
|
|
|
|
return methodNotAllowed(res);
|
|
};
|