-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateHighlight.js
44 lines (39 loc) · 1.26 KB
/
updateHighlight.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const AWS = require('aws-sdk');
const docClient = new AWS.DynamoDB.DocumentClient({region: "ap-southeast-2"});
exports.handler = (event, context, callback) => {
console.log("Processing...");
const params = {
Key: {webpageURL: event.url, highlightID: event.highlightID},
TableName: "highlights",
ReturnValues: 'ALL_NEW',
ExpressionAttributeValues: {
":topic": event.topic,
":colour": event.colour,
":notes": event.notes
},
UpdateExpression: "SET webpageTopic = :topic, highlightNotes = :notes, highlightColour = :colour"
};
const response = {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials': true,
},
body: JSON.stringify({
date: Date.now(),
webpageURL: event.url,
highlightID: context.awsRequestId,
highlightText: event.text,
webpageTitle: event.title,
webpageTopic: event.topic
}),
};
let self = this;
docClient.update(params, (err, data) => {
if(err){
callback(err, null);
} else {
callback(null, data);
}
})
};