Published the tickets POST route
This commit is contained in:
@@ -20,13 +20,25 @@ const db = getFirestore(app);
|
||||
export default withIronSessionApiRoute(handler, sessionOptions);
|
||||
|
||||
async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
// due to integration with the homepage the POST request should be public
|
||||
if (req.method === "POST") {
|
||||
await post(req, res);
|
||||
return;
|
||||
}
|
||||
|
||||
// specific logic for the preflight request
|
||||
if (req.method === "OPTIONS") {
|
||||
res.status(200).end();
|
||||
return;
|
||||
}
|
||||
if (!req.session.user) {
|
||||
res.status(401).json({ ok: false });
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.method === "GET") await get(req, res);
|
||||
if (req.method === "POST") await post(req, res);
|
||||
if (req.method === "GET") {
|
||||
await get(req, res);
|
||||
}
|
||||
}
|
||||
|
||||
async function get(req: NextApiRequest, res: NextApiResponse) {
|
||||
@@ -36,7 +48,7 @@ async function get(req: NextApiRequest, res: NextApiResponse) {
|
||||
snapshot.docs.map((doc) => ({
|
||||
id: doc.id,
|
||||
...doc.data(),
|
||||
})),
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -61,7 +73,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
description: body.description,
|
||||
},
|
||||
[body.reporter.email],
|
||||
`Ticket ${id}: ${body.subject}`,
|
||||
`Ticket ${id}: ${body.subject}`
|
||||
);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
|
||||
Reference in New Issue
Block a user