New design, added category & bug fixes

This commit is contained in:
pheralb
2022-01-21 22:30:32 +00:00
parent 2706236410
commit 57f2339589
43 changed files with 1916 additions and 191 deletions
+6
View File
@@ -0,0 +1,6 @@
import db from "data/icons";
// 📦 Show all content ->
export default function handler(req, res) {
res.status(200).json(db);
}
+13
View File
@@ -0,0 +1,13 @@
import db from "data/icons";
// 📦 Show categories ->
export default function handler(req, res) {
try {
const categories = db
.map((item) => item.category)
.filter((category, index, self) => self.indexOf(category) === index);
return res.status(200).json(categories);
} catch (err) {
res.status(400).json({ message: err });
}
}
+10 -1
View File
@@ -1,7 +1,7 @@
import db from "data/icons";
export default function handler(req, res) {
const { id, q } = req.query;
const { id, q, c } = req.query;
// 🔎 Search by id (ex: ?id=1) ->
if (id) {
@@ -18,6 +18,15 @@ export default function handler(req, res) {
return res.status(200).json(results);
}
// 🔎 Search by category (ex: ?c=library) ->
if (c) {
const results = db.filter((product) => {
const { category } = product;
return category.toLowerCase().includes(c.toLowerCase());
});
return res.status(200).json(results);
}
// ✖ Error ->
res.status(400).json({ info: 'Error: api query not found.' });
}