Skip to content

Commit

Permalink
feat: add filterId & groupId filtering options for /transfer api (
Browse files Browse the repository at this point in the history
#287)

* feat: add `filterId` & `groupId` filtering options for `/transfer` api

* chore: allow all origins
  • Loading branch information
diogogmatos authored Feb 17, 2025
1 parent ddc17d6 commit 5899a63
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pages/api/transfer/events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getEvents } from "../../../utils";

const API = async (req: NextApiRequest, res: NextApiResponse) => {
res.setHeader("Content-Type", "application/json");
res.setHeader("Access-Control-Allow-Origin", "*");

try {
const { GS_CLIENT_EMAIL, GS_PRIVATE_KEY } = process.env;
Expand All @@ -25,7 +26,21 @@ const API = async (req: NextApiRequest, res: NextApiResponse) => {
const sheets = google.sheets({ version: "v4", auth: jwt });

// Fetch event data
const eventsData: IEventDTO[] = await getEvents(sheets);
let eventsData: IEventDTO[] = await getEvents(sheets);

if (req.query.filterId) {
eventsData = eventsData.filter(
(event) => event.filterId === Number(req.query.filterId as string)
);
}

if (req.query.groupId) {
eventsData = eventsData.filter((event) =>
typeof req.query.groupId === "string"
? event.groupId === Number(req.query.groupId)
: req.query.groupId.includes(event.groupId.toString())
);
}

// Convert data into JSON
const data = JSON.stringify(eventsData);
Expand Down

0 comments on commit 5899a63

Please sign in to comment.