Wip backend (#4)
* feat: Add new API handlers for user, project, and task management; update package dependencies * feat: Update .gitignore, add Lambda layer configuration, and refactor DynamoDB handlers to use AWS SDK v3 * feat: Update serverless configuration and refactor API handlers to improve error handling and response structure * feat: Add Cognito user pool name parameter and update API handlers to include CORS headers * feat: Update task and project ID formats, add populateSeedData function, and enhance user ID handling * feat: Update image source paths to use S3 public URL for profile and task attachments
This commit was merged in pull request #4.
This commit is contained in:
44
tasker-server/src/handlers/getUser.ts
Normal file
44
tasker-server/src/handlers/getUser.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
|
||||
import { DynamoDBDocument, QueryCommandInput } from "@aws-sdk/lib-dynamodb";
|
||||
|
||||
const SLS_REGION = process.env.SLS_REGION;
|
||||
const TASKER_USER_TABLE_NAME = process.env.TASKER_USER_TABLE_NAME || "";
|
||||
|
||||
const client = new DynamoDBClient({ region: SLS_REGION });
|
||||
const docClient = DynamoDBDocument.from(client);
|
||||
|
||||
export const handler = async (event: any): Promise<any> => {
|
||||
const { cognitoId } = event.pathParameters;
|
||||
try {
|
||||
const params: QueryCommandInput = {
|
||||
TableName: TASKER_USER_TABLE_NAME,
|
||||
KeyConditionExpression: "category = :category AND cognitoId = :cognitoId",
|
||||
ExpressionAttributeValues: {
|
||||
":category": "users",
|
||||
":cognitoId": cognitoId,
|
||||
},
|
||||
};
|
||||
|
||||
const user = await docClient.query(params);
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
},
|
||||
body: JSON.stringify(user.Items?.[0] || {}),
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
statusCode: 500,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
message: `Error retrieving user: ${error.message}`,
|
||||
}),
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user