feat: Add new API handlers for user, project, and task management; update package dependencies
This commit is contained in:
52
tasker-server/src/handlers/getTeams.ts
Normal file
52
tasker-server/src/handlers/getTeams.ts
Normal 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}`,
|
||||
}),
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user