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
15 changes: 14 additions & 1 deletion apps/backend/lambdas/users/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,21 @@ export const handler = async (event: any): Promise<APIGatewayProxyResult> => {

return json(200, { ok: true, route: 'PATCH /users/{userId}', pathParams: { userId }, body: { email: updatedUser!.email, name: updatedUser!.name, isAdmin: updatedUser!.is_admin } });
}

// DELETE /users/{userId}
if (normalizedPath.startsWith('/') && normalizedPath.split('/').length === 2 && method === 'DELETE') {
const userId = normalizedPath.split('/')[1]; // Change from [2] to [1]
if (!userId) return json(400, { message: 'userId is required' });

// <<< ROUTES-END
const deleted = await db.deleteFrom('branch.users').where('user_id', '=', Number(userId)).execute();

if (!deleted[0] || deleted[0].numDeletedRows === 0n) {
return json(404, { message: 'User not found' });
}

return json(200, { ok: true, route: 'DELETE /users/{userId}', pathParams: { userId } });
}
// <<< ROUTES-END

return json(404, { message: 'Not Found', path: normalizedPath, method });
} catch (err) {
Expand Down
2 changes: 2 additions & 0 deletions apps/backend/lambdas/users/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
roots: ['<rootDir>/test'],
testMatch: ['**/*.test.ts'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
};
11 changes: 11 additions & 0 deletions apps/backend/lambdas/users/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,14 @@ paths:
description: OK
'404':
description: User not found
delete:
summary: DELETE /users/{userId}
parameters:
- in: path
name: userId
required: true
schema:
type: string
responses:
'200':
description: OK
Loading