umami/pages/api/websites/[id]/reset.ts
2022-11-15 13:21:14 -08:00

34 lines
832 B
TypeScript

import { resetWebsite } from 'queries';
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
import { allowQuery } from 'lib/auth';
import { useAuth, useCors } from 'lib/middleware';
import { TYPE_WEBSITE } from 'lib/constants';
import { NextApiRequestQueryBody } from 'interface/api/nextApi';
import { NextApiResponse } from 'next';
export interface WebsiteResetReqeustQuery {
id: string;
}
export default async (
req: NextApiRequestQueryBody<WebsiteResetReqeustQuery>,
res: NextApiResponse,
) => {
await useCors(req, res);
await useAuth(req, res);
const { id: websiteId } = req.query;
if (req.method === 'POST') {
if (!(await allowQuery(req, TYPE_WEBSITE))) {
return unauthorized(res);
}
await resetWebsite(websiteId);
return ok(res);
}
return methodNotAllowed(res);
};