From 4513e828dac47a1818062c1cbd5d94d980a14ff3 Mon Sep 17 00:00:00 2001 From: Saumya Palakodety Date: Tue, 4 Nov 2025 18:56:03 -0500 Subject: [PATCH] route for project users --- apps/backend/lambdas/projects/db.ts | 18 +++++++++++++++++ apps/backend/lambdas/projects/handler.ts | 23 +++++++++++++++++++++- apps/backend/lambdas/projects/openapi.yaml | 13 ++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 apps/backend/lambdas/projects/db.ts diff --git a/apps/backend/lambdas/projects/db.ts b/apps/backend/lambdas/projects/db.ts new file mode 100644 index 0000000..a34eac4 --- /dev/null +++ b/apps/backend/lambdas/projects/db.ts @@ -0,0 +1,18 @@ +import { Kysely, PostgresDialect } from 'kysely' +import { Pool } from 'pg' +import type { DB } from './db-types' + +const db = new Kysely({ + 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 \ No newline at end of file diff --git a/apps/backend/lambdas/projects/handler.ts b/apps/backend/lambdas/projects/handler.ts index 4ad00a1..36af8f2 100644 --- a/apps/backend/lambdas/projects/handler.ts +++ b/apps/backend/lambdas/projects/handler.ts @@ -1,4 +1,5 @@ import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda'; +import db from './db'; export const handler = async (event: any): Promise => { try { @@ -16,7 +17,27 @@ export const handler = async (event: any): Promise => { // >>> ROUTES-START (do not remove this marker) // CLI-generated routes will be inserted here - // <<< ROUTES-END + + // 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 + }}); + } + // <<< ROUTES-END return json(404, { message: 'Not Found', path: normalizedPath, method }); } catch (err) { diff --git a/apps/backend/lambdas/projects/openapi.yaml b/apps/backend/lambdas/projects/openapi.yaml index cb44afd..e614e2e 100644 --- a/apps/backend/lambdas/projects/openapi.yaml +++ b/apps/backend/lambdas/projects/openapi.yaml @@ -18,3 +18,16 @@ paths: properties: ok: type: boolean + + /projects/{id}/members: + get: + summary: GET /projects/{id}/members + parameters: + - in: path + name: id + required: true + schema: + type: string + responses: + '200': + description: OK