Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9adbc9a
added database
mehanana Nov 3, 2025
3cc2dba
joined tables to get donors
mehanana Nov 4, 2025
a67631d
added tests
mehanana Nov 6, 2025
05a66dd
Merge branch 'main' into #65-add-get-project-donors-route
mehanana Nov 18, 2025
6c4fe3c
Merge branch 'main' into #65-add-get-project-donors-route
mehanana Nov 20, 2025
faed311
Merge branch 'main' into #65-add-get-project-donors-route
mehanana Nov 28, 2025
e12d645
Update apps/backend/lambdas/projects/handler.ts
mehanana Dec 4, 2025
431c2bb
Merge branch 'main' into #65-add-get-project-donors-route
mehanana Jan 23, 2026
c5eeb1e
Merge branch 'main' into #65-add-get-project-donors-route
mehanana Feb 4, 2026
48d797b
Merge branch 'main' into #65-add-get-project-donors-route
nourshoreibah Feb 12, 2026
356fc26
handler code was missing, so added it back in
mehanana Feb 22, 2026
e38c5f0
update package lock for ci failing
mehanana Feb 24, 2026
7b3bde8
Merge branch 'main' into #65-add-get-project-donors-route
mehanana Apr 12, 2026
802f6cb
chore: regenerate lambda READMEs
github-actions[bot] Apr 12, 2026
11696aa
Merge branch 'main' into #65-add-get-project-donors-route
Rayna-Yu Apr 12, 2026
0519b5d
Merge branch 'main' into #65-add-get-project-donors-route
mehanana Apr 12, 2026
fb32e59
Merge branch 'main' into #65-add-get-project-donors-route
mehanana Apr 12, 2026
874051b
added a new project with no donors
mehanana Apr 12, 2026
4595a76
Merge branch '#65-add-get-project-donors-route' of https://github.com…
mehanana Apr 12, 2026
a5ed7c5
Merge branch 'main' into #65-add-get-project-donors-route
Vaibhav978 Apr 12, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/backend/db/.env.dev
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DATABASE_URL=postgresql://branch_dev:password@localhost:5433/branch_db
DATABASE_URL=postgresql://branch_dev:password@localhost:5432/branch_db
3 changes: 2 additions & 1 deletion apps/backend/db/db_setup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ INSERT INTO users (name, email, is_admin) VALUES
INSERT INTO projects (name, description, total_budget, start_date, end_date, currency) VALUES
('Clinician Communication Study', 'Study of clinician-patient communication patterns', 500000, '2025-01-01', '2026-01-01', 'USD'),
('Health Education Initiative', 'Community health education and outreach', 300000, '2025-03-01', '2026-03-01', 'USD'),
('Policy Advocacy Program', 'Advocacy and policy change efforts', 200000, '2025-06-01', '2026-06-01', 'USD');
('Policy Advocacy Program', 'Advocacy and policy change efforts', 200000, '2025-06-01', '2026-06-01', 'USD'),
('Proj B', '', 2500.50, NULL, NULL, 'USD');

INSERT INTO donors (organization, contact_name, contact_email) VALUES
('NIH', 'Dr. Sarah Lee', 'sarah@nih.gov'),
Expand Down
1 change: 1 addition & 0 deletions apps/backend/lambdas/projects/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Lambda for managing projects.
| GET | /health | Health check |
| GET | /projects/{id}/members | |
| GET | /projects | |
| GET | /projects/{id}/donors | |
| GET | /projects/{id} | |
| PUT | /projects/{id} | |

Expand Down
38 changes: 38 additions & 0 deletions apps/backend/lambdas/projects/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,44 @@ export const handler = async (event: any): Promise<APIGatewayProxyResult> => {
const projects = await db.selectFrom("branch.projects").selectAll().execute();
return json(200, projects);
}

