Cloud functions for Lovebank App
1) Make sure Node.js and npm are installed. If you haven't already installed, you can do so here
To check if you have installed Node.js, run:
node -v
To check if you have installed npm, run:
npm -v
npm install -g firebase-tools
firebase login
To view the list of projects (and their IDs) associated with your current account, run
firebase projects:list
To switch to a project, run the following command - replace {project_id} with the ID of your project:
firebase use {project_id}
Within the "/functions" directory, run:
npm install
Functions are currently declared in the TypeScript file located at "functions/src/index.ts"
Within the "/functions" directory, run:
npm run serve
This will start the functions emulator and deploy them locally. For HTTPS functions, follow the URIs provided to trigger them.
To be written...
Send a PUT request to the URI for the invite function. The request body should be a JSON object with the following parameters:
Name | Required | Type | Description |
---|---|---|---|
id |
required | string | id of the user sending the invite |
mobile |
required | string | mobile number for invitee |
{
"id": "AAA4JAwXrwGeoTlZVuz",
"mobile": "+12345678901",
"action": "invite"
}
If the request is successful, a document will be added or updated in the invites collection. The response will be a JSON representation of this invite document.
{
"creation_time": {
"_seconds": 1595478889,
"_nanoseconds": 320000000
},
"expiration_time": {
"_seconds": 1596083689,
"_nanoseconds": 0
},
"requester_id": "AAA4JAwXrwGeoTlZVuz",
"invite_code": "731b7db1",
"mobile": "+12345678901"
}
Note: The creation_time and expiration_time fields are created using Firestore timestamps. For more information on Firestore timestamps please refer to this documentation.
Send a PUT request to the URI for the accept function. The request body should be a JSON object with the following parameters:
Name | Required | Type | Description |
---|---|---|---|
id |
required | string | id of the user accepting the invite |
code |
required | string | invite code |
{
"code": "731b7db1",
"id": "BBB86GaIFXBxRxyUZc3"
}
If the request is successful, the partnerId field for both users will be updated accordingly. The response will be a JSON object of the updated user document.
{
"balance": 0,
"displayName": "Bob",
"partnerId": "AAA4JAwXrwGeoTlZVuz",
"email": "[email protected]",
"mobile": "+12345678901"
}