|
| 1 | +# COVID-19 Self-reporting API server User IDs |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +## Requirements |
| 11 | + |
| 12 | +You need these packages installed on your machine: |
| 13 | +* [Docker and docker-compose](https://docs.docker.com/compose/install/) |
| 14 | +* [NPM](https://www.npmjs.com/get-npm) |
| 15 | +* [nodejs](https://nodejs.org/en/) |
| 16 | + |
| 17 | +## Installation |
| 18 | + |
| 19 | +Clone the project and run these commands. |
| 20 | + |
| 21 | +``` |
| 22 | +$ cd <your_project_folder>/backend/app/ |
| 23 | +
|
| 24 | +$ npm install |
| 25 | +
|
| 26 | +$ cd .. |
| 27 | + |
| 28 | +$ docker-compose up --build |
| 29 | +``` |
| 30 | + |
| 31 | + The node js project will run on http://localhost:4080/ |
| 32 | + |
| 33 | + admin-mongo interface will be displayed on http://localhost:8082/ |
| 34 | + (this is deactivated by default. You need to uncomment lines in the docker-compose.yml to activate it) |
| 35 | + |
| 36 | + Internal Mongo DB connection string |
| 37 | + `mongodb://mongo/safetrace` |
| 38 | + |
| 39 | + External Mongo DB connection string (Robo3t) |
| 40 | + `mongodb://localhost:10975/safetrace` *In the docker-compose.yml file the port configuration is mapping the port 10975 to 27017 just to avoid expose the normal mongodb port.* |
| 41 | + |
| 42 | + .env file has some configurations |
| 43 | +- PORT: port where run nodejs |
| 44 | +- MONGOURI: path to access to mongoDB database (`mongodb://mongo/safetrace`) |
| 45 | +- GOOGLE_CLIENT_ID= client id path to register and validate users for Google sign up service. More innformation [here](https://developers.google.com/identity/sign-in/web/backend-auth). |
| 46 | + |
| 47 | +app/config/config.js |
| 48 | + - >secret: 'youSecretWord' |
| 49 | + - This configuration is used to encrypt the user id. It must be changed for every different app. *This is a temporary solution for the MVP version.* |
| 50 | + |
| 51 | +# Google Sign In integration |
| 52 | + |
| 53 | +## /user/glogin |
| 54 | + |
| 55 | +This endpoint registers new Google users if it don't exist. And logs in the user. It returns the internal token that you have to use for the next requests (header `x-access-token`) |
| 56 | + |
| 57 | +``` |
| 58 | +curl --location --request POST 'http://localhost:4080/user/glogin' \ |
| 59 | +--header 'Content-Type: application/json' \ |
| 60 | +--data-raw '{ |
| 61 | + "token": "eyJhbGciO0eXAiOi...LeLIU9ZMrVoCV2xA" |
| 62 | +}' |
| 63 | +``` |
| 64 | +**Returns** |
| 65 | + |
| 66 | +``` |
| 67 | +{ |
| 68 | + "token": "eyJhbGciOiJIUzI1NiIs...yiV2CNK12IVGESQ" |
| 69 | +} |
| 70 | +``` |
| 71 | + |
| 72 | +# JWT User endpoints |
| 73 | + |
| 74 | +## /user/signup |
| 75 | + |
| 76 | +``` |
| 77 | +curl --location --request POST 'https://localhost:4080/user/signup' \ |
| 78 | +--header 'Content-Type: application/json' \ |
| 79 | +--data-raw '{ |
| 80 | + "username": "username", |
| 81 | + |
| 82 | + "password": "yourpass", |
| 83 | + "agreeToBeNotified": true |
| 84 | +}' |
| 85 | +``` |
| 86 | +**Returns** |
| 87 | +``` |
| 88 | +{ |
| 89 | + "token": "eyJhbGciOiJIUzI1NiI....bJI7QTsgyM3Qk0" |
| 90 | +} |
| 91 | +``` |
| 92 | + |
| 93 | +## /user/login |
| 94 | + |
| 95 | +``` |
| 96 | +curl --location --request POST 'http://localhost:4080/user/login' \ |
| 97 | +--header 'Content-Type: application/json' \ |
| 98 | +--data-raw '{ |
| 99 | + |
| 100 | + "password": "yourpass" |
| 101 | +}' |
| 102 | +``` |
| 103 | +**Returns** |
| 104 | +``` |
| 105 | +{ |
| 106 | + "token": "eyJhbGciOiJIUzI1NiIs....R-sJ9iHNUde0" |
| 107 | +} |
| 108 | +``` |
| 109 | + |
| 110 | +## /user/me |
| 111 | + |
| 112 | +``` |
| 113 | +curl --location --request GET 'http://localhost:4080/user/me' \ |
| 114 | +--header 'x-access-token: eyJhbGci....blSXAPm0' |
| 115 | +
|
| 116 | +``` |
| 117 | +**Returns** |
| 118 | +``` |
| 119 | +{ |
| 120 | + "agreeToBeNotified": false, |
| 121 | + "userType": 1, |
| 122 | + "createdAt": "2020-04-02T10:16:12.090Z", |
| 123 | + "_id": "5e85bf05420bac7bcfece08f", |
| 124 | + "username": "username", |
| 125 | + |
| 126 | + "password": "$2a$10$21w/RANQMJoc2Ge6FpcSSOCpY1S2ae6li5dv5xNeQEzewphkneGcS", |
| 127 | + "idUser": 1, |
| 128 | + "encryptedUserId": "5f6451160f76aac8a02493787dc940a0057746c6401cc49757664ce1032b8450", |
| 129 | + "__v": 0 |
| 130 | +} |
| 131 | +``` |
| 132 | + |
| 133 | +`encryptedUserId` returns the encrypted email as user id. |
| 134 | + |
| 135 | +# Report |
| 136 | + |
| 137 | +## POST: /report |
| 138 | + |
| 139 | +This let to add a result test to the report table. |
| 140 | + |
| 141 | +``` |
| 142 | +curl --location --request POST 'http://localhost:4080/report' \ |
| 143 | +--header 'x-access-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjoiNWU4ODhhZDBlZGEwN2U2ZGFlYjY0ODBiIn0sImlhdCI6MTU4NjAxNjA2MiwiZXhwIjoxNTg2MDE5NjYyfQ.hmxFFAz1P80Yq4Q2iA6D8IpCOhI5_7xkfZYWDkQOHK4' \ |
| 144 | +--header 'Content-Type: application/json' \ |
| 145 | +--data-raw '{ |
| 146 | + "idUser": "'9365df4e9acef8b63b45dc3534491225ac32630abe6991f6bf5a74c9803412fc'", |
| 147 | + "testDate": "03/02/2020", |
| 148 | + "testResult": 0 |
| 149 | +}' |
| 150 | +``` |
| 151 | +**Returns** |
| 152 | + |
| 153 | +``` |
| 154 | +{ |
| 155 | + "report": { |
| 156 | + "createdAt": "2020-04-04T16:04:00.725Z", |
| 157 | + "_id": "5e88b01316714c664f5ef11e", |
| 158 | + "idUser": 1, |
| 159 | + "testDate": "2020-03-02T03:00:00.000Z", |
| 160 | + "testResult": 0, |
| 161 | + "idReport": 13, |
| 162 | + "__v": 0 |
| 163 | + } |
| 164 | +} |
| 165 | +``` |
| 166 | + |
| 167 | +## GET: /report/{idUser} |
| 168 | + |
| 169 | +Get the list of reported tests |
| 170 | + |
| 171 | + |
| 172 | +``` |
| 173 | +curl --location --request GET 'http://localhost:4080/report/9365df4e9acef8b63b45dc3534491225ac32630abe6991f6bf5a74c9803412fc' \ |
| 174 | +--header 'x-access-token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjoiNWU4ODhhZDBlZGEwN2U2ZGFlYjY0ODBiIn0sImlhdCI6MTU4NjI4Njg4MiwiZXhwIjoxNTg2MjkwNDgyfQ.zVNwkDZCXtlxRJnDhonptMxbgpngrB3T7cNIy8vde_I' |
| 175 | +``` |
| 176 | +**Returns** |
| 177 | + |
| 178 | +``` |
| 179 | +{ |
| 180 | + "reports": [ |
| 181 | + { |
| 182 | + "createdAt": "2020-04-07T19:24:31.388Z", |
| 183 | + "_id": "5e8cd38dc43d8007408e600d", |
| 184 | + "idUser": "9365df4e9acef8b63b45dc3534491225ac32630abe6991f6bf5a74c9803412fc", |
| 185 | + "testDate": "2020-03-04T03:00:00.000Z", |
| 186 | + "testResult": 1, |
| 187 | + "idReport": 17, |
| 188 | + "__v": 0 |
| 189 | + }, |
| 190 | + { |
| 191 | + ... |
| 192 | + } |
| 193 | + ] |
| 194 | +} |
| 195 | +``` |
| 196 | + |
| 197 | +## LICENSE |
| 198 | + |
| 199 | +The code in this repository is released under the [MIT License](https://github.com/cmalfesi/SafeTrace/blob/master/LICENSE). |
0 commit comments