Commit 071f816
Add nonprofit sorting functionality (#72)
Closes #62
### Overview
This PR implements sorting and filtering capabilities for the nonprofits
GraphQL endpoint. The goal was to enable users to sort nonprofits
alphabetically (A-Z and Z-A), by most recent project start date, and by
status (ACTIVE/INACTIVE), as well as filter nonprofits by chapter IDs
and status.
**Key Changes:**
- Added `NonprofitSortOption` enum with four sorting options: `A_TO_Z`,
`Z_TO_A`, `MOST_RECENT`, and `STATUS`
- Implemented derived status computation logic that determines if a
nonprofit is ACTIVE or INACTIVE based on its associated projects
- Added `status` field to the `Nonprofit` GraphQL type
- Enhanced the `nonprofits` query to accept optional `chapterIds`,
`statuses`, and `sort` parameters
- Implemented multi-level sorting that allows combining multiple sort
options in order of precedence
- Added comprehensive filtering by chapter IDs and status types
**Implementation Details:**
- Status is derived dynamically from `nonprofit_chapter_project`
relationships (ACTIVE if there's an ongoing project, INACTIVE otherwise)
- Sorting is performed in-memory after fetching nonprofits to support
complex multi-level sorting
- All query parameters are optional for backward compatibility
- Chapter filtering uses Prisma relation filters for efficiency
### Testing
**Unit Tests:**
- Added comprehensive unit tests in
`tests/unit/services/nonprofits.service.test.ts` covering:
- Status derivation logic (ACTIVE vs INACTIVE based on project dates and
status)
- A-Z and Z-A alphabetical sorting
- Most recent sorting (by latest project start date)
- Status sorting (ACTIVE before INACTIVE)
- Combined multi-level sorting (e.g., STATUS + MOST_RECENT + A_TO_Z)
- Chapter filtering
- Status filtering
- Edge cases (nonprofits without projects, multiple projects, etc.)
**Integration Tests:**
- Added new integration test file
`tests/integration/graphql/nonprofits-sorting.test.ts` with end-to-end
GraphQL tests:
- A to Z sorting
- Z to A sorting
- Most recent sorting
- Status sorting
- Status filtering (ACTIVE only)
- Chapter filtering
- Combined sorting (STATUS + MOST_RECENT)
All tests pass successfully. The implementation maintains backward
compatibility - existing queries without the new parameters continue to
work as before.
### Screenshots / Screencasts
N/A - This is a backend API change with no frontend components affected.
### Checklist
- [x] Code is neat, readable, and works
- [x] Code is commented where appropriate and well-documented
- [x] Commit messages follow our
[guidelines](https://www.conventionalcommits.com)
- [x] Issue number is linked
- [x] Branch is linked
- [x] Reviewers are assigned (one of your tech leads)
### Notes
- The status field is computed dynamically on each query rather than
being persisted in the database, which ensures accuracy but may have
performance implications for very large datasets
- Nonprofits without any projects are considered INACTIVE
- When sorting by MOST_RECENT, nonprofits without projects appear last
- The implementation follows the existing codebase patterns and
maintains consistency with other similar features (e.g., project
sorting)
- All linting errors have been resolved and the code passes ESLint
checks
---------
Co-authored-by: Sophia Chang <[email protected]>1 parent 4c35188 commit 071f816
File tree
13 files changed
+1336
-73
lines changed- src
- api/graphql
- resolvers
- schemas
- config
- core
- services
- tests
- integration/graphql
- unit/services
13 files changed
+1336
-73
lines changedBinary file not shown.
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
5 | 4 | | |
6 | | - | |
| 5 | + | |
7 | 6 | | |
8 | | - | |
9 | 7 | | |
10 | | - | |
11 | | - | |
12 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
12 | 16 | | |
13 | 17 | | |
14 | 18 | | |
15 | 19 | | |
16 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
17 | 27 | | |
18 | 28 | | |
19 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
20 | 35 | | |
21 | 36 | | |
22 | 37 | | |
| |||
43 | 58 | | |
44 | 59 | | |
45 | 60 | | |
46 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
47 | 65 | | |
48 | 66 | | |
49 | | - | |
| 67 | + | |
50 | 68 | | |
51 | 69 | | |
52 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
2 | 9 | | |
3 | 10 | | |
4 | 11 | | |
| |||
8 | 15 | | |
9 | 16 | | |
10 | 17 | | |
| 18 | + | |
11 | 19 | | |
12 | 20 | | |
13 | 21 | | |
14 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
15 | 27 | | |
16 | 28 | | |
17 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
5 | 16 | | |
6 | | - | |
7 | | - | |
8 | | - | |
| 17 | + | |
9 | 18 | | |
10 | 19 | | |
11 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
12 | 20 | | |
13 | 21 | | |
14 | 22 | | |
| |||
0 commit comments