AWS Amplify Project: Functions - a2n-seattle/rms-app GitHub Wiki
Field | Value |
---|---|
Milestone: | Milestone |
Owner: | Jeremy Yau |
Contributors: | Johnny Chen, Russell Nyrako |
Reviewer: | Jeremy Yau |
Status: | Approved |
As a Frontend Developer
I want to be able to perform CRUD operations against a centralized database
So that I can change the common state of the RMS system across devices.
Put this as documentation on top of the class
Right now, there are a bunch of APIs that have been created for the router implementation to call. For the App, we want to directly invoke the API to perform CRUD operations. We want to expose the existing APIs as Lambda functions, so that the Frontend team can call the APIs.
We should prioritize creating Lambda Handlers for CUD operations, since we want to try to perform read operations against the on device datastore. In Particular, here are the APIs that we want to create Lambda Handlers for:
-
High Priority
-
BorrowItem
-
ReturnItem
-
BorrowBatch
-
ReturnBatch
-
AddItem
-
DeleteItem
-
CreateBatch
-
DeleteBatch
-
-
Medium Priority (Update Operations)
-
UpdateDescription
-
UpdateTags
-
UpdateItemNotes
-
UpdateItemOwner
-
-
Low Priority (Read Operations)
-
GetItem
-
ReturnItem
-
SearchItems
-
GetBatch
-
ReturnBatch
-
internal/PrintTable
-
For each API, we need to:
-
Change
ScratchInterface
name to be<APIName>Input
and export the interface- This is so that the Frontend team can know what to pick up.
-
Implement field validation
- Context:
ScratchInterface
was created as a way to store user inputs for the router implementation. Thus, all fields are optional, so that you can store an incomplete object into the transactions database. We need validation that all fields have been given before we proceed with performing the API call.
-
Create new
performAllFVAs(input: <APIName>Input>): Promise<Void>
function -
Add all validation that is needed. At the baseline, we want to validate that all the inputs are given.
-
Insert
performAllFVAs
at the beginning of the promise chain of theexecute
function. -
Add tests in the existing test class for
performAllFVAs
- Context:
-
Create new handler for the API in the
handler
folder.- [Not Ready] Create tests for the create handler, overriding the database type and metric type.
-
Run
amplify function add
- Call amplify function
api-name
- Call amplify function
-
Change the amplify directory name to be
APIName
- This is for scripts to work properly
-
Delete
event.json
andindex.js
from thesrc
directory of the amplify function.- Optionally create a
test-json
folder and configure different json files that you can test the Lambda function with.
- Optionally create a
-
Change the
"main"
field inpackage.json
to equal./ts-output/handers/api/<APIName>.js
-
Modify CloudFormation template
-
Change the
"handler"
field fromindex.handler
to./ts-output/handlers/api/<APIName>.handler
-
Add the following to the PolicyDocument of AmplifyResourcesPolicy:
-
{
"Effect": "Allow",
"Action": [
"cloudwatch:PutMetricData"
],
"Resource": "*"
},
-
Add
APIName
to the list inamplify/backend/resources/scripts/compile-ts.sh
-
Add test for handler
- Can copy logic in
__tests__/handlers/api/BorrowBatch.test.ts
- Can copy logic in
Scenario | Expected Response |
---|---|
When the API is called with a valid input | Will perform the API's function, and return successfully |
These scenarios should be written up as tests, using the following naming convention:
'will <have expected response> when <a certain input is given>'