forked from aws-samples/amplify-next-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: updated the status field on PersonLearning to be not empty
- Loading branch information
Carsten Koch
committed
Dec 19, 2024
1 parent
cd90d5f
commit e67efcb
Showing
4 changed files
with
139 additions
and
64 deletions.
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,61 @@ | ||
const { | ||
ScanCommand, | ||
UpdateItemCommand, | ||
DynamoDBClient, | ||
} = require("@aws-sdk/client-dynamodb"); | ||
const { stdLog } = require("./filter-and-mapping"); | ||
const { getTable, getEnvironment } = require("../import-data/environments"); | ||
const { getAwsProfile } = require("./get-aws-profile"); | ||
const { fromIni } = require("@aws-sdk/credential-providers"); | ||
|
||
const fillFinishedOn = async () => { | ||
const TableName = getTable("Activity"); | ||
const log = stdLog(`[${TableName}] [UPDATE FIELD finishedOn]:`); | ||
log("Start processing…"); | ||
const region = getEnvironment().region; | ||
const profile = getAwsProfile(); | ||
const client = new DynamoDBClient({ | ||
region, | ||
credentials: fromIni({ profile }), | ||
}); | ||
const existingRecords = await client.send( | ||
new ScanCommand({ | ||
TableName, | ||
FilterExpression: "attribute_not_exists(#f)", | ||
ExpressionAttributeNames: { "#f": "finishedOn" }, | ||
Limit: 5000, | ||
}) | ||
); | ||
log( | ||
"Relevant records:", | ||
existingRecords.Items.map(({ id }) => id.S) | ||
); | ||
await Promise.all( | ||
existingRecords.Items.map(async ({ id, createdAt }) => { | ||
log("Processing record with ID:", id.S, "and createdAt:", createdAt.S); | ||
const params = { | ||
TableName, | ||
Key: { | ||
id, | ||
}, | ||
UpdateExpression: `SET finishedOn = :newValue`, | ||
ExpressionAttributeValues: { | ||
":newValue": createdAt, | ||
}, | ||
ReturnValues: "UPDATED_NEW", | ||
}; | ||
const response = await client.send(new UpdateItemCommand(params)); | ||
log( | ||
"Response:", | ||
"StatusCode", | ||
response.$metadata.httpStatusCode, | ||
"Attributes", | ||
response.Attributes.finishedOn | ||
); | ||
}) | ||
); | ||
}; | ||
|
||
module.exports = { | ||
fillFinishedOn, | ||
}; |
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,65 @@ | ||
const { | ||
ScanCommand, | ||
UpdateItemCommand, | ||
DynamoDBClient, | ||
} = require("@aws-sdk/client-dynamodb"); | ||
const { stdLog } = require("./filter-and-mapping"); | ||
const { getTable, getEnvironment } = require("../import-data/environments"); | ||
const { getAwsProfile } = require("./get-aws-profile"); | ||
const { fromIni } = require("@aws-sdk/credential-providers"); | ||
|
||
const fillLearningPersonStatus = async () => { | ||
const TableName = getTable("PersonLearning"); | ||
const log = stdLog(`[${TableName}] [UPDATE FIELD status]:`); | ||
log("Start processing…"); | ||
const region = getEnvironment().region; | ||
const profile = getAwsProfile(); | ||
const client = new DynamoDBClient({ | ||
region, | ||
credentials: fromIni({ profile }), | ||
}); | ||
const existingRecords = await client.send( | ||
new ScanCommand({ | ||
TableName, | ||
FilterExpression: "attribute_not_exists(#f)", | ||
ExpressionAttributeNames: { "#f": "status" }, | ||
Limit: 5000, | ||
}) | ||
); | ||
log( | ||
"Relevant records:", | ||
existingRecords.Items.map(({ id }) => id.S) | ||
); | ||
await Promise.all( | ||
existingRecords.Items.map(async ({ id, createdAt }) => { | ||
log("Processing record with ID:", id.S, "and createdAt:", createdAt.S); | ||
const params = { | ||
TableName, | ||
Key: { | ||
id, | ||
}, | ||
UpdateExpression: `SET #status = :newValue`, | ||
ExpressionAttributeNames: { | ||
"#status": "status", | ||
}, | ||
ExpressionAttributeValues: { | ||
":newValue": { S: "new" }, | ||
}, | ||
ReturnValues: "UPDATED_NEW", | ||
}; | ||
log("Update params:", params); | ||
const response = await client.send(new UpdateItemCommand(params)); | ||
log( | ||
"Response:", | ||
"StatusCode", | ||
response.$metadata.httpStatusCode, | ||
"Attributes", | ||
response.Attributes.status | ||
); | ||
}) | ||
); | ||
}; | ||
|
||
module.exports = { | ||
fillLearningPersonStatus, | ||
}; |
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