fix: query user directory safely
This commit is contained in:
@@ -65,5 +65,55 @@ Passed with no whitespace errors.
|
||||
|
||||
## Concerns
|
||||
|
||||
- The service intentionally fetches the user and player directory sets and applies the authorization filter in memory. Task 2's planned foreign-key index work can support a future query-builder optimization without changing this safe response contract.
|
||||
- The repository-wide Jest suite has documented pre-existing placeholder dependency failures in the SDD ledger; this task verified its focused suite, lint, build, and whitespace check.
|
||||
|
||||
## Fix Round 1
|
||||
|
||||
### Files changed
|
||||
|
||||
- `myteamwallet_backend/src/users/users.service.ts` — replaces whole-entity loading with database-side raw projections for visibility, search, distinct count, deterministic ordering, pagination, and assignment filtering.
|
||||
- `myteamwallet_backend/src/users/users.service.spec.ts` — adds the inactive-requester regression and runs the directory contract against query-builder doubles that reject entity hydration and unsafe projected authentication fields.
|
||||
|
||||
### RED evidence
|
||||
|
||||
Test file: `myteamwallet_backend/src/users/users.service.spec.ts`
|
||||
|
||||
Command:
|
||||
|
||||
```powershell
|
||||
npm test -- users/users.service.spec.ts --runInBand
|
||||
```
|
||||
|
||||
Result: failed as expected with 2 failures. `treats an inactive requester assignment as a shared team membership` received `[]` instead of `[1, 2]`; `does not hydrate whole user entities for the directory` rejected with `directory queries must use a safe database projection` because the old code called `usersRepository.find`.
|
||||
|
||||
### GREEN verification
|
||||
|
||||
```powershell
|
||||
npm test -- users/users.service.spec.ts --runInBand
|
||||
```
|
||||
|
||||
Passed: 1 suite, 9 tests.
|
||||
|
||||
```powershell
|
||||
.\node_modules\.bin\eslint.cmd src\users\users.service.ts src\users\users.service.spec.ts --max-warnings=0
|
||||
```
|
||||
|
||||
Passed with no warnings or errors.
|
||||
|
||||
```powershell
|
||||
npm run build
|
||||
```
|
||||
|
||||
Passed: Nest build completed successfully.
|
||||
|
||||
```powershell
|
||||
git diff --check
|
||||
```
|
||||
|
||||
Passed with no whitespace errors.
|
||||
|
||||
### Implementation notes
|
||||
|
||||
- Shared-team membership now uses every requester `Player` row, including inactive ones, exactly as required by the directory plan.
|
||||
- The user query joins only `status` and `role`, projects safe raw columns, applies shared-team visibility/search in SQL, counts `DISTINCT user.id`, orders by `user.id`, and applies offset/limit before mapping.
|
||||
- Assignment rows are fetched only for the selected page of user IDs and are scoped with the same shared-team subquery for non-admins. No directory query selects or hydrates `User` authentication columns.
|
||||
|
||||
Reference in New Issue
Block a user