Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
c9580cd
added prettier to clean up code
KrishnaSolo Feb 7, 2021
294e809
Updated template to have region env variable
KrishnaSolo Feb 7, 2021
2f1096d
Updated delete handler to delete cognito account linked to user
KrishnaSolo Feb 7, 2021
e3179b9
fixed body error in setUpParam function
KrishnaSolo Feb 7, 2021
f4903db
Fix param function name
KrishnaSolo Feb 7, 2021
0bbe781
Merge pull request #25 from TakeNoteInc/updated-delete-to-delete-cogn…
KrishnaSolo Feb 7, 2021
57c6aea
Added putJournal endpoint
Feb 7, 2021
d580b51
Add putWeeks
Feb 7, 2021
1e415d4
Merge pull request #29 from TakeNoteInc/weeks-endpoint
GurmeharS Feb 8, 2021
2073b16
Merge branch 'staging' into journals-endpoint
GurmeharS Feb 8, 2021
edf720e
Merge pull request #28 from TakeNoteInc/journals-endpoint
GurmeharS Feb 8, 2021
bf44337
Add more checks to validate
Feb 8, 2021
6b42cb6
fix order of delete, so user always gets deleted first
Feb 8, 2021
b5ea203
Change POST request to accept body input instead of input from cognito
Feb 9, 2021
e6f2e18
Fix event body parse error
Feb 9, 2021
2f140ee
Took out post confirmation
Feb 9, 2021
b295655
add POOL_ID to delete
Feb 9, 2021
0bbcf48
revert template
Feb 9, 2021
79bf1dc
Update template
Feb 9, 2021
e12c90f
Hardcode stage userpool name
Feb 9, 2021
af04f5e
remove schema from working template
Feb 9, 2021
50e7cbd
Take out post confirmation again
Feb 9, 2021
02ea958
Added handler for put notes request
KrishnaSolo Feb 12, 2021
134ebb3
Updated notes to use ID now and added logger
KrishnaSolo Feb 20, 2021
4b91abe
fixed uuid import
KrishnaSolo Feb 20, 2021
cf896ed
aded logging
KrishnaSolo Feb 20, 2021
19c7226
Updated id to using expressions values
KrishnaSolo Feb 20, 2021
f5bfabf
more logging
KrishnaSolo Feb 20, 2021
dc58ee5
trying hardcoded value
KrishnaSolo Feb 20, 2021
a308d06
fixed incorrect update
KrishnaSolo Feb 20, 2021
0ac4563
fixed incorrect update statment
KrishnaSolo Feb 20, 2021
b6814b4
fix id generation
KrishnaSolo Feb 20, 2021
c557020
updated namings
KrishnaSolo Feb 20, 2021
76c1dfa
added controller to get weeks for a user
KrishnaSolo Feb 21, 2021
6890a00
Added controller to get all entries in a week
KrishnaSolo Feb 21, 2021
fdc1576
updated put to only do updates
KrishnaSolo Feb 21, 2021
1c4e10c
Added post handler for new notes
KrishnaSolo Feb 21, 2021
29b1d1d
Merge pull request #38 from TakeNoteInc/#32-get-all-entries-in-week
KrishnaSolo Feb 21, 2021
c56a2ce
Merge branch 'staging' into #31-fetch-all-weeks-given-user
KrishnaSolo Feb 21, 2021
a2f253a
Merge pull request #37 from TakeNoteInc/#31-fetch-all-weeks-given-user
KrishnaSolo Feb 21, 2021
8fa67f2
Merge pull request #34 from TakeNoteInc/#16-create-put-request-for-notes
KrishnaSolo Feb 21, 2021
3293541
added handler to create a new entry
KrishnaSolo Feb 21, 2021
ca1193f
added entries to field path and udpate date to use isoString
KrishnaSolo Feb 22, 2021
37c7b67
added updated field
KrishnaSolo Feb 22, 2021
83d0667
Added id, created and updated field to note object
KrishnaSolo Feb 22, 2021
cf10c8c
Return validation details
Feb 23, 2021
f59b16d
Added route handler to update an entry
KrishnaSolo Feb 23, 2021
e4d0d74
Update gitignore to ignore all secret files ('.*')
Feb 23, 2021
fb435c9
Merge pull request #43 from TakeNoteInc/#30-return-invalid-inputs-on-…
GurmeharS Feb 23, 2021
2578576
Updated error code and fixed up naming
KrishnaSolo Feb 23, 2021
77ea169
fixed nits and updated naming to be singular
KrishnaSolo Feb 23, 2021
b022e24
updated name to be singular and updated error code
KrishnaSolo Feb 23, 2021
35118cc
Merge pull request #41 from TakeNoteInc/#39-created-post-request-for-…
KrishnaSolo Feb 23, 2021
0ecf155
Merge pull request #45 from TakeNoteInc/#33-add-route-to-update-entry
KrishnaSolo Feb 23, 2021
c345bee
Merge branch 'staging' into #42-create-post-for-entries
KrishnaSolo Feb 23, 2021
a5754ca
Merge pull request #44 from TakeNoteInc/#42-create-post-for-entries
KrishnaSolo Feb 23, 2021
88d6d71
Added delete endpoint handler
KrishnaSolo Feb 27, 2021
4c522ec
use remove over delete in update expression
KrishnaSolo Feb 27, 2021
bde2573
Added endpoint to allow deletes for note
KrishnaSolo Feb 27, 2021
cd69c8a
Merge pull request #48 from TakeNoteInc/#46-delete-for-entries
KrishnaSolo Mar 2, 2021
a1e3132
Fis isEmpty check for data
Apr 11, 2021
76cf40f
Merge branch 'staging' into #40-delete-notes-endpoint
KrishnaSolo Apr 11, 2021
5c7bdb7
Log data in getUser
Apr 11, 2021
05dbee6
added check for note id in path param for delete notes endpoint
KrishnaSolo Apr 11, 2021
4c9e4ed
Merge pull request #49 from TakeNoteInc/#40-delete-notes-endpoint
KrishnaSolo Apr 11, 2021
bc5a677
Updated post and put for notes to use singular note - was missed earl…
KrishnaSolo Apr 21, 2021
f3ba9f1
fixed up logging to be better - will need to apply this to other lamb…
KrishnaSolo Apr 21, 2021
77508b6
Merge pull request #50 from TakeNoteInc/fix-notes-to-note
KrishnaSolo Apr 22, 2021
2961f38
Note was missing metadata for puts - pushing to branch directly
KrishnaSolo Apr 22, 2021
468a623
Removing www
KrishnaSolo Dec 23, 2021
0429635
Deleting todo-src
KrishnaSolo Dec 23, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# All secret files
.*

