owned this note
owned this note
Published
Linked with GitHub
# PAWSEARCH API -- PLAN AND ENDPOINTS
###### tags: `NestJs` `Rinkeby` `wallet` `ERC20 token`
# Table of Contents
[toc]
## Introduction
The data that we obtain from different variety of sources(blockchain, search engine..), termed as raw data, needs processing before we can utilize it for analysis and management purposes.
The datamodel below is formed by six main classes, that could be extended by the time.
## Data Model

## Main configuration(.env)
| Attribute | Description | Example |
| --------- | ----------- | ------- |
DATABASE_TYPE | Database type | postgres |
| POSTGRES_HOST | database host | localhost |
| POSTGRES_PORT | database port | 5432 |
| POSTGRES_USER | database username | postgres |
| POSTGRES_PASSWORD | database password | mysecretpassword |
| POSTGRES_DATABASE | databse name | postgres |
| API_PAWSEARCH | Search engine api url | `http://18.191.161.244/api/search` |
| API_KEY | Search engine api key | 6Fr5aMjHbwXJGBkKXBdS |
| SMTP_CONFIG | SMTP URL configuration | `smtps://test@gmail.com:password@smtp.gmail.com` |
| SMTP_FROM | SMTP Sender email and name(or Company) | `"PAW Search Team" <modules@test.com>` |
| PRIVATE_KEY | The admin private key used to sign transactions | `d0385a375954d4ea25a947ee0b370f72e74bc926f5224ffae115303fa7da03c7` |
| BC_RPC | Infura Rinkeby/mainnet RPC | `https://rinkeby.infura.io/v3/f9921c5ce48c41f9a68ec3e0db7ef171` |
| UPI_ADDRESS | UPI token ethereum address | |
| UPT_KARMA_POINTS_RATE | UPI and Karm point rate example (1UPI = 100 karma points) | 100 |
| MIN_KARMA_POINT | Min required karma to exchange to UPI tokens | 500 |
## Account validation process
In order to validate new users accounts, 4 steps are required.
1 - user sign up
2 - he will receive and OTP code by email
3 - when signed using(username, password), he has to validate his account.
4 - once the code is validated the account is activated and he could start surfing.
## PAWSEARCH MAIN APIs
This api is formed of eight main endpoints to manage paw search user data.
### Note
> For all the next endpoints(except users post & main search engine endpoint) the header should be filled with the authorization bearer
> `Authorization: bearer jwt_token`
### Main search engine endpoint
Method: get `/search/term`: return data from search engine api
### Users api:
manage users accounts as described below:
**Endpoint` /users`**
* Method: `post`
This method will save users data and send the OTP code by email, for testing purpose now it returns all data(OPT Token):
Body:
```JSON
{
"email":"username@test.com",
"username":"username",
"password":"password",
"firstName" : "firstname",
"lastName": "lastname"
}
```
Result:
```JSON
{
"address": "0x",
"rememberCountry": false,
"karmaBalance": 0,
"karmaLevel": 0,
"pointsBalance": 0,
"totalPointsEarned": 0,
"upiBalance": 0,
"totalUpiEarned": 0,
"firstName": "firstname",
"lastName": "lastname",
"username": "username",
"email": "username@test.com",
"ipAddress": null,
"country_code": null,
"id": 5,
"validated": false,
"rememberIp": false
}
```
* Method: post `auth/login`
Body:
```JSON
{
"username":"firstname",
"password":"&@@*HHTG"
}
```
Result:
```JSON
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InpvdWhhaXIiLCJzdWIiOjEsImlhdCI6MTYwNTQ1NjgxMywiZXhwIjoxNjA1NDU5ODEzfQ.72mkA2c-s0v4sm_YkqmCdHS_NBAu-Deq7JnXoKcJdgc",
"user_id": 1
}
```
We saved the user's data, but account still invalidated till user fill the right OTP:
to Validate the OTP, put users endpoint should be used as below:
* Method: `put`
```JSON
{
"otpToken": "258596",
}
```
This method could be used also to increse or decrease user balance whether it was for karma or points and all other attributes.
Login: all endpoints are protected with JWT guards, so users should be logged to invoke others endpoints except `/users post & /search/term`.
* Method: get `/profile`
Returns current connected user's details as below:
```JSON
{
"address": "0x",
"rememberCountry": false,
"karmaBalance": 12,
"karmaLevel": 0,
"pointsBalance": 0,
"totalPointsEarned": 0,
"upiBalance": 0,
"totalUpiEarned": 0,
"id": 2,
"username": "username",
"email": "username@test.com",
"firstName": "admin",
"validated": false,
"lastName": "admin",
"ipAddress": null,
"rememberIp": false,
"country_code": null,
"setting": null,
"avatar": null,
"search": {
"id": 1,
"savedLinks": [],
"hiddenLinks": [],
"hiddenDomains": [],
"preferredDomains": [],
"recordHistory": true,
"filterExplicit": true,
"resultsPerPage": 10,
"openInNewWindow": false,
"showDetails": true,
"showThumbnail": true,
"terms": [
{
"id": 1,
"content": "tata",
"timeStamp": "A Javascript datetime string",
"device": "string",
"deviceType": "string"
}
]
}
}
```
### Setting api
this endpoint save connected user settings as below
**Endpoint `/settings`**
* Method: `post`
Body:
```JSON
{
"darkTheme":"#87872",
"themeColor": "#433",
"fontSize": 32,
"showQuickLinks": false,
"quickLinks":["http://google.com","http://dev.com"]
}
```
Result:
```JSON
{
"darkTheme": "ddddd",
"themeColor": "333",
"fontSize": 32,
"showQuickLinks": false,
"quickLinks": [
"eeee",
"eeee"
],
...
"id": 1
}
```
* Method: `put`
Body:
```JSON
{
"darkTheme": "theme",
"themeColor": "#33232323",
"fontSize": 32,
"showQuickLinks": false,
"quickLinks": [
"http://google.com",
"http://homme.com"
],
"id": 6
}
```
Result:
```
boolean
```
### Avatars api
this endpoint save connected user avatar as below
**Endpoint: `/avatars`**
* Method: `post`
Body:
```JSON
{
"selected":"true",
"unlocked": "false",
"hidden": ["ddd","ddddwww"],
"wanted": ["ddd","ddd"],
"display":"ss"
}
```
Result:
```JSON
{
"selected": "ddddd",
"unlocked": "333",
"hidden": [
"ddd",
"ddddwww"
],
"wanted": [
"ddd",
"ddd"
],
"display": "ss",
...
"id": 2
}
```
* Method: `put`
Body:
```JSON
{
"selected": "ddddd",
"unlocked": "333",
"hidden": [
"ddd",
"ddddwww"
],
"wanted": [
"dev2",
"dev1"
],
"display": "false",
"id": 3
}
```
Result:
```
boolean
```
### SearchSettings api
This endpoint save connected user avatar as below
**Endpoint `/seachSettings`**
* Method: `post`
Body:
```JSON
{
"savedLinks": [],
"hiddenLinks": [],
"hiddenDomains": [],
"preferredDomains": [],
"recordHistory": true,
"filterExplicit": true,
"resultsPerPage": 10,
"openInNewWindow": false,
"showDetails": true,
"showThumbnail": true
}
```
* Method(Example): put
Body:
```JSON
{
"showThumbnail": true,
"id": 1
}
```
Result:
```
boolean
```
### Terms api
this endpoint search terms
**Endpoint `/terms`**
* Method: `post`
Body:
```JSON
{
"searchId": 1,
"content": "description",
"timeStamp": "A Javascript datetime string",
"device": "string",
"deviceType": string
}
```
* Method: `put`
Body:
```JSON
{
"content": "tata",
"timeStamp": "A Javascript datetime string",
"device": "string",
"deviceType": "string",
"id": 1
}
```
Result:
```
boolean
```
### Transactions api
this endpoint save admin & user transactions logs
**Endpoint `/transactions`**
* Method: `post`
Body:
```JSON
{
"txid":"0x9fc76417374aa880d4349a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b",
"status":true
}
```
result
```JSON
{
"user": {
"address": "0x",
"rememberCountry": false,
"karmaBalance": 0,
"karmaLevel": 0,
"pointsBalance": 0,
"totalPointsEarned": 0,
"upiBalance": 0,
"totalUpiEarned": 0,
"id": 1
},
"txid": "0x9fc76417374aa880d4349a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b",
"status": true,
"id": 4
}
```
* Method: `put`
Body:
```JSON
{
"id":4,
"status": false
}
```
Result:
```
boolean
```
* Method: `get`
Result:
```JSON
[
{
"id": 3,
"txid": "0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b",
"status": true
},
{
"id": 4,
"txid": "0x9fc76417374aa880d4349a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b",
"status": false
}
]
```
### Exchanges api
this endpoint exchanges karma points to UPI tokens
**Endpoint `/exchanges`**
* Method: `post`
Body:
```JSON
{
"karmaPoints":511,
"address":"0x20c558DD389b101e4141f2Aa59209FB11c944d06"
}
```
Result:
```JSON
{
"txid": "0xbe4dcc7a35d1313dd9e9eac2c507e5909550f830a8a7fa02acdf5505b627106b",
"to": "0x20c558DD389b101e4141f2Aa59209FB11c944d06",
"status": true,
"karmaPoints": 511,
"id": 7,
"created_at": "2020-11-15T15:16:44.955Z"
}
```
* Method: `get`
Result:
```JSON
[
{
"id": 4,
"txid": "0x791aa4cc2656a17c10e6d280db3b419044959f7cd9cd309be2da6c159ef45521",
"to": "0x20c558DD389b101e4141f2Aa59209FB11c944d06",
"karmaPoints": 500,
"status": true,
"created_at": "2020-11-15T15:01:59.208Z"
},
{
"id": 5,
"txid": "0x2576a34696d2c4dc92831cddb47608d9115caad80e99348c7bcf8306c1b2aa46",
"to": "0x20c558DD389b101e4141f2Aa59209FB11c944d06",
"karmaPoints": 511,
"status": true,
"created_at": "2020-11-15T15:02:59.517Z"
}
]
```
## Test karmaBlance/UPI Tokens exchange
To test the karmaBlance/UPI tokens exchange
you should update the karmaBalance to at least 500 points as below:
endpoit: users
Method: put
Body:
```JSON
{
"karmaBalance": 1000
}
```
Result
boolean
Then go to [exchange/post endpoint](#Exchanges-api)