# Backend Specs

The backend for the I-am-human app is built using Node.js deployed to Google Cloud using Firebase-admin and connects to a [Supabase](https://supabase.com/docs/guides/database/overview) database.

Link to our source code on GitHub [here](https://github.com/near-ndc/i-am-human-backend).

\
API Endpoints

#### Database CRUD Operations API

* There are 4 endpoints which are pretty much self explanatory : `POST /api/select , api/insert , api/delete , api/update`
* This API helps to retrieve and update the supabase database.
* Request Body&#x20;
  * `/api/insert :`&#x20;

    ```javascript
    const { match = undefined, table } = req.body;
    ```
  * `/api/select :`&#x20;

    ```javascript
    const { match = undefined, table } = req.body;
    ```
  * `/api/update :`&#x20;

    ```javascript
    const { match, body , table } = req.body;
    ```
  * `/api/delete :`&#x20;

    ```javascript
    const { match, table } = req.body;
    ```
* Response: The API will respond with the data and any error if there is:

  ```javascript
  RESPONSE : { data: [..], error:"" }
  ```

#### is\_admin API

* Endpoint: POST `/api/is-admin`
* Request body:&#x20;
  * ```javascript
    const { wallet } = req.body;
    ```
* Response: The API will respond with a boolean value indicating whether the user with the specified ID is a superadmin or not.
* ```javascript
  RESPONSE : { is_super_admin: boolean }
  ```

#### Community Scoreboard API

Endpoint: GET `/scoreboard`

Checkout `scoreboard` branch to run the code

This API helps users to fetch data of humans onboarded using a particular community name and vertical.

Query Param: `communityName, communityVertical`: Mention the name or vertical of the community you want to receive data.

Response: The API will respond with an object containing `data` which is an array of objects and `error` which is a string of error message in case any error occurs.

```
RESPONSE : { data: [..], error:"" }
```

To help non technical users, we have made our scoreboard API open for community usage, following is the curl you can use to fetch data of humans onboarded using `communityName=marketingdao` and `communityVertical=infrastructure`

```
curl --location 
'https://scoreboard-ophc7vkxsq-uc.a.run.app/scoreboard?communityName=marketingdao&communityVertical=infrastructure'
```

### Installation and Setup

To install and set up the backend for the I-am-human app, follow these steps:

1. Clone the repository from GitHub.
2. Install the required dependencies using NPM.
3. Set up environment variables by creating a `.env` file in the root directory with the Supabase URL and key.
4. Start the server.

### Dependencies

The backend for the I-am-human app uses the following dependencies:

* `@supabase/supabase-js`: A JavaScript client for interacting with the Supabase API
* `body-parser`: A middleware for parsing request bodies
* `cors`: A middleware for enabling CORS
* `express` : A NODE JS backend server library
* `firebase-admin and firebase-functions: Used to host the APP on the firebase cloud functions`&#x20;
