-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added conversations-clear.ts, groups-clear.ts, users-clear.ts (#7)
- Loading branch information
1 parent
3555192
commit f6d8d56
Showing
5 changed files
with
154 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { DynamoDBClient, ScanCommand, DeleteItemCommand, DeleteTableCommand } from "@aws-sdk/client-dynamodb"; | ||
import {APIGatewayProxyEventV2} from "aws-lambda"; | ||
|
||
const client = new DynamoDBClient({ region: 'eu-central-1' }); | ||
|
||
export const handler = async (event: APIGatewayProxyEventV2) => { | ||
|
||
const getCommand = new ScanCommand({ | ||
TableName: 'rsschool-2023-conversations', | ||
ExpressionAttributeNames: { | ||
"#ID": "id", | ||
"#U1": "user1", | ||
"#U2": "user2", | ||
}, | ||
ProjectionExpression: "#ID, #U1, #U2", | ||
}); | ||
const result = await client.send(getCommand); | ||
|
||
const deleteRequests = result.Items.map(item => { | ||
const conversationID = item.id.S; | ||
|
||
const deleteItemCommand = new DeleteItemCommand({ | ||
TableName: "rsschool-2023-conversations", | ||
Key: { | ||
id: { | ||
S: conversationID, | ||
}, | ||
}, | ||
ReturnValues: "NONE", | ||
}); | ||
const deleteItemQuery = client.send(deleteItemCommand); | ||
|
||
const deleteTableCommand = new DeleteTableCommand({ | ||
TableName: `conversation-${conversationID}`, | ||
}); | ||
const deleteTableQuery = client.send(deleteTableCommand); | ||
|
||
|
||
return Promise.allSettled([deleteItemQuery, deleteTableQuery]).then(res => ({conversationID, result: res.status === 'fulfilled' ? res.value : res.reason})); | ||
Check failure on line 39 in src/functions/conversations-clear.ts GitHub Actions / Build & Deploy
Check failure on line 39 in src/functions/conversations-clear.ts GitHub Actions / Build & Deploy
|
||
}); | ||
|
||
const response = await Promise.allSettled(deleteRequests); | ||
|
||
|
||
return { | ||
statusCode: 200, | ||
body: JSON.stringify(response), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { DynamoDBClient, ScanCommand, DeleteItemCommand, DeleteTableCommand } from "@aws-sdk/client-dynamodb"; | ||
import {APIGatewayProxyEventV2} from "aws-lambda"; | ||
|
||
const client = new DynamoDBClient({ region: 'eu-central-1' }); | ||
|
||
export const handler = async (event: APIGatewayProxyEventV2) => { | ||
|
||
const getCommand = new ScanCommand({ | ||
TableName: 'rsschool-2023-groups', | ||
ExpressionAttributeNames: { | ||
"#ID": "id", | ||
}, | ||
ProjectionExpression: "#ID", | ||
}); | ||
const result = await client.send(getCommand); | ||
|
||
const deleteRequests = result.Items.map(item => { | ||
const groupID = item.id.S; | ||
|
||
const deleteItemCommand = new DeleteItemCommand({ | ||
TableName: "rsschool-2023-groups", | ||
Key: { | ||
id: { | ||
S: groupID, | ||
}, | ||
}, | ||
ReturnValues: "NONE", | ||
}); | ||
const deleteItemQuery = client.send(deleteItemCommand); | ||
|
||
const deleteTableCommand = new DeleteTableCommand({ | ||
TableName: `group-${groupID}`, | ||
}); | ||
const deleteTableQuery = client.send(deleteTableCommand); | ||
|
||
|
||
return Promise.allSettled([deleteItemQuery, deleteTableQuery]).then(res => ({groupID, result: res.status === 'fulfilled' ? res.value : res.reason})); | ||
Check failure on line 37 in src/functions/groups-clear.ts GitHub Actions / Build & Deploy
Check failure on line 37 in src/functions/groups-clear.ts GitHub Actions / Build & Deploy
|
||
}); | ||
|
||
const response = await Promise.allSettled(deleteRequests); | ||
|
||
|
||
return { | ||
statusCode: 200, | ||
body: JSON.stringify(response), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { DynamoDBClient, ScanCommand, DeleteItemCommand } from "@aws-sdk/client-dynamodb"; | ||
import {APIGatewayProxyEventV2} from "aws-lambda"; | ||
|
||
const client = new DynamoDBClient({ region: 'eu-central-1' }); | ||
|
||
export const handler = async (event: APIGatewayProxyEventV2) => { | ||
|
||
const getCommand = new ScanCommand({ | ||
TableName: 'rsschool-2023-users', | ||
ExpressionAttributeNames: { | ||
"#E": "email", | ||
}, | ||
ProjectionExpression: "#E", | ||
}); | ||
const result = await client.send(getCommand); | ||
|
||
const deleteRequests = result.Items.map(item => { | ||
const email = item.email.S; | ||
|
||
const deleteItemCommand = new DeleteItemCommand({ | ||
TableName: "rsschool-2023-users", | ||
Key: { | ||
email: { | ||
S: email, | ||
}, | ||
}, | ||
ReturnValues: "NONE", | ||
}); | ||
const deleteItemQuery = client.send(deleteItemCommand); | ||
|
||
|
||
return deleteItemQuery.then(res => ({email, result: res.status === 'fulfilled' ? res.value : res.reason})); | ||
Check failure on line 32 in src/functions/users-clear.ts GitHub Actions / Build & Deploy
Check failure on line 32 in src/functions/users-clear.ts GitHub Actions / Build & Deploy
|
||
}); | ||
|
||
const response = await Promise.allSettled(deleteRequests); | ||
|
||
|
||
return { | ||
statusCode: 200, | ||
body: JSON.stringify(response), | ||
}; | ||
}; |