feat: Update task and project ID formats, add populateSeedData function, and enhance user ID handling
This commit is contained in:
1181
tasker-server/seed/populateSeedData.ts
Normal file
1181
tasker-server/seed/populateSeedData.ts
Normal file
File diff suppressed because it is too large
Load Diff
@@ -40,6 +40,11 @@ provider:
|
||||
- "arn:aws:execute-api:${self:provider.region}:*:*/*/POST/users"
|
||||
|
||||
functions:
|
||||
populateSeedData:
|
||||
handler: seed/populateSeedData.handler
|
||||
memorySize: 1024
|
||||
timeout: 60
|
||||
|
||||
# POST /users or triggered by Cognito
|
||||
createUser:
|
||||
handler: src/handlers/createUser.handler
|
||||
|
||||
@@ -14,7 +14,7 @@ export const handler = async (event: any): Promise<any> => {
|
||||
try {
|
||||
const newProject = {
|
||||
category: "projects",
|
||||
projectId: `project#${uuidv4()}`,
|
||||
projectId: `project_${uuidv4()}`,
|
||||
name,
|
||||
description,
|
||||
startDate,
|
||||
|
||||
@@ -25,7 +25,7 @@ export const handler = async (event: any): Promise<any> => {
|
||||
try {
|
||||
const newTask = {
|
||||
category: "tasks",
|
||||
taskId: `task#${uuidv4()}`,
|
||||
taskId: `task_${uuidv4()}`,
|
||||
title,
|
||||
description,
|
||||
status,
|
||||
|
||||
@@ -10,6 +10,7 @@ const client = new DynamoDBClient({ region: SLS_REGION });
|
||||
const docClient = DynamoDBDocument.from(client);
|
||||
|
||||
export const handler = async (event: any): Promise<any> => {
|
||||
console.info(`Event: ${JSON.stringify(event)}`);
|
||||
const username =
|
||||
event.request.userAttributes["preferred_username"] || event.userName;
|
||||
const cognitoId = event.userName;
|
||||
@@ -19,9 +20,9 @@ export const handler = async (event: any): Promise<any> => {
|
||||
const newUser = {
|
||||
category: "users",
|
||||
cognitoId,
|
||||
userId: `user#${uuidv4()}`,
|
||||
userId: `user_${uuidv4()}`,
|
||||
username,
|
||||
profilePictureUrl: "i0.jpg",
|
||||
profilePictureUrl: "p0.jpeg",
|
||||
teamId,
|
||||
};
|
||||
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
import https from "https";
|
||||
import path from "path";
|
||||
|
||||
const API_BASE_URL = process.env.API_BASE_URL || "";
|
||||
|
||||
export const handler = async (event: any): Promise<any> => {
|
||||
const postData = JSON.stringify({
|
||||
username:
|
||||
event.request.userAttributes["preferred_username"] || event.userName,
|
||||
cognitoId: event.userName,
|
||||
});
|
||||
|
||||
console.log(postData);
|
||||
|
||||
const options = {
|
||||
hostname: API_BASE_URL ? new URL(API_BASE_URL).hostname : "",
|
||||
port: 443,
|
||||
path: API_BASE_URL
|
||||
? path.join(new URL(API_BASE_URL).pathname, "/users")
|
||||
: "",
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-category": "application/json",
|
||||
"Content-Length": Buffer.byteLength(postData),
|
||||
"Allow-Control-Allow-Origin": "*",
|
||||
},
|
||||
};
|
||||
|
||||
const responseBody = await 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();
|
||||
});
|
||||
|
||||
console.log(responseBody);
|
||||
|
||||
return event;
|
||||
};
|
||||
@@ -2,7 +2,7 @@ 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 TASKER_TEAM_TABLE_NAME = process.env.TASKER_TEAM_TABLE_NAME || "";
|
||||
const TASKER_USER_TABLE_NAME = process.env.TASKER_USER_TABLE_NAME || "";
|
||||
const TASKER_TASK_TABLE_NAME = process.env.TASKER_TASK_TABLE_NAME || "";
|
||||
const TASKER_TASK_EXTRA_TABLE_NAME =
|
||||
@@ -13,20 +13,20 @@ const docClient = DynamoDBDocument.from(client);
|
||||
|
||||
export const fetchRandomTeamId = async () => {
|
||||
const params = {
|
||||
TableName: TASKER_PROJECT_TABLE_NAME,
|
||||
TableName: TASKER_TEAM_TABLE_NAME,
|
||||
KeyConditionExpression: "category = :category",
|
||||
ExpressionAttributeValues: {
|
||||
":category": "teams",
|
||||
},
|
||||
};
|
||||
|
||||
const projects = await docClient.query(params);
|
||||
if (!projects.Items) {
|
||||
const teams = await docClient.query(params);
|
||||
if (!teams.Items) {
|
||||
return null;
|
||||
}
|
||||
const randomProject =
|
||||
projects.Items[Math.floor(Math.random() * projects.Items.length)];
|
||||
return randomProject.id;
|
||||
const randomTeam =
|
||||
teams.Items[Math.floor(Math.random() * teams.Items.length)];
|
||||
return randomTeam.teamId;
|
||||
};
|
||||
|
||||
export const fetchUserWithUserId = async (userId: string): Promise<any> => {
|
||||
|
||||
@@ -1,11 +1,22 @@
|
||||
resource "aws_s3_bucket" "tasker_public_images" {
|
||||
bucket = "tasker-public-images"
|
||||
|
||||
tags = {
|
||||
Environment = "Dev"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_s3_bucket_policy" "public_read_policy" {
|
||||
bucket = aws_s3_bucket.tasker_public_images.id
|
||||
policy = data.aws_iam_policy_document.public_read_policy.json
|
||||
}
|
||||
|
||||
data "aws_iam_policy_document" "public_read_policy" {
|
||||
statement {
|
||||
actions = ["s3:GetObject"]
|
||||
resources = ["${aws_s3_bucket.tasker_public_images.arn}/*"]
|
||||
principals {
|
||||
type = "AWS"
|
||||
identifiers = ["*"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_s3_bucket_ownership_controls" "tasker_public_images_ownership_controls" {
|
||||
bucket = aws_s3_bucket.tasker_public_images.id
|
||||
|
||||
Reference in New Issue
Block a user