Conversation
| return NextResponse.json({ message: "Invalid ID" }, | ||
| { status: 400 }); | ||
| } | ||
| const item = await getLab(parsedParams.data.id); |
There was a problem hiding this comment.
This is good but let's update this to return a list of labs when we pass in user id. Because what if a user is a part of multiple labs?
arnavjk007
left a comment
There was a problem hiding this comment.
Let's also have a function that returns all labs but paginated so we only fetch for example 10 labs per query until end. Also, remember to add unit testing.
arnavjk007
left a comment
There was a problem hiding this comment.
Missing some CRUD functions also for unit tests please send a ss of all tests passing.
| await connectToDatabase(); | ||
| const lab = await LabModel.findById(id).exec(); | ||
| if (!lab) { | ||
| throw new Error(`Lab with ID ${id} not found`); |
There was a problem hiding this comment.
We want to return false here instead of throwing.
| { status: 500 }); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
There should be a POST function
| console.error(err); | ||
| return NextResponse.json({ message: "Internal server error" }, { status: 500 }); | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
Missing PUT and DELETE
| if (!parsed.success) { | ||
| return NextResponse.json({ message: "Invalid data" }, { status: 400 }); | ||
| } | ||
| const newLab = await addLab(parsed.data as unknown as Lab); |
There was a problem hiding this comment.
This type casting may not work for all cases and is a bit unsafe we can just change header of addLab to this.. export async function addLab(newLab: LabInput | Omit<Lab, 'id'>): Promise {
await connectToDatabase();
const createdLab = await LabModel.create(newLab);
return toLab(createdLab);
}
Describe your changes
[ Couple of bullet points ]
Issue ticket number and link
[ Insert Link & Ticket #]
Checklist before requesting a review