Skip to content

Commit

Permalink
split keyword query
Browse files Browse the repository at this point in the history
  • Loading branch information
guyutongxue committed Jan 22, 2025
1 parent d132942 commit ac4a631
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion api/v2/data/[id].js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-check

import { keywords } from "@gi-tcg/static-data";
import { all } from "../data.js";

/**
Expand All @@ -15,7 +16,17 @@ import { all } from "../data.js";
*/
export default function handler(req, res) {
const { id } = req.query;
const found = all.find((obj) => obj.id === Number(id));
if (Array.isArray(id)) {
res.status(400)
.send("Bad request (multiple id)");
return;
}
let found;
if (id.startsWith("K")) {
found = keywords.find((obj) => obj.id === Number(id.slice(1)));
} else {
found = all.find((obj) => obj.id === Number(id));
}
if (found) {
res.status(200).json(found);
return;
Expand Down

0 comments on commit ac4a631

Please sign in to comment.