in amplify/backend/function/ConnectDialerJS/src/index.js [67:125]
async function resetMaxAttempts(){
// Now Datetime
var now = new Date();
var nowseconds = Math.round(now.getTime() / 1000);
var lastSuccessThreshold = nowseconds - (minbs * 60);
console.log(`lastSuccessThreshold: ${lastSuccessThreshold}`);
// Get users with a last success older than threshold
// DynamoDB parameters
let params = {
TableName: storageContactsStoreName,
IndexName:'Enabled-lastSuccess',
KeyConditionExpression: 'enabled = :enabled and lastSuccess < :lst',
FilterExpression: 'lastAttempt < :lst and contactAttempts >= :ma',
ExpressionAttributeValues: {
':enabled': "1",
':lst': lastSuccessThreshold,
':ma': ma
}
};
console.log(`resetMaxAttempts query DDB params: ${JSON.stringify(params)}`);
try {
var result = await docClient.query(params).promise();
} catch (error) {
console.error(JSON.stringify(error));
return {"Count": -1};
}
console.log(`resetMaxAttempts query DDB result: ${JSON.stringify(result)}`);
if (result['Count'] > 0){
await result.Items.forEach(async (item) => {
let dynamoParams = {
TableName: storageContactsStoreName,
Key: {
"telephoneNumber": item["telephoneNumber"]
},
UpdateExpression: "set contactAttempts = :attempts",
ExpressionAttributeValues: {
':attempts': 0
}
};
console.log(`resetMaxAttempts update DDB params: ${JSON.stringify(dynamoParams)}`);
try {
var result = await docClient.update(dynamoParams).promise();
} catch (error) {
console.error(error);
}
console.log(`queryDDB result: ${result}`);
});
return {"Count": result['Count']};
} else {
return {"Count": 0};
}
}