Skip to content
Open
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
13 changes: 6 additions & 7 deletions apps/backend/lambdas/projects/db.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Kysely, PostgresDialect } from 'kysely';
import { Pool } from 'pg';
import type { DB } from './db-types';
import { Kysely, PostgresDialect } from 'kysely'
import { Pool } from 'pg'
import type { DB } from './db-types'

const db = new Kysely<DB>({
dialect: new PostgresDialect({
Expand All @@ -10,9 +10,8 @@ const db = new Kysely<DB>({
user: process.env.DB_USER ?? 'branch_dev',
password: process.env.DB_PASSWORD ?? 'password',
database: process.env.DB_NAME ?? 'branch_db',
ssl: false,
ssl: false,
}),
}),
});

export default db;
})
export default db
22 changes: 19 additions & 3 deletions apps/backend/lambdas/projects/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
import db from './db';
import { ProjectValidationUtils } from './validation-utils';


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

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

// GET /projects/{id}/members
if (normalizedPath.startsWith('/projects/') && normalizedPath.split('/').length === 4 && method === 'GET') {
const id = normalizedPath.split('/')[2];
if (!id) return json(400, { message: 'id is required' });
const users = await db
.selectFrom('branch.project_memberships as pm')
.innerJoin('branch.users as u', 'u.user_id', 'pm.user_id')
.select([
'u.user_id',
'u.name',
'u.email',
'pm.role'
])
.where('pm.project_id', '=', id)
.execute();
return json(200, { ok: true, route: 'GET /projects/{id}/members', pathParams: { id }, body: {
users
}});
}
// GET /projects
if (rawPath === '/' && method === 'GET') {
const projects = await db.selectFrom("branch.projects").selectAll().execute();
Expand Down Expand Up @@ -72,7 +89,6 @@ export const handler = async (event: any): Promise<APIGatewayProxyResult> => {
}
}
// <<< ROUTES-END

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

/projects/{id}/members:
get:
summary: GET /projects/{id}/members
parameters:
- in: path
name: id
required: true
schema:
type: string
/projects:
post:
summary: POST /projects
Expand Down