Conversation
arnavjk007
left a comment
There was a problem hiding this comment.
Error handling, enum correction, add pagination & limit, and remember to add basic unit tests for the functions.
models/UserLab.ts
Outdated
| }, | ||
| role: { | ||
| type: String, | ||
| enum: ["member", "lead", "admin"], |
There was a problem hiding this comment.
this should be enum: ["PI", "LAB_MANAGER", "RESEARCHER", "VIEWER"],
|
|
||
|
|
||
| // GET: all or by id | ||
| export async function GET(request: Request) { |
There was a problem hiding this comment.
for each function we need to add try catch clauses so if anything breaks it will throw an error and not break the service.. here is an example of what it would look like (would also be nice to add the comments above each one so other reading it can understand what it is doing)
/**
- Get one lab entry by ID
- @param request request object
- @param context context object containing route parameters
- @return response with lab data or error message
*/
export async function GET(request: Request, context : { params: Params }) {
try {
const parsedParams = z.object({ id: z.string().min(1) })
.safeParse(context.params);
if (!parsedParams.success) {
return NextResponse.json({ message: "Invalid ID" },
{ status: 400 });
}
const item = await getLab(parsedParams.data.id);Expand commentComment on line R40
if (!item) {
return NextResponse.json({ message: "Lab not found" },
{ status: 404 });
}
return NextResponse.json(item, { status: 200 });
} catch (err) {
console.error(err);
return NextResponse.json({ message: "Internal server error" },
{ status: 500 });
}
}
app/api/UserLab/route.ts
Outdated
|
|
||
| return NextResponse.json(entry, { status: 200 }); | ||
| } else { | ||
| const entries = await getUserLabs(); |
There was a problem hiding this comment.
Is there a way to have this paginated / limited to around 10 labs per request. If there were around 100 labs we don't want users to scroll through all of them and we don't want to load all at same time. So each time they click next page to view the next 10, we call this again to make it more optimal
|
I addressed the requested changes on
Please take another look when you have a chance. Thanks! |
arnavjk007
left a comment
There was a problem hiding this comment.
We also need unit testing for the services/UserLab.ts functions. Other than that it should be good. Once all unit tests are written, please also send me an ss of it all passing.
arnavjk007
left a comment
There was a problem hiding this comment.
Looks good to merge! I will look if there's overlap with others and merge accordingly.

Describe your changes
Issue ticket number and link
[ Insert Link & Ticket #]
Checklist before requesting a review