Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 6 additions & 3 deletions apps/backend/db/db_setup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,12 @@ INSERT INTO project_memberships (project_id, user_id, role, start_date, hours) V
(2, 3, 'Staff', '2025-03-15', 60.00);

INSERT INTO expenditures (project_id, entered_by, amount, category, description, spent_on) VALUES
(1, 1, 5000, 'Travel', 'Conference attendance', '2025-02-10'),
(2, 2, 3000, 'Equipment', 'Purchase of recording devices', '2025-04-05'),
(3, 3, 2500, 'Supplies', 'Educational materials', '2025-07-12');
(1, 1, 5000, 'Travel', 'Domestic conference attendance', '2025-02-10'),
(1, 1, 4200, 'Travel Foreign', 'International collaborator meeting in London', '2025-03-22'),
(2, 2, 3000, 'General', 'Recording device supplies', '2025-04-05'),
(2, 2, 1500, 'Visitor / Honorarium', 'Guest lecturer honorarium', '2025-05-18'),
(3, 3, 2500, 'General', 'Educational materials', '2025-07-12'),
(3, 3, 1800, 'Travel', 'Local outreach travel', '2025-08-03');

INSERT INTO reports (project_id, object_url) VALUES
(1, 'https://s3.amazonaws.com/branch-reports/clinician_communication_study_report.pdf'),
Expand Down
4 changes: 4 additions & 0 deletions apps/backend/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ services:
DB_USER: ${DB_USER:-branch_dev}
DB_PASSWORD: ${DB_PASSWORD:-password}
DB_NAME: ${DB_NAME:-branch_db}
COGNITO_USER_POOL_ID: ${COGNITO_USER_POOL_ID}
COGNITO_APP_CLIENT_ID: ${COGNITO_CLIENT_ID}
ports:
- '3003:3000'
depends_on:
Expand All @@ -93,6 +95,8 @@ services:
DB_USER: ${DB_USER:-branch_dev}
DB_PASSWORD: ${DB_PASSWORD:-password}
DB_NAME: ${DB_NAME:-branch_db}
COGNITO_USER_POOL_ID: ${COGNITO_USER_POOL_ID}
COGNITO_CLIENT_ID: ${COGNITO_CLIENT_ID}
ports:
- '3004:3000'
depends_on:
Expand Down
3 changes: 2 additions & 1 deletion apps/backend/lambdas/donors/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Lambda for managing donors.
|--------|------|-------------|
| GET | /health | Health check |
| GET | /donors | |
| GET | /donations | |
| POST | /donations | |
| POST | /donors | |

## Setup

Expand Down
12 changes: 12 additions & 0 deletions apps/backend/lambdas/donors/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export const handler = async (event: any): Promise<APIGatewayProxyResult> => {
const normalizedPath = rawPath.replace(/\/$/, '');
const method = (event.requestContext?.http?.method || event.httpMethod || 'GET').toUpperCase();

// CORS preflight
if (method === 'OPTIONS') {
return json(200, {});
}

// Health check
if ((normalizedPath.endsWith('/health') || normalizedPath === '/health') && method === 'GET') {
return json(200, { ok: true, timestamp: new Date().toISOString() });
Expand Down Expand Up @@ -126,6 +131,13 @@ export const handler = async (event: any): Promise<APIGatewayProxyResult> => {
.execute();
return json(200, { data: donations });
}

// POST /donors
if (normalizedPath === '/donors' && method === 'POST') {
const body = event.body ? JSON.parse(event.body) as Record<string, unknown> : {};
// TODO: Add your business logic here
return json(201, { ok: true, route: 'POST /donors', body });
}
// <<< ROUTES-END

return json(404, { message: 'Not Found', path: normalizedPath, method });
Expand Down
40 changes: 40 additions & 0 deletions apps/backend/lambdas/donors/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,43 @@ paths:
responses:
'200':
description: OK

/donors:
post:
summary: POST /donors
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
organization:
type: string
contact_name:
type: string
contact_email:
type: string
responses:
'201':
description: Success

/donations:
post:
summary: POST /donations
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
donor_id:
type: integer
project_id:
type: integer
amount:
type: number
responses:
'201':
description: Success
5 changes: 5 additions & 0 deletions apps/backend/lambdas/expenditures/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export const handler = async (event: any): Promise<APIGatewayProxyResult> => {
const normalizedPath = rawPath.replace(/\/$/, '');
const method = (event.requestContext?.http?.method || event.httpMethod || 'GET').toUpperCase();

// CORS preflight
if (method === 'OPTIONS') {
return json(200, {});
}

// Health check
if ((normalizedPath.endsWith('/health') || normalizedPath === '/health') && method === 'GET') {
return json(200, { ok: true, timestamp: new Date().toISOString() });
Expand Down
32 changes: 16 additions & 16 deletions apps/backend/lambdas/expenditures/package-lock.json

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

21 changes: 11 additions & 10 deletions apps/backend/lambdas/expenditures/test/expenditures.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ describe('Expenditures integration tests', () => {
expect(res.statusCode).toBe(200);
const body = JSON.parse(res.body);
expect(Array.isArray(body.data)).toBe(true);
expect(body.data.length).toBe(3);
expect(body.data.length).toBe(6);
expect(body.pagination).toBeUndefined();
});

Expand All @@ -233,8 +233,9 @@ describe('Expenditures integration tests', () => {
const res = await handler(getEvent('/'));
const body = JSON.parse(res.body);
const dates = body.data.map((e: any) => new Date(e.spent_on).getTime());
expect(dates[0]).toBeGreaterThanOrEqual(dates[1]);
expect(dates[1]).toBeGreaterThanOrEqual(dates[2]);
for (let i = 0; i < dates.length - 1; i++) {
expect(dates[i]).toBeGreaterThanOrEqual(dates[i + 1]);
}
});

test('200: paginated response with page and limit', async () => {
Expand All @@ -246,8 +247,8 @@ describe('Expenditures integration tests', () => {
expect(body.pagination).toBeDefined();
expect(body.pagination.page).toBe(1);
expect(body.pagination.limit).toBe(1);
expect(body.pagination.totalItems).toBe(3);
expect(body.pagination.totalPages).toBe(3);
expect(body.pagination.totalItems).toBe(6);
expect(body.pagination.totalPages).toBe(6);
});

test('200: page 2 returns second item', async () => {
Expand All @@ -264,8 +265,8 @@ describe('Expenditures integration tests', () => {
const res = await handler(getEvent('/', { page: '1', limit: '100' }));
const body = JSON.parse(res.body);
expect(res.statusCode).toBe(200);
expect(body.data.length).toBe(3);
expect(body.pagination.totalItems).toBe(3);
expect(body.data.length).toBe(6);
expect(body.pagination.totalItems).toBe(6);
expect(body.pagination.totalPages).toBe(1);
});

Expand All @@ -275,7 +276,7 @@ describe('Expenditures integration tests', () => {
const body = JSON.parse(res.body);
expect(res.statusCode).toBe(200);
expect(body.pagination).toBeUndefined();
expect(body.data.length).toBe(3);
expect(body.data.length).toBe(6);
});

test('200: only limit provided returns all without pagination', async () => {
Expand All @@ -284,7 +285,7 @@ describe('Expenditures integration tests', () => {
const body = JSON.parse(res.body);
expect(res.statusCode).toBe(200);
expect(body.pagination).toBeUndefined();
expect(body.data.length).toBe(3);
expect(body.data.length).toBe(6);
});

test('200: filter by projectId returns only matching expenditures', async () => {
Expand All @@ -300,7 +301,7 @@ describe('Expenditures integration tests', () => {
const res = await handler(getEvent('/', { projectId: '1', page: '1', limit: '10' }));
const body = JSON.parse(res.body);
expect(res.statusCode).toBe(200);
expect(body.pagination.totalItems).toBe(1);
expect(body.pagination.totalItems).toBe(2);
expect(body.data.every((e: any) => e.project_id === 1)).toBe(true);
});

Expand Down
Loading
Loading