⚒️ Preparate boilerplate v2 - Typescript + React 18.

This commit is contained in:
pheralb
2022-06-03 11:53:50 +01:00
parent 48e648a04b
commit b21f464108
46 changed files with 1374 additions and 12586 deletions
-6
View File
@@ -1,6 +0,0 @@
import db from "data/svgs";
// 📦 Show all content ->
export default function handler(req, res) {
res.status(200).json(db);
}
-13
View File
@@ -1,13 +0,0 @@
import db from "data/svgs";
// 📦 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 });
}
}
+13
View File
@@ -0,0 +1,13 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from 'next'
type Data = {
name: string
}
export default function handler(
req: NextApiRequest,
res: NextApiResponse<Data>
) {
res.status(200).json({ name: 'John Doe' })
}
-32
View File
@@ -1,32 +0,0 @@
import db from "data/svgs";
export default function handler(req, res) {
const { id, q, c } = req.query;
// 🔎 Search by id (ex: ?id=1) ->
if (id) {
const item = db.find((item) => item.id === +id);
return res.status(200).json(item);
}
// 🔎 Search by query (ex: ?q=d) ->
if (q) {
const results = db.filter((product) => {
const { title } = product;
return title.toLowerCase().includes(q.toLowerCase());
});
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.' });
}