User DAO Mongoose Migration - #100
Draft
AustinSMueller wants to merge 2 commits into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR migrates user data access in the backend from direct/native collection usage (and prior Prisma patterns) to a Mongoose-backed UserDAO, updating service code paths and tests accordingly.
Changes:
- Reworked
UserDAOto extend a newMongooseGenericDAOusing a new MongooseUsermodel. - Updated
UserService(and some other services) to query viauserDAOmethods (findById,findFirst,findMany,update,updateMany,aggregate) and addedfindByID/findByIDshelpers. - Updated a broad set of unit tests to mock
userDAOinstead ofuserCollection/ aggregation pipelines.
Reviewed changes
Copilot reviewed 40 out of 40 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| apps/backend/services/user.js | Switches user operations to UserDAO + adds helper methods; updates several query/update paths. |
| apps/backend/dao/user.js | Converts UserDAO from Prisma/collection usage to Mongoose via MongooseGenericDAO. |
| apps/backend/mongoose/models/user.js | Adds Mongoose User schema/model aligned to existing document shape (incl. updateAt). |
| apps/backend/services/organization-service.js | Drops native userCollection dependency; uses UserDAO for user org updates. |
| apps/backend/services/application.js | Replaces direct user collection queries with userService.findByID/findByIDs and updates user lookups. |
| apps/backend/services/approved-studies.js | Removes native userCollection dependency; uses UserDAO for submitter lookup. |
| apps/backend/services/submission.js | Updates user queries to use _id-based filters with userDAO. |
| apps/backend/routers/graphql-router.js | Updates service constructors to match new signatures (no user collection injection). |
| apps/backend/app.js | Updates service wiring for organization/approved-studies/user services (no user collection injection). |
| apps/backend/test/dao/dao.user.test.js | Replaces Prisma-based DAO tests with Mongoose model mock coverage for UserDAO. |
| apps/backend/test/graphql-queries/batch-job.test.js | Adjusts UserService construction to new constructor signature. |
| apps/backend/test/services/user.updateUserInstitution.test.js | Updates tests to mock userDAO.updateMany and new error-handling behavior. |
| apps/backend/test/services/user.updateUserInfo.approvedStudyStatus.test.js | Updates tests to assert userDAO.update usage; adds rejection test for UPDATE_FAILED. |
| apps/backend/test/services/user.updateMyUser.test.js | Updates test scaffolding to use userDAO.findById/update semantics. |
| apps/backend/test/services/user.requestAccess.test.js | Uses userDAO.getUsersByNotifications mocking instead of user collection. |
| apps/backend/test/services/user.reopenOwner.test.js | Updates UserService constructor call signature. |
| apps/backend/test/services/user.listUsers.test.js | Replaces aggregation expectations with userDAO.findMany expectations. |
| apps/backend/test/services/user.listActiveDCPs.test.js | Updates constructor + DAO mocking to findMany. |
| apps/backend/test/services/user.listActiveCurators.test.js | Updates constructor + DAO mocking to findMany. |
| apps/backend/test/services/user.isUserPrimaryContact.test.js | Updates constructor + DAO mocking to findMany. |
| apps/backend/test/services/user.grantToken.test.js | Updates tests to assert userDAO.update usage and UPDATE_FAILED behavior. |
| apps/backend/test/services/user.getUsersByIDs.test.js | Updates construction comments/signature for UserService. |
| apps/backend/test/services/user.getUser.test.js | Switches from mocked implementation to real getUser bound to instance; updates mocks to userDAO.findFirst. |
| apps/backend/test/services/user.getFedLeads.test.js | Replaces aggregation with userDAO.findMany expectations. |
| apps/backend/test/services/user.getDCPs.test.js | Replaces aggregation with userDAO.findMany expectations. |
| apps/backend/test/services/user.getCollaboratorsByStudyID.test.js | Replaces aggregation pipeline usage with userDAO.findMany expectations. |
| apps/backend/test/services/user.getAdminPBACUsers.test.js | Replaces aggregation with userDAO.findMany expectations. |
| apps/backend/test/services/user.getAdmin.test.js | Replaces aggregation with userDAO.findMany expectations. |
| apps/backend/test/services/user.disableInactiveUsers.test.js | Updates to userDAO.updateMany returning {count} and userDAO.findMany for post-update fetch. |
| apps/backend/test/services/user.checkForInactiveUsers.test.js | Updates aggregation execution to userDAO.aggregate instead of native collection. |
| apps/backend/test/services/submission.editSubmissionCollaborators.test.js | Updates user lookup filter from {id: ...} to {_id: ...}. |
| apps/backend/test/services/data-submission.test.js | Updates user lookup filter from {id: ...} to {_id: ...}. |
| apps/backend/test/services/organization.service.test.js | Updates Organization constructor signature and asserts userDAO.updateUserOrg integration. |
| apps/backend/test/services/approved-studies.test.js | Updates ApprovedStudiesService constructor signature (no user collection). |
| apps/backend/test/services/approved-studies-notification-error-handling.test.js | Updates ApprovedStudiesService constructor signature (no user collection). |
| apps/backend/test/services/application.test.js | Refactors mocked userService interface away from userCollection to findByID/findByIDs. |
| apps/backend/test/services/application.remindApplicationSubmission.test.js | Refactors mocked userService interface away from userCollection to findByID/findByIDs. |
| apps/backend/test/services/application.deleteInactiveApplications.test.js | Refactors mocked userService interface away from userCollection.aggregate to findByIDs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.