PioneerSquareLabs / otto-playground

A playground where Otto can run free while hopefully not accidentally reformatting your hard drive
https://otto-playground.vercel.app
13 stars 0 forks source link

Otto PR for Issue Create API endpoint => src/pages/api/projects/[projectId]/data.ts #694

Closed kleneway closed 1 year ago

kleneway commented 1 year ago

Summary:

  1. Create a new file data.ts inside the src/pages/api/projects/[projectId] folder.
  2. Import the required modules and types at the beginning of the file.
  3. Define a new async function handler that takes two arguments: req of type NextApiRequest and res of type NextApiResponse.
  4. Inside the handler function, first, call the getServerAuthSession function to get the user's session. If there is no session, return a 401 Unauthorized status and an error message.
  5. Check if the request method is GET. If not, return a 405 Method Not Allowed status and an error message.
  6. Extract the projectId parameter from the request query. Make sure to cast it to a string.
  7. Use the Prisma client to fetch the data schema items for the specified project. Make sure to include a where clause to filter the data schema items by the projectId.
  8. Validate the fetched data schema items using the Zod schema dataSchemaItemSchema.
  9. Return the validated data schema items with a 200 OK status.
  10. Export the handler function as the default export of the module.
kleneway commented 1 year ago

Hello human! 👋

This PR was created by Otto to address the issue Otto PR for Issue Create API endpoint => src/pages/api/projects/[projectId]/data.ts

Next Steps

  1. Please review the PR carefully. Auto-generated code can and will contain subtle bugs and mistakes.

  2. If you identify code that needs to be changed, please reject the PR with a specific reason. Be as detailed as possible in your comments. Otto will take these comments, make changes to the code and push up changes. Please note that this process will take a few minutes.

  3. Once the code looks good, approve the PR and merge the code.