|
| 1 | +## User.js |
| 2 | + |
| 3 | +## Routes available |
| 4 | + |
| 5 | +The following routes are available for the ```Computer``` resource. They are all prefixed by ```/api/v1/computer```. |
| 6 | + |
| 7 | +| Methods | Path | Authentication | Description | |
| 8 | +| --- | --- | --- | --- | |
| 9 | +| `POST` | '/new' | Admin Required | Add a new computer to the system | |
| 10 | +| `GET` | '/' | Required | Gets all the computers registered in the system | |
| 11 | +| `PUT` | '/deactivate' | Admin Required | Deactivate the computer so that it is not accessible | |
| 12 | +| `PUT` | '/reactivate' | Admin Required | Reactivate the computer so that it can be accessible | |
| 13 | +| `Delete` | '/unregister' | Admin Required | Remove the computer from the system | |
| 14 | + |
| 15 | +## #create() |
| 16 | + |
| 17 | +This method creates a new computer in the database |
| 18 | + |
| 19 | +**Usage** |
| 20 | +```javascript |
| 21 | + const axios = require('axios') |
| 22 | + |
| 23 | + const res = await axios.post('/api/v1/computers/new', { |
| 24 | + name: 'computer3' |
| 25 | + }) |
| 26 | + |
| 27 | + console.log(res.data) |
| 28 | +``` |
| 29 | + |
| 30 | +> The responses below are just a demo to show the keys that the response object may have |
| 31 | +### Success response |
| 32 | + |
| 33 | +```json |
| 34 | +{ |
| 35 | + "message": "successfully created computer.", |
| 36 | + "computer": { |
| 37 | + "name": "computer3", |
| 38 | + "active": true, |
| 39 | + "created_at": "2018-01-12T16:25:11.893Z" |
| 40 | + } |
| 41 | +} |
| 42 | +``` |
| 43 | + |
| 44 | +### Error response |
| 45 | + |
| 46 | +**If no token is provided** |
| 47 | +```json |
| 48 | +{ |
| 49 | + "message": "No token provided." |
| 50 | +} |
| 51 | +``` |
| 52 | + |
| 53 | +**validation errors** |
| 54 | +```json |
| 55 | +{ |
| 56 | + "message": "Validation errors occured", |
| 57 | + "error": { |
| 58 | + "message": "Validation errors occured", |
| 59 | + "errors": [ |
| 60 | + { |
| 61 | + "message": "\"name\" is required", |
| 62 | + "path": "name", |
| 63 | + "type": "any.required", |
| 64 | + "context": { |
| 65 | + "key": "name" |
| 66 | + } |
| 67 | + } |
| 68 | + ], |
| 69 | + "status": 400 |
| 70 | + } |
| 71 | +} |
| 72 | +``` |
| 73 | +--- |
| 74 | +## #getAllComputers() |
| 75 | + |
| 76 | +Returns all the computers in the databse |
| 77 | + |
| 78 | +**Usage** |
| 79 | +```javascript |
| 80 | + const axios = require('axios') |
| 81 | + |
| 82 | + const res = await axios.post('/api/v1/computers') |
| 83 | + |
| 84 | + console.log(res) |
| 85 | +``` |
| 86 | + |
| 87 | +> The responses below are just a demo to show the keys that the response object may have |
| 88 | +### Success response |
| 89 | + |
| 90 | +```js |
| 91 | +{ |
| 92 | + "computers": [ |
| 93 | + { |
| 94 | + "name": "computer1", |
| 95 | + "active": true, |
| 96 | + "created_at": "2018-01-12T15:56:42.181Z", |
| 97 | + "username": "garikai", |
| 98 | + "login_time": "18:15:41", |
| 99 | + "login_date": "2018-01-12T18:15:41.522+02:00", |
| 100 | + "computer_name": "computer1", |
| 101 | + "status": "in_use" |
| 102 | + }, |
| 103 | + { |
| 104 | + "name": "computer3", |
| 105 | + "active": true, |
| 106 | + "created_at": "2018-01-12T16:25:11.893Z", |
| 107 | + "username": null, |
| 108 | + "login_time": null, |
| 109 | + "login_date": null, |
| 110 | + "computer_name": null, |
| 111 | + "status": "available" |
| 112 | + } |
| 113 | + ] |
| 114 | +} |
| 115 | +``` |
| 116 | + |
| 117 | +### Error response |
| 118 | + |
| 119 | +**If no token is provided** |
| 120 | +```json |
| 121 | +{ |
| 122 | + "message": "No token provided." |
| 123 | +} |
| 124 | +``` |
| 125 | +--- |
| 126 | + |
| 127 | +## #deactivate() |
| 128 | + |
| 129 | +Deactivate the computer so that it is not accessible |
| 130 | + |
| 131 | +**Usage** |
| 132 | +```javascript |
| 133 | + const axios = require('axios') |
| 134 | + |
| 135 | + const res = await axios.put('/api/v1/computers/deactivate', { |
| 136 | + name: 'computer3' |
| 137 | + }) |
| 138 | + |
| 139 | + console.log(res.data) |
| 140 | +``` |
| 141 | + |
| 142 | +> The responses below are just a demo to show the keys that the response object may have |
| 143 | +### Success response |
| 144 | + |
| 145 | +```json |
| 146 | +{ |
| 147 | + "message": "successfully deactivated computer." |
| 148 | +} |
| 149 | +``` |
| 150 | + |
| 151 | +### Error response |
| 152 | + |
| 153 | +**If no token is provided** |
| 154 | +```json |
| 155 | +{ |
| 156 | + "message": "No token provided." |
| 157 | +} |
| 158 | +``` |
| 159 | +--- |
| 160 | + |
| 161 | + |
| 162 | +## #reactivate() |
| 163 | + |
| 164 | +Deactivate the computer so that it is not accessible |
| 165 | + |
| 166 | +**Usage** |
| 167 | +```javascript |
| 168 | + const axios = require('axios') |
| 169 | + |
| 170 | + const res = await axios.put('/api/v1/computers/reactivate', { |
| 171 | + name: 'computer3' |
| 172 | + }) |
| 173 | + |
| 174 | + console.log(res.data) |
| 175 | +``` |
| 176 | + |
| 177 | +> The responses below are just a demo to show the keys that the response object may have |
| 178 | +### Success response |
| 179 | + |
| 180 | +```json |
| 181 | +{ |
| 182 | + "message": "successfully reactivated computer." |
| 183 | +} |
| 184 | +``` |
| 185 | + |
| 186 | +### Error response |
| 187 | + |
| 188 | +**If no token is provided** |
| 189 | +```json |
| 190 | +{ |
| 191 | + "message": "No token provided." |
| 192 | +} |
| 193 | +``` |
| 194 | +--- |
| 195 | + |
| 196 | + |
| 197 | +## #unregister() |
| 198 | + |
| 199 | +Deactivate the computer so that it is not accessible |
| 200 | + |
| 201 | +**Usage** |
| 202 | +```javascript |
| 203 | + const axios = require('axios') |
| 204 | + |
| 205 | + const res = await axios.delete('/api/v1/computers/unregister', { |
| 206 | + name: 'computer3' |
| 207 | + }) |
| 208 | + |
| 209 | + console.log(res.data) |
| 210 | +``` |
| 211 | + |
| 212 | +> The responses below are just a demo to show the keys that the response object may have |
| 213 | +### Success response |
| 214 | + |
| 215 | +```json |
| 216 | +{ |
| 217 | + "message": "successfully unregistered computer." |
| 218 | +} |
| 219 | +``` |
| 220 | + |
| 221 | +### Error response |
| 222 | + |
| 223 | +**If no token is provided** |
| 224 | +```json |
| 225 | +{ |
| 226 | + "message": "No token provided." |
| 227 | +} |
| 228 | +``` |
| 229 | +--- |
0 commit comments