sst.dev icon indicating copy to clipboard operation
sst.dev copied to clipboard

Comments: Add a List All the Notes API

Open jayair opened this issue 9 years ago • 9 comments

Link to chapter - http://serverless-stack.com/chapters/add-a-list-all-the-notes-api.html

jayair avatar Apr 10 '17 01:04 jayair

One suggestion - why not name the event.json files after the function they are testing, that way a library of them can be maintained in case of further testing? eg: serverless webpack invoke --function list --path -list-event.json

SherpaPsy avatar Apr 20 '17 12:04 SherpaPsy

Ah yeah that's not a bad idea. In the case of the tutorial, we just use it for one off testing cases and don't commit it to the repo - https://github.com/AnomalyInnovations/serverless-stack-demo-api/blob/master/.gitignore#L40

jayair avatar Apr 20 '17 18:04 jayair

Created a PR for this. Updated instructions to test functions coming from a mocks/ directory for cleaner structure.

ryanjcruz avatar May 13 '17 07:05 ryanjcruz

I'm following the serverless tutorial, and when it comes to this function I get a "Cannot read property 'id' of undefined" error. The previous tests ran just fine. I tried to look for a solution but I found nothing. Do I need to open a new issue?

bimbo1989 avatar Nov 27 '17 16:11 bimbo1989

Nevermind. Tried again today without changing anything and works flawlessly. Stranger things, season 3 :)

bimbo1989 avatar Nov 28 '17 08:11 bimbo1989

@bimbo1989 Thanks for reporting back.

jayair avatar Nov 28 '17 20:11 jayair

Hi, apologies if this doesn't belong here because of the modification I made, but I'm trying to write the "list all notes" API with a minor modification and running into an issue:

In list.js, I have this: const params = { TableName: "notes", IndexName: "teacher-index", KeyConditionExpression: "teacher = :teacher", ExpressionAttributeValues: { ":teacher": event.pathParameters.teacher } };

I am trying to retrieve all the notes that are assigned to a specific teacher (instead of the user), and the teacher field is NOT part of the key (partition or sort). So, I created an index (teacher-index) and referenced it above.

This works, with the list-event.json below: { "pathParameters": { "teacher": "Bill" } } It successfully returns all the notes that have the teacher field set to "Bill".

However, this does NOT work: { "pathParameters": { "teacher": "Omair Hamid" } } It returns an empty set, even though there are several notes that have the teacher field set to "Omair Hamid".

Are spaces something that I cannot have? Do I need to escape them? Am I building the list-event.json incorrectly or the list.js file?

omairhamid avatar Jan 26 '18 00:01 omairhamid

@omairhamid That looks okay and it should work. Can you just make sure that that it is stored and queried with a space in the middle and not a tab or something? Since Bill is working, it should be fine.

jayair avatar Jan 27 '18 23:01 jayair

This issue was moved to https://discourse.serverless-stack.com/t/comments-add-a-list-all-the-notes-api/147

jayair avatar May 09 '18 20:05 jayair