feat: Update .gitignore, add Lambda layer configuration, and refactor DynamoDB handlers to use AWS SDK v3
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
import { DynamoDB } from "aws-sdk";
|
||||
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
|
||||
import { DynamoDBDocument, PutCommandInput } from "@aws-sdk/lib-dynamodb";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
const SLS_REGION = process.env.SLS_REGION;
|
||||
const TASKER_PROJECT_TABLE_NAME = process.env.TASKER_PROJECT_TABLE_NAME || "";
|
||||
|
||||
const docClient = new DynamoDB.DocumentClient({ region: SLS_REGION });
|
||||
const client = new DynamoDBClient({ region: SLS_REGION });
|
||||
const docClient = DynamoDBDocument.from(client);
|
||||
|
||||
export const handler = async (event: any): Promise<any> => {
|
||||
const { name, description, startDate, endDate } = event.body;
|
||||
try {
|
||||
const newProject = {
|
||||
type: "projects",
|
||||
category: "projects",
|
||||
projectId: `project#${uuidv4()}`,
|
||||
name,
|
||||
description,
|
||||
@@ -18,12 +20,12 @@ export const handler = async (event: any): Promise<any> => {
|
||||
endDate,
|
||||
};
|
||||
|
||||
const params = {
|
||||
const params: PutCommandInput = {
|
||||
TableName: TASKER_PROJECT_TABLE_NAME,
|
||||
Item: newProject,
|
||||
};
|
||||
|
||||
await docClient.put(params).promise();
|
||||
await docClient.put(params);
|
||||
|
||||
return {
|
||||
status: 201,
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { DynamoDB } from "aws-sdk";
|
||||
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
|
||||
import { DynamoDBDocument, PutCommandInput } from "@aws-sdk/lib-dynamodb";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
const SLS_REGION = process.env.SLS_REGION;
|
||||
const TASKER_TASK_TABLE_NAME = process.env.TASKER_TASK_TABLE_NAME || "";
|
||||
|
||||
const docClient = new DynamoDB.DocumentClient({ region: SLS_REGION });
|
||||
const client = new DynamoDBClient({ region: SLS_REGION });
|
||||
const docClient = DynamoDBDocument.from(client);
|
||||
|
||||
export const handler = async (event: any): Promise<any> => {
|
||||
const {
|
||||
@@ -22,7 +24,7 @@ export const handler = async (event: any): Promise<any> => {
|
||||
} = event.body;
|
||||
try {
|
||||
const newTask = {
|
||||
type: "tasks",
|
||||
category: "tasks",
|
||||
taskId: `task#${uuidv4()}`,
|
||||
title,
|
||||
description,
|
||||
@@ -37,12 +39,12 @@ export const handler = async (event: any): Promise<any> => {
|
||||
assignedUserId,
|
||||
};
|
||||
|
||||
const params = {
|
||||
const params: PutCommandInput = {
|
||||
TableName: TASKER_TASK_TABLE_NAME,
|
||||
Item: newTask,
|
||||
};
|
||||
|
||||
await docClient.put(params).promise();
|
||||
await docClient.put(params);
|
||||
|
||||
return {
|
||||
status: 201,
|
||||
|
||||
@@ -1,32 +1,34 @@
|
||||
import { fetchRandomTeamId } from "@/lib/util";
|
||||
import { DynamoDB } from "aws-sdk";
|
||||
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
|
||||
import { DynamoDBDocument, PutCommandInput } from "@aws-sdk/lib-dynamodb";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
const SLS_REGION = process.env.SLS_REGION;
|
||||
const TASKER_USER_TABLE_NAME = process.env.TASKER_USER_TABLE_NAME || "";
|
||||
|
||||
const docClient = new DynamoDB.DocumentClient({ region: SLS_REGION });
|
||||
const client = new DynamoDBClient({ region: SLS_REGION });
|
||||
const docClient = DynamoDBDocument.from(client);
|
||||
|
||||
export const handler = async (event: any): Promise<any> => {
|
||||
const { username, cognitoId, profilePictureUrl = "i0.jpg" } = event.body;
|
||||
const { username, cognitoId } = event.body;
|
||||
const teamId = fetchRandomTeamId();
|
||||
|
||||
try {
|
||||
const newUser = {
|
||||
type: "users",
|
||||
category: "users",
|
||||
cognitoId,
|
||||
userId: `user#${uuidv4()}`,
|
||||
username,
|
||||
profilePictureUrl,
|
||||
profilePictureUrl: "i0.jpg",
|
||||
teamId,
|
||||
};
|
||||
|
||||
const params = {
|
||||
const params: PutCommandInput = {
|
||||
TableName: TASKER_USER_TABLE_NAME,
|
||||
Item: newUser,
|
||||
};
|
||||
|
||||
await docClient.put(params).promise();
|
||||
await docClient.put(params);
|
||||
|
||||
return {
|
||||
status: 201,
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
import { DynamoDB } from "aws-sdk";
|
||||
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
|
||||
import { DynamoDBDocument, QueryCommandInput } from "@aws-sdk/lib-dynamodb";
|
||||
|
||||
const SLS_REGION = process.env.SLS_REGION;
|
||||
const TASKER_PROJECT_TABLE_NAME = process.env.TASKER_PROJECT_TABLE_NAME || "";
|
||||
|
||||
const docClient = new DynamoDB.DocumentClient({ region: SLS_REGION });
|
||||
const client = new DynamoDBClient({ region: SLS_REGION });
|
||||
const docClient = DynamoDBDocument.from(client);
|
||||
|
||||
export const handler = async (event: any): Promise<any> => {
|
||||
try {
|
||||
const params = {
|
||||
const params: QueryCommandInput = {
|
||||
TableName: TASKER_PROJECT_TABLE_NAME,
|
||||
KeyConditionExpression: "type = :type",
|
||||
KeyConditionExpression: "category = :category",
|
||||
ExpressionAttributeValues: {
|
||||
":type": "projects",
|
||||
":category": "projects",
|
||||
},
|
||||
};
|
||||
|
||||
const projects = await docClient.query(params).promise();
|
||||
const projects = await docClient.query(params);
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
|
||||
@@ -3,27 +3,29 @@ import {
|
||||
fetchComments,
|
||||
fetchUserWithUserId,
|
||||
} from "@/lib/util";
|
||||
import { DynamoDB } from "aws-sdk";
|
||||
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
|
||||
import { DynamoDBDocument, QueryCommandInput } from "@aws-sdk/lib-dynamodb";
|
||||
|
||||
const SLS_REGION = process.env.SLS_REGION;
|
||||
const TASKER_TASK_TABLE_NAME = process.env.TASKER_TASK_TABLE_NAME || "";
|
||||
|
||||
const docClient = new DynamoDB.DocumentClient({ region: SLS_REGION });
|
||||
const client = new DynamoDBClient({ region: SLS_REGION });
|
||||
const docClient = DynamoDBDocument.from(client);
|
||||
|
||||
export const handler = async (event: any): Promise<any> => {
|
||||
const { projectId } = event.queryStringParameters;
|
||||
try {
|
||||
const params = {
|
||||
const params: QueryCommandInput = {
|
||||
TableName: TASKER_TASK_TABLE_NAME,
|
||||
KeyConditionExpression: "type = :type AND projectId = :projectId",
|
||||
KeyConditionExpression: "category = :category AND projectId = :projectId",
|
||||
IndexName: "GSI-project-id",
|
||||
ExpressionAttributeValues: {
|
||||
":type": "tasks",
|
||||
":category": "tasks",
|
||||
":projectId": projectId,
|
||||
},
|
||||
};
|
||||
|
||||
const result = await docClient.query(params).promise();
|
||||
const result = await docClient.query(params);
|
||||
const tasks = result.Items || [];
|
||||
|
||||
const tasksWithDetails = await Promise.all(
|
||||
|
||||
@@ -1,22 +1,24 @@
|
||||
import { fetchUserWithUserId } from "@/lib/util";
|
||||
import { DynamoDB } from "aws-sdk";
|
||||
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
|
||||
import { DynamoDBDocument, QueryCommandInput } from "@aws-sdk/lib-dynamodb";
|
||||
|
||||
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 });
|
||||
const client = new DynamoDBClient({ region: SLS_REGION });
|
||||
const docClient = DynamoDBDocument.from(client);
|
||||
|
||||
export const handler = async (event: any): Promise<any> => {
|
||||
try {
|
||||
const params = {
|
||||
const params: QueryCommandInput = {
|
||||
TableName: TASKER_TEAM_TABLE_NAME,
|
||||
KeyConditionExpression: "type = :type",
|
||||
KeyConditionExpression: "category = :category",
|
||||
ExpressionAttributeValues: {
|
||||
":type": "teams",
|
||||
":category": "teams",
|
||||
},
|
||||
};
|
||||
|
||||
const result = await docClient.query(params).promise();
|
||||
const result = await docClient.query(params);
|
||||
const teams = result.Items || [];
|
||||
|
||||
const teamsWithUsernames = await Promise.all(
|
||||
|
||||
@@ -1,23 +1,25 @@
|
||||
import { DynamoDB } from "aws-sdk";
|
||||
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 docClient = new DynamoDB.DocumentClient({ region: SLS_REGION });
|
||||
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 = {
|
||||
const params: QueryCommandInput = {
|
||||
TableName: TASKER_USER_TABLE_NAME,
|
||||
KeyConditionExpression: "type = :type AND cognitoId = :cognitoId",
|
||||
KeyConditionExpression: "category = :category AND cognitoId = :cognitoId",
|
||||
ExpressionAttributeValues: {
|
||||
":type": "users",
|
||||
":category": "users",
|
||||
":cognitoId": cognitoId,
|
||||
},
|
||||
};
|
||||
|
||||
const user = await docClient.query(params).promise();
|
||||
const user = await docClient.query(params);
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
import { DynamoDB } from "aws-sdk";
|
||||
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 docClient = new DynamoDB.DocumentClient({ region: SLS_REGION });
|
||||
const client = new DynamoDBClient({ region: SLS_REGION });
|
||||
const docClient = DynamoDBDocument.from(client);
|
||||
|
||||
export const handler = async (event: any): Promise<any> => {
|
||||
try {
|
||||
const params = {
|
||||
const params: QueryCommandInput = {
|
||||
TableName: TASKER_USER_TABLE_NAME,
|
||||
KeyConditionExpression: "type = :type",
|
||||
KeyConditionExpression: "category = :category",
|
||||
ExpressionAttributeValues: {
|
||||
":type": "users",
|
||||
":category": "users",
|
||||
},
|
||||
};
|
||||
|
||||
const users = await docClient.query(params).promise();
|
||||
const users = await docClient.query(params);
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
|
||||
34
tasker-server/src/handlers/postSignUp.ts
Normal file
34
tasker-server/src/handlers/postSignUp.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import https from "https";
|
||||
|
||||
export const handler = async (event: any): Promise<any> => {
|
||||
const postData = JSON.stringify({
|
||||
username:
|
||||
event.request.userAttributes["preferred_username"] || event.userName,
|
||||
cognitoId: event.userName,
|
||||
});
|
||||
|
||||
const options = {
|
||||
hostname: process.env.API_URL,
|
||||
port: 443,
|
||||
path: "/users",
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-category": "application/json",
|
||||
"Content-Length": Buffer.byteLength(postData),
|
||||
},
|
||||
};
|
||||
|
||||
const responseBody = new Promise((resolve, reject) => {
|
||||
const req = https.request(options, (res) => {
|
||||
res.setEncoding("utf8");
|
||||
let responseBody = "";
|
||||
res.on("data", (chunk) => (responseBody += chunk));
|
||||
res.on("end", () => resolve(responseBody));
|
||||
});
|
||||
req.on("error", (error) => reject(error));
|
||||
req.write(postData);
|
||||
req.end();
|
||||
});
|
||||
|
||||
return event;
|
||||
};
|
||||
@@ -1,18 +1,20 @@
|
||||
import { DynamoDB } from "aws-sdk";
|
||||
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
|
||||
import { DynamoDBDocument, UpdateCommandInput } from "@aws-sdk/lib-dynamodb";
|
||||
|
||||
const SLS_REGION = process.env.SLS_REGION;
|
||||
const TASKER_TASK_TABLE_NAME = process.env.TASKER_TASK_TABLE_NAME || "";
|
||||
|
||||
const docClient = new DynamoDB.DocumentClient({ region: SLS_REGION });
|
||||
const client = new DynamoDBClient({ region: SLS_REGION });
|
||||
const docClient = DynamoDBDocument.from(client);
|
||||
|
||||
export const handler = async (event: any): Promise<any> => {
|
||||
const { taskId } = event.pathParameters;
|
||||
const { status } = event.body;
|
||||
try {
|
||||
const params = {
|
||||
const params: UpdateCommandInput = {
|
||||
TableName: TASKER_TASK_TABLE_NAME,
|
||||
Key: {
|
||||
type: "tasks",
|
||||
category: "tasks",
|
||||
taskId,
|
||||
},
|
||||
UpdateExpression: "set #status = :status",
|
||||
@@ -25,7 +27,7 @@ export const handler = async (event: any): Promise<any> => {
|
||||
ReturnValues: "ALL_NEW",
|
||||
};
|
||||
|
||||
const updatedTask = await docClient.update(params).promise();
|
||||
const updatedTask = await docClient.update(params);
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { DynamoDB } from "aws-sdk";
|
||||
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
|
||||
import { DynamoDBDocument, QueryCommandInput } from "@aws-sdk/lib-dynamodb";
|
||||
|
||||
const SLS_REGION = process.env.SLS_REGION;
|
||||
const TASKER_PROJECT_TABLE_NAME = process.env.TASKER_PROJECT_TABLE_NAME || "";
|
||||
@@ -7,18 +8,19 @@ const TASKER_TASK_TABLE_NAME = process.env.TASKER_TASK_TABLE_NAME || "";
|
||||
const TASKER_TASK_EXTRA_TABLE_NAME =
|
||||
process.env.TASKER_TASK_EXTRA_TABLE_NAME || "";
|
||||
|
||||
const docClient = new DynamoDB.DocumentClient({ region: SLS_REGION });
|
||||
const client = new DynamoDBClient({ region: SLS_REGION });
|
||||
const docClient = DynamoDBDocument.from(client);
|
||||
|
||||
export const fetchRandomTeamId = async () => {
|
||||
const params = {
|
||||
TableName: TASKER_PROJECT_TABLE_NAME,
|
||||
KeyConditionExpression: "type = :type",
|
||||
KeyConditionExpression: "category = :category",
|
||||
ExpressionAttributeValues: {
|
||||
":type": "teams",
|
||||
":category": "teams",
|
||||
},
|
||||
};
|
||||
|
||||
const projects = await docClient.query(params).promise();
|
||||
const projects = await docClient.query(params);
|
||||
if (!projects.Items) {
|
||||
return null;
|
||||
}
|
||||
@@ -28,47 +30,47 @@ export const fetchRandomTeamId = async () => {
|
||||
};
|
||||
|
||||
export const fetchUserWithUserId = async (userId: string): Promise<any> => {
|
||||
const params: DynamoDB.DocumentClient.QueryInput = {
|
||||
const params: QueryCommandInput = {
|
||||
TableName: TASKER_USER_TABLE_NAME,
|
||||
KeyConditionExpression: "type = :type AND userId = :userId",
|
||||
KeyConditionExpression: "category = :category AND userId = :userId",
|
||||
IndexName: "GSI-user-id",
|
||||
ExpressionAttributeValues: {
|
||||
":type": "users",
|
||||
":category": "users",
|
||||
":userId": userId,
|
||||
},
|
||||
};
|
||||
|
||||
const result = await docClient.query(params).promise();
|
||||
const result = await docClient.query(params);
|
||||
return result.Items?.[0];
|
||||
};
|
||||
|
||||
export const fetchComments = async (taskId: string): Promise<any> => {
|
||||
const params: DynamoDB.DocumentClient.QueryInput = {
|
||||
const params: QueryCommandInput = {
|
||||
TableName: TASKER_TASK_EXTRA_TABLE_NAME,
|
||||
KeyConditionExpression: "type = :type AND taskId = :taskId",
|
||||
KeyConditionExpression: "category = :category AND taskId = :taskId",
|
||||
IndexName: "GSI-task-id",
|
||||
ExpressionAttributeValues: {
|
||||
":type": "comments",
|
||||
":category": "comments",
|
||||
":taskId": taskId,
|
||||
},
|
||||
};
|
||||
|
||||
const result = await docClient.query(params).promise();
|
||||
const result = await docClient.query(params);
|
||||
return result.Items;
|
||||
};
|
||||
|
||||
export const fetchAttachments = async (taskId: string): Promise<any> => {
|
||||
const params: DynamoDB.DocumentClient.QueryInput = {
|
||||
const params: QueryCommandInput = {
|
||||
TableName: TASKER_TASK_EXTRA_TABLE_NAME,
|
||||
KeyConditionExpression: "type = :type AND taskId = :taskId",
|
||||
KeyConditionExpression: "category = :category AND taskId = :taskId",
|
||||
IndexName: "GSI-task-id",
|
||||
ExpressionAttributeValues: {
|
||||
":type": "attachments",
|
||||
":category": "attachments",
|
||||
":taskId": taskId,
|
||||
},
|
||||
};
|
||||
|
||||
const result = await docClient.query(params).promise();
|
||||
const result = await docClient.query(params);
|
||||
return result.Items;
|
||||
};
|
||||
|
||||
@@ -76,13 +78,13 @@ export const queryTasks = async (
|
||||
userId: string,
|
||||
indexName: string,
|
||||
key: string
|
||||
): Promise<DynamoDB.ItemList> => {
|
||||
const params = {
|
||||
): Promise<any> => {
|
||||
const params: QueryCommandInput = {
|
||||
TableName: TASKER_TASK_TABLE_NAME,
|
||||
KeyConditionExpression: "type = :type AND #key = :userId",
|
||||
KeyConditionExpression: "category = :category AND #key = :userId",
|
||||
IndexName: indexName,
|
||||
ExpressionAttributeValues: {
|
||||
":type": "tasks",
|
||||
":category": "tasks",
|
||||
":userId": userId,
|
||||
},
|
||||
ExpressionAttributeNames: {
|
||||
@@ -90,6 +92,6 @@ export const queryTasks = async (
|
||||
},
|
||||
};
|
||||
|
||||
const result = await docClient.query(params).promise();
|
||||
const result = await docClient.query(params);
|
||||
return result.Items ?? [];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user