Skip to content

Implement UserLab schemas and apis#11

Open
AlexMeng0831 wants to merge 5 commits intomainfrom
UserLab-schema-api
Open

Implement UserLab schemas and apis#11
AlexMeng0831 wants to merge 5 commits intomainfrom
UserLab-schema-api

Conversation

@AlexMeng0831
Copy link
Copy Markdown
Collaborator

Describe your changes

  • Added UserLab schema to represent user-lab memberships
  • Enforced unique constraint on (user, lab) pairs
  • Implemented GET, POST, PUT, DELETE APIs for UserLab
  • Added service layer functions for database operations
  • Added request validation using zod

Issue ticket number and link

[ Insert Link & Ticket #]

Checklist before requesting a review

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • This change requires a documentation update

@AlexMeng0831 AlexMeng0831 requested a review from arnavjk007 as a code owner April 6, 2026 01:46
Copy link
Copy Markdown
Collaborator

@arnavjk007 arnavjk007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error handling, enum correction, add pagination & limit, and remember to add basic unit tests for the functions.

},
role: {
type: String,
enum: ["member", "lead", "admin"],
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be enum: ["PI", "LAB_MANAGER", "RESEARCHER", "VIEWER"],



// GET: all or by id
export async function GET(request: Request) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 });
    }
    }


return NextResponse.json(entry, { status: 200 });
} else {
const entries = await getUserLabs();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@AlexMeng0831
Copy link
Copy Markdown
Collaborator Author

I addressed the requested changes on UserLab-schema-api:

  • updated the UserLab enum values to PI, LAB_MANAGER, RESEARCHER, and VIEWER
  • added try/catch error handling to all UserLab route handlers
  • added pagination with a max limit of 10 to the GET list endpoint
  • added basic unit tests for the UserLab route

Please take another look when you have a chance. Thanks!

@AlexMeng0831 AlexMeng0831 requested a review from arnavjk007 April 7, 2026 17:35
Copy link
Copy Markdown
Collaborator

@arnavjk007 arnavjk007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@AlexMeng0831
Copy link
Copy Markdown
Collaborator Author

I added unit tests for services/UserLab.ts and ran the UserLab tests.

Passing tests:

  • app/api/UserLab/__tests__/route.test.ts
  • services/__tests__/UserLab.test.ts

I also attached a screenshot of the passing run. The db down line in the output is from an intentional mocked error case to verify the route handles database failures correctly.
UserLab-tests-passing

@AlexMeng0831 AlexMeng0831 requested a review from arnavjk007 April 8, 2026 06:35
Copy link
Copy Markdown
Collaborator

@arnavjk007 arnavjk007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to merge! I will look if there's overlap with others and merge accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants