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
77 changes: 77 additions & 0 deletions apps/backend/lambdas/projects/db-types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* This file was generated by kysely-codegen.
* Please do not edit it manually.
*/

import type { ColumnType } from "kysely";

export type Generated<T> = T extends ColumnType<infer S, infer I, infer U>
? ColumnType<S, I | undefined, U>
: ColumnType<T, T | undefined, T>;

export type Numeric = ColumnType<string, number | string, number | string>;

export type Timestamp = ColumnType<Date, Date | string, Date | string>;

export interface BranchDonors {
contact_email: string | null;
contact_name: string | null;
created_at: Generated<Timestamp | null>;
donor_id: Generated<number>;
organization: string;
}

export interface BranchExpenditures {
amount: Numeric;
category: string | null;
created_at: Generated<Timestamp | null>;
description: string | null;
entered_by: number | null;
expenditure_id: Generated<number>;
project_id: number;
spent_on: Generated<Timestamp>;
}

export interface BranchProjectDonations {
amount: Numeric;
donated_at: Generated<Timestamp | null>;
donation_id: Generated<number>;
donor_id: number;
project_id: number;
}

export interface BranchProjectMemberships {
hours: Numeric | null;
membership_id: Generated<number>;
project_id: number;
role: string;
start_date: Timestamp | null;
user_id: number;
}

export interface BranchProjects {
created_at: Generated<Timestamp | null>;
currency: Generated<string | null>;
end_date: Timestamp | null;
name: string;
project_id: Generated<number>;
start_date: Timestamp | null;
total_budget: Numeric | null;
}

export interface BranchUsers {
created_at: Generated<Timestamp | null>;
email: string;
is_admin: Generated<boolean | null>;
name: string;
user_id: Generated<number>;
}

export interface DB {
"branch.donors": BranchDonors;
"branch.expenditures": BranchExpenditures;
"branch.project_donations": BranchProjectDonations;
"branch.project_memberships": BranchProjectMemberships;
"branch.projects": BranchProjects;
"branch.users": BranchUsers;
}
19 changes: 19 additions & 0 deletions apps/backend/lambdas/projects/db.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Kysely, PostgresDialect } from 'kysely'
import { Pool } from 'pg'
import type { DB } from './db-types'


const db = new Kysely<DB>({
dialect: new PostgresDialect({
pool: new Pool({
host: process.env.DB_HOST ?? 'localhost',
port: Number(process.env.DB_PORT ?? 5432),
user: process.env.DB_USER ?? 'branch_dev',
password: process.env.DB_PASSWORD ?? 'password',
database: process.env.DB_NAME ?? 'branch_db',
ssl: false,
}),
}),
})

export default db
11 changes: 10 additions & 1 deletion apps/backend/lambdas/projects/handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';

import db from './db';

export const handler = async (event: any): Promise<APIGatewayProxyResult> => {
try {
// Support both API Gateway and Lambda Function URL events
Expand All @@ -16,7 +18,14 @@ export const handler = async (event: any): Promise<APIGatewayProxyResult> => {

// >>> ROUTES-START (do not remove this marker)
// CLI-generated routes will be inserted here
// <<< ROUTES-END

// GET /projects
if (rawPath === '/' && method === 'GET') {
const projects = await db.selectFrom("branch.projects").selectAll().execute();
return json(200, projects);
}

// <<< ROUTES-END

return json(404, { message: 'Not Found', path: normalizedPath, method });
} catch (err) {
Expand Down
57 changes: 57 additions & 0 deletions apps/backend/lambdas/projects/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,60 @@ paths:
properties:
ok:
type: boolean

/projects:
get:
summary: GET /projects
responses:
'200':
description: OK

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

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

/projects/{id}:
put:
summary: PUT /projects/{id}
parameters:
- in: path
name: id
required: true
schema:
type: string
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
name:
type: string
total_budget:
type: number
responses:
'200':
description: OK
Loading