// GET /projects/{id}/donors
const parts = normalizedPath.split('/');
if (parts.length === 3 && parts[2] === 'donors' && method === 'GET') {
const id = parts[1];


if (!id) return json(400, { message: 'id is required' });
if (isNaN(Number(id))) {
return json(400, { message: 'Project id must be a valid number' });
}
const queryString = event.rawQueryString || event.queryStringParameters;

if (queryString && (typeof queryString === 'string' ? queryString.length > 0 : Object.keys(queryString).length > 0)) {
return json(400, { message: 'Bad Request: Query parameters are not allowed' });
}

const project = await db
.selectFrom("branch.projects as p")
.where("p.project_id", "=", Number(id))
.selectAll()
.executeTakeFirst();

if (!project) {
return json(404, { message: 'Project not found' });
}

const donors = await db.selectFrom("branch.projects as p").where("p.project_id", "=", Number(id)).innerJoin(
"branch.project_donations as bpd",
"bpd.project_id",
"p.project_id"
).innerJoin(
"branch.donors as bd",
"bd.donor_id",
"bpd.donor_id"
).selectAll().execute();
return json(200, { donors });
}

// GET /projects/{id}
if (rawPath.startsWith('/') && rawPath.split('/').length === 2 && method === 'GET') {
Expand Down
44 changes: 43 additions & 1 deletion apps/backend/lambdas/projects/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ paths:
schema:
type: string
/projects:
get:
summary: GET /projects
responses:
'200':
description: OK
post:
summary: POST /projects
requestBody:
Expand All @@ -37,7 +42,7 @@ paths:
application/json:
schema:
type: object
required:
required:
- name
properties:
name:
Expand All @@ -50,6 +55,29 @@ paths:
'200':
description: OK

/projects/{id}:
get:
summary: GET /projects/{id}
parameters:
- in: path
name: id
required: true
schema:
type: string
responses:
'200':
description: OK
put:
summary: PUT /projects/{id}
parameters:
- in: path
name: id
required: true
schema:
type: string
responses:
'200':
description: OK
/projects/{id}/expenditures:
get:
summary: GET /projects/{id}/expenditures
Expand All @@ -68,3 +96,17 @@ paths:
type: array
items:
type: object

/projects/{id}/donors:
get:
summary: GET /projects/{id}/donors
parameters:
- in: path
name: id
required: true
schema:
type: string
responses:
'200':
description: OK

20 changes: 10 additions & 10 deletions apps/backend/lambdas/projects/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions apps/backend/lambdas/projects/test/example.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

test("health test 🌞", async () => {
let res = await fetch("http://localhost:3000/projects/health")
expect(res.status).toBe(200);
});


test("get projects no donors test 🌞", async () => {
const res = await fetch("http://localhost:3000/projects/4/donors");
expect(res.status).toBe(200);
let body = await res.json();
console.log(body);
expect(body.donors).toBeDefined();
expect(Array.isArray(body.donors)).toBe(true);
});

test("get projects yes donors test 🌞", async () => {
const res = await fetch("http://localhost:3000/projects/1/donors");
expect(res.status).toBe(200);
let body = await res.json();
console.log(body);
expect(body.donors).toBeDefined();
expect(Array.isArray(body.donors)).toBe(true);
if (body.donors.length > 0) {
const donor = body.donors[0];
expect(donor.project_id).toBeDefined();
expect(donor.name).toBeDefined();
expect(donor.total_budget).toBeDefined();
expect(donor.start_date).toBeDefined();
expect(donor.end_date).toBeDefined();
expect(donor.currency).toBeDefined();
expect(donor.created_at).toBeDefined();
expect(donor.donation_id).toBeDefined();
expect(donor.donor_id).toBeDefined();
expect(donor.amount).toBeDefined();
expect(donor.donated_at).toBeDefined();
expect(donor.organization).toBeDefined();
expect(donor.contact_name).toBeDefined();
expect(donor.contact_email).toBeDefined();
}
});


test("404 when invalid project id 🌞", async () => {
const res = await fetch("http://localhost:3000/projects/1000/donors");
expect(res.status).toBe(404);
});

test("400 when project id is not a number 🌞", async () => {
const res = await fetch("http://localhost:3000/projects/abc/donors");
expect(res.status).toBe(400);
const body = await res.json();
expect(body.message).toContain("must be a valid number");
});

test("400 when request has both body and query params 🌞", async () => {
const res = await fetch("http://localhost:3000/projects/1/donors?sort=desc");
expect(res.status).toBe(400);
const body = await res.json();
expect(body.message).toContain("Bad Request");
});
Loading