*.DS_Store
# Logs
logs
Expand Down
80 changes: 80 additions & 0 deletions takeNotes-src/deleteEntry/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// default imports
const AWS = require("aws-sdk");
const DDB = new AWS.DynamoDB({ apiVersion: "2012-10-08" });
const { v4: uuidv4 } = require("uuid");

// environment variables
const { TABLE_NAME, ENDPOINT_OVERRIDE, REGION } = process.env;
const options = { region: REGION };
AWS.config.update({ region: REGION });

if (ENDPOINT_OVERRIDE !== "") {
options.endpoint = ENDPOINT_OVERRIDE;
}

const docClient = new AWS.DynamoDB.DocumentClient(options);

// response helper
const response = (statusCode, body, additionalHeaders) => ({
statusCode,
body: JSON.stringify(body),
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
...additionalHeaders,
},
});

function isValidRequest(context, event) {
let isIdValid =
event !== null &&
event.pathParameters !== null &&
event.pathParameters.id !== null &&
event.pathParameters.weekIdx !== null &&
event.pathParameters.entryIdx !== null;

return isIdValid;
}

function updateRecord(recordId, weekIdx, entryIdx) {
let d = new Date();
console.log("record id: " + recordId + " entryIdx: " + entryIdx);

const params = {
TableName: TABLE_NAME,
Key: {
id: recordId,
},
UpdateExpression: `SET updated = :u,
docBody.journal.weeks[${weekIdx}].updated = :u
REMOVE docBody.journal.weeks[${weekIdx}].entries.#entryId`,
ExpressionAttributeNames: { "#entryId": entryIdx },
ExpressionAttributeValues: {
":u": d.toISOString(),
},
ConditionExpression: `attribute_exists(docBody.journal.weeks[${weekIdx}].entries.#entryId)`,
ReturnValues: "ALL_NEW",
};
console.log("params: " + params);
return docClient.update(params);
}

