Created
October 31, 2022 22:21
-
-
Save Josh4324/453857dadde47f84c05f8c140108a394 to your computer and use it in GitHub Desktop.
files.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction | |
export default function handler(req, res) { | |
if (req.method === "GET") { | |
// retrieving the search query | |
const search = req.query.search; | |
//filter checks for search query | |
const options = { | |
method: "POST", | |
headers: { | |
Authorization: process.env.XATA, | |
"Content-Type": "application/json", | |
}, | |
body: `{"filter":{"userid":"${search}"},"page":{"size":15}}`, | |
}; | |
(async () => { | |
try { | |
// queries the files table for the userId,and return all files attached to the userid if it exists | |
const response = await fetch( | |
`${process.env.database}:main/tables/files/query`, | |
options | |
); | |
const data = await response.json(); | |
return res.status(200).json(data.records); | |
} catch (err) { | |
return res.status(500).json({ message: "An error occured" }); | |
} | |
})(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment