Completing Listing REST endpoints for GET all and POST#7
Conversation
arnavjk007
left a comment
There was a problem hiding this comment.
We will also have it where only certain roles can create listings or ping these APIs. So just keep note or maybe comment as a reminder to implement user auth and permissions once that is implemented. For example, only lab admins can create or delete listings so we need to check permissions before we do the process.
…tion for GET requests
arnavjk007
left a comment
There was a problem hiding this comment.
Some minor changes + sorting changes
…now, created indexing for filters in schema file
arnavjk007
left a comment
There was a problem hiding this comment.
Restructuring change for consistency across all services
…w requested changes
There was a problem hiding this comment.
This looks good, I think the final thing we need is a little bit of unit testing to make sure that the apis work properly. I set up jest on the main branch so make sure to do git merge main in your feat branch to get the updates. Unit testing goes into each folder and creates a new tests file with .test.ts.
arnavjk007
left a comment
There was a problem hiding this comment.
Okay I think there is a little confusion abt file structure for tests. In every folder you have a file that needs testing, just create its own tests folder there, here you are creating unit test files in the lib/tests folder which is only meant to test mongoose.
- So for your listings.id.route.test.ts, you would create a tests folder in app/api/listings folder and put all route relate testing there.
- For services, same thing you would go into services/listings and make a tests with all unit tests testing in your listings.ts file in services.
- We don't commit coverage files as that is just for you to look at when you run tests so I would add everything relate to coverage into your .gitignore.
- We also need testing on each function I only saw it for the get filtered and a post
…e coverage from git tracking
|
|
||
| // Coverage settings | ||
| collectCoverageFrom: [ | ||
| "app/*/.ts", |
There was a problem hiding this comment.
We don't have to change this file since I already added it in the main branch so just copy the contents of it from the main branch here.
…et and updated POST handler to allow multipart/form-data
arnavjk007
left a comment
There was a problem hiding this comment.
Tests failing, looks good besides that.
arnavjk007
left a comment
There was a problem hiding this comment.
Looks good to merge.
arnavjk007
left a comment
There was a problem hiding this comment.
Conditionally approved, waiting for RBAC svc
arnavjk007
left a comment
There was a problem hiding this comment.
minor reorganizations
| const { searchParams } = new URL(request.url); | ||
| const labId = searchParams.get("labId") || undefined; | ||
| const itemId = searchParams.get("itemId") || undefined; | ||
| const page = parseInt(searchParams.get("page") || "1"); |
There was a problem hiding this comment.
add validation for page & limit inputs
| * @returns JSON response with success message and req body echoed | ||
| */ | ||
| async function POST(request: Request) { | ||
| let { allowed, reason } = await getSession("inventory:create"); |
There was a problem hiding this comment.
we only need listing:create here
| result.imageUrls = imageUrls; | ||
| } | ||
|
|
||
| const parsedBody = listingValidationSchema.safeParse(result); |
There was a problem hiding this comment.
this validation happens after uploading image, lets validate first then upload
| updateData.imageUrls = imageUrls; | ||
| } | ||
|
|
||
| const parsedRequest = listingValidationSchema.safeParse(updateData); |
There was a problem hiding this comment.
upload happens before validation, lets validate first
Describe your changes
Issue ticket number and link
[ Insert Link & Ticket #]
Checklist before requesting a review