umami/pages/api/teams/[id]/website.ts

38 lines
955 B
TypeScript
Raw Normal View History

2022-11-18 09:27:42 +01:00
import { NextApiRequestQueryBody } from 'interface/api/nextApi';
2022-11-20 09:48:13 +01:00
import { allowQuery } from 'lib/auth';
import { UmamiApi } from 'lib/constants';
2022-11-18 09:27:42 +01:00
import { useAuth } from 'lib/middleware';
import { NextApiResponse } from 'next';
2022-11-20 09:48:13 +01:00
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
import { getWebsitesByTeamId } from 'queries';
2022-11-18 09:27:42 +01:00
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') {
2022-11-20 09:48:13 +01:00
if (!(await allowQuery(req, UmamiApi.AuthType.Team))) {
return unauthorized(res);
}
2022-11-18 09:27:42 +01:00
const website = await getWebsitesByTeamId({ teamId });
return ok(res, website);
}
return methodNotAllowed(res);
};