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

Function handler

apps/web/pages/api/plans/index.ts:124–171  ·  view source on GitHub ↗
(
  request: NextApiRequest,
  response: NextApiResponse
)

Source from the content-addressed store, hash-verified

122}
123
124export default async function handler(
125 request: NextApiRequest,
126 response: NextApiResponse
127) {
128 if (request.method === 'OPTIONS') {
129 return preflight(request, response, ['POST', 'GET']);
130 }
131 cors(request, response);
132
133 if (request.method === 'POST') {
134 const { communityId, priceId, successUrl, cancelUrl } = request.body;
135 if (!communityId || !priceId || !successUrl || !cancelUrl) {
136 return response.status(400).json({});
137 }
138 const permissions = await PermissionsService.get({
139 request,
140 response,
141 params: { communityId },
142 });
143 if (!permissions.auth || !permissions.manage) {
144 return response.status(401).end();
145 }
146
147 const email = permissions.auth.email;
148 const url = await create({
149 communityId,
150 email,
151 priceId,
152 successUrl,
153 cancelUrl,
154 });
155 if (url) {
156 try {
157 await sendNotification(`User ${email} is being redirected to stripe.`);
158 } catch (exception) {
159 console.error('Failed to send a notification: ', exception);
160 }
161 return response.status(200).json({ redirectUrl: url });
162 }
163 return response.status(500).json({});
164 }
165 if (request.method === 'GET') {
166 const period = request.query.period as string;
167 const { status, data } = await index({ period });
168 return response.status(status).json(data);
169 }
170 return response.status(405).end();
171}

Callers

nothing calls this directly

Calls 8

preflightFunction · 0.90
corsFunction · 0.90
sendNotificationFunction · 0.90
createFunction · 0.70
indexFunction · 0.70
errorMethod · 0.65
getMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected