feat: Add new API handlers for user, project, and task management; update package dependencies

This commit is contained in:
2024-11-21 11:21:21 +02:00
parent 132f526179
commit 86c671ccd8
15 changed files with 1288 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
import { fetchUserWithUserId } from "@/lib/util";
import { DynamoDB } from "aws-sdk";
const SLS_REGION = process.env.SLS_REGION;
const TASKER_TEAM_TABLE_NAME = process.env.TASKER_TEAM_TABLE_NAME || "";
const docClient = new DynamoDB.DocumentClient({ region: SLS_REGION });
export const handler = async (event: any): Promise<any> => {
try {
const params = {
TableName: TASKER_TEAM_TABLE_NAME,
KeyConditionExpression: "type = :type",
ExpressionAttributeValues: {
":type": "teams",
},
};
const result = await docClient.query(params).promise();
const teams = result.Items || [];
const teamsWithUsernames = await Promise.all(
teams.map(async (team: any) => {
const productOwnerUsername = team.productOwnerUserId
? (await fetchUserWithUserId(team.productOwnerUserId))?.username
: null;
const projectManagerUsername = team.projectManagerUserId
? (await fetchUserWithUserId(team.projectManagerUserId))?.username
: null;
return {
...team,
productOwnerUsername,
projectManagerUsername,
};
})
);
return {
status: 200,
body: JSON.stringify(teamsWithUsernames),
};
} catch (error: any) {
return {
status: 500,
body: JSON.stringify({
message: `Error retrieving teams: ${error.message}`,
}),
};
}
};