// Lambda Handler
exports.deleteEntry = async (event, context, callback) => {
console.log("event: " + event);
console.log("body: " + event.body);
if (!isValidRequest(context, event)) {
return response(400, { message: "Error: Invalid request" });
}

try {
let data = await updateRecord(
event.pathParameters.id,
event.pathParameters.weekIdx,
event.pathParameters.entryIdx
).promise();
return response(200, data);
} catch (err) {
return response(500, { message: err.message });
}
};
109 changes: 109 additions & 0 deletions takeNotes-src/deleteEntry/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions takeNotes-src/deleteEntry/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "delete",
"version": "1.0.0",
"description": "Delete handler for TakeNotes users API",
"main": "src/app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"style": "npx prettier --write ."
},
"author": "",
"license": "ISC",
"dependencies": {
"aws-sdk": "^2.834.0",
"uuid": "^8.3.2"
}
}
75 changes: 75 additions & 0 deletions takeNotes-src/deleteNote/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// default imports
const AWS = require("aws-sdk");
const DDB = new AWS.DynamoDB({ apiVersion: "2012-10-08" });
const { v4: uuidv4 } = require("uuid");

// environment variables
const { TABLE_NAME, ENDPOINT_OVERRIDE, REGION } = process.env;
const options = { region: REGION };
AWS.config.update({ region: REGION });

if (ENDPOINT_OVERRIDE !== "") {
options.endpoint = ENDPOINT_OVERRIDE;
}

const docClient = new AWS.DynamoDB.DocumentClient(options);

// response helper
const response = (statusCode, body, additionalHeaders) => ({
statusCode,
body: JSON.stringify(body),
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
...additionalHeaders,
},
});

function isValidRequest(context, event) {
let isIdValid =
event !== null &&
event.pathParameters !== null &&
event.pathParameters.id !== null &&
event.pathParameters.noteIdx !== null;

return isIdValid;
}

function updateRecord(recordId, noteIdx) {
let d = new Date();
console.log("record id: " + recordId + " noteIdx: " + noteIdx);
const params = {
TableName: TABLE_NAME,
Key: {
id: recordId,
},
UpdateExpression: `SET updated = :u REMOVE docBody.notes.#noteId`,
ExpressionAttributeNames: { "#noteId": noteIdx },
ExpressionAttributeValues: {
":u": d.toISOString(),
},
ConditionExpression: "attribute_exists(docBody.notes.#noteId)",
ReturnValues: "ALL_NEW",
};
console.log("params: " + params);
return docClient.update(params);
}

// Lambda Handler
exports.deleteNote = async (event, context, callback) => {
console.log("event: " + event);
console.log("body: " + event.body);
if (!isValidRequest(context, event)) {
return response(400, { message: "Error: Invalid request" });
}

try {
let data = await updateRecord(
event.pathParameters.id,
event.pathParameters.noteIdx
).promise();
return response(200, data);
} catch (err) {
return response(400, { message: err.message });
}
};
Loading