MCPcopy Create free account
hub / github.com/Linen-dev/linen.dev / handler

Function handler

apps/web/pages/api/metrics/index.ts:6–38  ·  view source on GitHub ↗
(
  request: NextApiRequest,
  response: NextApiResponse
)

Source from the content-addressed store, hash-verified

4import { cors, preflight } from 'utilities/cors';
5
6export default async function handler(
7 request: NextApiRequest,
8 response: NextApiResponse
9) {
10 if (request.method === 'OPTIONS') {
11 return preflight(request, response, ['GET']);
12 }
13 cors(request, response);
14 if (request.method === 'GET') {
15 const { communityId } = request.query;
16 if (typeof communityId !== 'string') {
17 return response.status(400).end();
18 }
19
20 const permissions = await PermissionsService.get({
21 request,
22 response,
23 params: { communityId },
24 });
25
26 if (!permissions.manage) {
27 return response.status(401).json({});
28 }
29
30 const members = await prisma.users.count({
31 where: { accountsId: communityId },
32 });
33 return response.status(200).json({
34 members,
35 });
36 }
37 return response.status(405).json({});
38}

Callers

nothing calls this directly

Calls 4

preflightFunction · 0.90
corsFunction · 0.90
endMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected