-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Authentication is implemented using JWTs. When a user enters their credentials, a token is sent back to them, and it's the user's (client) responsibility to include it inside the Authorization
header on subsequent requests. This token will be referenced as jwt_token
from now on.
Authenticates user with provided credentials.
POST /users/sign_in
Accept: application/json
Content-Type: application/json
Name | Type | Description |
---|---|---|
user | object |
required An object containing the sign in credentials. Keys and values of this object are described below |
string |
required Email of the user. It should be included inside the user object |
|
password | string |
required Password of the user. It should be included inside the user object |
{"user": { "email": "[email protected]", "password": "some-password" } }
200
{
"id": 1,
"email": "[email protected]",
"created_at": "2019-11-15T20:04:53.321Z",
"updated_at": "2019-11-15T20:04:53.321Z",
"name": "User name",
"position": "Some position or null",
"role": "some-role"
}
Leaves the user unauthenticated.
DELETE /users/sign_out
Accept: application/json
Authorization: Bearer jwt_token
204
Fetches report corresponding to the authenticated user. If no report exists, worked days for the last month are returned.
GET /users/report
Accept: application/json
Authorization: Bearer jwt_token
200
[
{
"id": 1,
"day": "2019-10-14",
"arrived_at": "2019-10-14T09:56:00.000Z",
"left_at": "2019-10-14T17:48:00.000Z"
},
{
"id": 2,
"day": "2019-10-15",
"arrived_at": "2019-10-15T09:56:00.000Z",
"left_at": "2019-10-15T17:48:00.000Z"
},
...
]
The following endpoints are accesible only by administrator users. This is accomplished using the role associated to a user.
The following endpoints allow to manage users inside the platform.
Fetches list of all users.
GET /admin/users
Accept: application/json
Authorization: Bearer jwt_token
200
[
{
"id": 1,
"email": "[email protected]",
"name": "User name 1",
"position": "Some position or null",
"role": "some-role",
"created_at": "2019-11-15T20:04:53.321Z",
"updated_at": "2019-11-15T20:04:53.321Z",
"url": "http://localhost:3000/admin/users/1"
},
{
"id": 2,
"email": "[email protected]",
"name": "User name 2",
"position": "Some position or null",
"role": "some-role",
"created_at": "2019-11-15T20:04:53.321Z",
"updated_at": "2019-11-15T20:04:53.321Z",
"url": "http://localhost:3000/admin/users/2"
},
...
]
Fetches a particular user.
GET /admin/users/:id
Accept: application/json
Authorization: Bearer jwt_token
Name | Type | Description |
---|---|---|
id | number | A number representing the id of the user |
200
{
"id": 1,
"email": "[email protected]",
"name": "User name 1",
"position": "Some position or null",
"role": "some-role",
"created_at": "2019-11-15T20:04:53.321Z",
"updated_at": "2019-11-15T20:04:53.321Z",
"url": "http://localhost:3000/admin/users/1"
}
Creates a new user.
POST /admin/users
Accept: application/json
Content-Type: application/json
Authorization: Bearer jwt_token
Name | Type | Description |
---|---|---|
user | object |
required An object containing the new user data. Keys and values of this object are described below |
string |
required Email of the user. It should be included inside the user object |
|
password | string |
required Password of the user. It should be included inside the user object |
name | string |
required Name of the user. It should be included inside the user object |
position | string | Position associated to the user. It should be included inside the user object |
role | string | Role of the user. It has two possible values: "employee" or "admin" . Defaults to "employee" . It should be included inside the user object |
{"user": { "email": "[email protected]", "password": "some-password", "name": "Some name", "position": "Some position", "role": "some-role" } }
201
{
"id": 2,
"email": "[email protected]",
"name": "Some name",
"position": "Some position",
"role": "some-role",
"created_at": "2019-11-15T20:04:53.321Z",
"updated_at": "2019-11-15T20:04:53.321Z",
"url": "http://localhost:3000/admin/users/2"
}
Updates an existing user.
PATCH /admin/users/:id
Accept: application/json
Content-Type: application/json
Authorization: Bearer jwt_token
Name | Type | Description |
---|---|---|
id | number | A number representing the id of the user |
Name | Type | Description |
---|---|---|
user | object |
required An object containing the user data that needs to be updated. Keys and values of this object are described below |
string | Email of the user. It should be included inside the user object |
|
password | string | Password of the user. It should be included inside the user object |
name | string | Name of the user. It should be included inside the user object |
position | string | Position associated to the user. It should be included inside the user object |
role | string | Role of the user. It has two possible values: "employee" or "admin" . Defaults to "employee" . It should be included inside the user object |
{"user": { "email": "[email protected]" } }
Note: Parameters omitted inside the body will be ignored when updating the user.
200
{
"id": 2,
"email": "[email protected]",
"name": "Some name",
"position": "Some position",
"role": "some-role",
"created_at": "2019-11-15T20:04:53.321Z",
"updated_at": "2019-11-15T20:04:53.321Z",
"url": "http://localhost:3000/admin/users/2"
}
Deletes an existing user.
DELETE /admin/users/:id
Accept: application/json
Authorization: Bearer jwt_token
Name | Type | Description |
---|---|---|
id | number | A number representing the id of the user |
204
Work days are in charge of specifying the date and times of a worked day for an employee. Therefore, these work days are always associated to a user. For that reason, each of the following endpoints include the user inside the URL.
Fetches list of work days for a user.
GET /admin/users/:user_id/work_days
Accept: application/json
Authorization: Bearer jwt_token
Name | Type | Description |
---|---|---|
user_id | number | A number representing the id of the user |
200
[
{
"id": 32,
"day": "2019-10-14",
"arrived_at": "2019-10-14T09:56:00.000Z",
"left_at": "2019-10-14T17:48:00.000Z",
"created_at": "2019-10-15T17:48:00.000Z",
"updated_at": "2019-10-15T17:48:00.000Z",
"url": "http://localhost:3000/admin/users/2/work_days/32",
"human_url": "http://localhost:3000/admin/users/2/work_days/2019-10-14"
},
{
"id": 33,
"day": "2019-10-15",
"arrived_at": "2019-10-15T09:56:00.000Z",
"left_at": "2019-10-15T17:48:00.000Z",
"created_at": "2019-10-15T17:48:00.000Z",
"updated_at": "2019-10-15T17:48:00.000Z",
"url": "http://localhost:3000/admin/users/2/work_days/33",
"human_url": "http://localhost:3000/admin/users/2/work_days/2019-10-15"
},
...
]
Fetches a particular work day for a user.
GET /admin/users/:user_id/work_days/:id_or_day
Accept: application/json
Authorization: Bearer jwt_token
Name | Type | Description |
---|---|---|
user_id | number | A number representing the id of the user |
id_or_day | string | A number representing the id of the user or a string with the day in YYYY-MM-DD format |
200
{
"id": 33,
"day": "2019-10-15",
"arrived_at": "2019-10-15T09:56:00.000Z",
"left_at": "2019-10-15T17:48:00.000Z",
"created_at": "2019-10-15T17:48:00.000Z",
"updated_at": "2019-10-15T17:48:00.000Z",
"url": "http://localhost:3000/admin/users/2/work_days/33",
"human_url": "http://localhost:3000/admin/users/2/work_days/2019-10-15"
}
Creates a new work day for a user.
POST /admin/users/:user_id/work_days
Accept: application/json
Content-Type: application/json
Authorization: Bearer jwt_token
Name | Type | Description |
---|---|---|
user_id | number | A number representing the id of the user |
Name | Type | Description |
---|---|---|
work_day | object |
required An object containing the new work day data. Keys and values of this object are described below |
day | string |
required The day in YYYY-MM-DD format. It should be included inside the work_day object |
arrived_at | string | The datetime of the arrival of the employee, in YYYY-MM-DD HH:mm:ss format. It should be included inside the work_day object |
left_at | string | The datetime when the employee left, in YYYY-MM-DD HH:mm:ss format. It should be included inside the work_day object |
{"work_day": { "day": "2019-11-16", "arrived_at": "2019-11-16 09:00:05", "left_at": "2019-11-16 18:58:23" } }
201
{
"id": 66,
"day": "2019-11-16",
"arrived_at": "2019-11-16T09:00:05.000Z",
"left_at": "2019-11-16T18:58:23.000Z",
"created_at": "2019-11-16T00:32:11.990Z",
"updated_at": "2019-11-16T00:32:11.990Z",
"url": "http://localhost:3000/admin/users/2/work_days/66",
"human_url": "http://localhost:3000/admin/users/2/work_days/2019-11-16"
}
Updates an existing work day for a user.
PATCH /admin/users/:user_id/work_days/:id_or_day
Accept: application/json
Content-Type: application/json
Authorization: Bearer jwt_token
Name | Type | Description |
---|---|---|
user_id | number | A number representing the id of the user |
id_or_day | string | A number representing the id of the user or a string with the day in YYYY-MM-DD format |
Name | Type | Description |
---|---|---|
work_day | object |
required An object containing the work day data that needs to be updated. Keys and values of this object are described below |
day | string | The day in YYYY-MM-DD format. It should be included inside the work_day object |
arrived_at | string | The datetime of the arrival of the employee, in YYYY-MM-DD HH:mm:ss format. It should be included inside the work_day object |
left_at | string | The datetime when the employee left, in YYYY-MM-DD HH:mm:ss format. It should be included inside the work_day object |
{"work_day": { "left_at": "2019-11-06 17:30:00" } }
Note: Parameters omitted inside the body will be ignored when updating the work day.
200
{
"id": 66,
"day": "2019-11-16",
"arrived_at": "2019-11-16T09:00:05.000Z",
"left_at": "2019-11-16T17:30:00.000Z",
"created_at": "2019-11-16T00:32:11.990Z",
"updated_at": "2019-11-16T00:32:11.990Z",
"url": "http://localhost:3000/admin/users/2/work_days/66",
"human_url": "http://localhost:3000/admin/users/2/work_days/2019-11-16"
}
Deletes an existing work day of a user.
DELETE /admin/users/:user_id/work_days/:id_or_day
Accept: application/json
Authorization: Bearer jwt_token
Name | Type | Description |
---|---|---|
user_id | number | A number representing the id of the user |
id_or_day | string | A number representing the id of the user or a string with the day in YYYY-MM-DD format |
204
A report is always associated to a user. For that reason, each of the following endpoints include the user inside the URL.
Fetches the report associated to a user. It includes the work days in the range of dates specified by the report. If no report exists, worked days for the last month are returned.
GET /admin/users/:user_id/report
Accept: application/json
Authorization: Bearer jwt_token
Name | Type | Description |
---|---|---|
user_id | number | A number representing the id of the user |
200
{
"id": 1,
"start_date": "2019-10-01",
"end_date": "2019-10-20",
"created_at": "2019-11-15T20:04:53.387Z",
"updated_at": "2019-11-15T20:04:53.387Z",
"url": "http://localhost:3000/admin/users/2/report",
"work_days": [
{
"id": 32,
"day": "2019-10-14",
"arrived_at": "2019-10-14T09:56:00.000Z",
"left_at": "2019-10-14T17:48:00.000Z",
"created_at": "2019-10-15T17:48:00.000Z",
"updated_at": "2019-10-15T17:48:00.000Z",
"url": "http://localhost:3000/admin/users/2/work_days/32",
"human_url": "http://localhost:3000/admin/users/2/work_days/2019-10-14"
},
{
"id": 33,
"day": "2019-10-15",
"arrived_at": "2019-10-15T09:56:00.000Z",
"left_at": "2019-10-15T17:48:00.000Z",
"created_at": "2019-10-15T17:48:00.000Z",
"updated_at": "2019-10-15T17:48:00.000Z",
"url": "http://localhost:3000/admin/users/2/work_days/33",
"human_url": "http://localhost:3000/admin/users/2/work_days/2019-10-15"
},
...
]
}
Creates a new report for a user. It there was a report previously created, it returns that report (does not replace it).
POST /admin/users/:user_id/report
Accept: application/json
Content-Type: application/json
Authorization: Bearer jwt_token
Name | Type | Description |
---|---|---|
user_id | number | A number representing the id of the user |
Name | Type | Description |
---|---|---|
report | object |
required An object containing the new report data. Keys and values of this object are described below |
start_date | string |
required The start date in YYYY-MM-DD format. It should be included inside the report object |
end_date | string |
required The end date in YYYY-MM-DD format. It should be included inside the report object |
{"report": { "start_date": "2019-11-12", "end_date": "2019-11-14" } }
201
{
"id": 2,
"start_date": "2019-11-12",
"end_date": "2019-11-14",
"created_at": "2019-11-15T20:04:53.387Z",
"updated_at": "2019-11-15T20:04:53.387Z",
"url": "http://localhost:3000/admin/users/2/report",
"work_days": [
{
"id": 52,
"day": "2019-11-12",
"arrived_at": "2019-11-12T09:56:00.000Z",
"left_at": "2019-11-12T17:48:00.000Z",
"created_at": "2019-10-15T17:48:00.000Z",
"updated_at": "2019-10-15T17:48:00.000Z",
"url": "http://localhost:3000/admin/users/2/work_days/52",
"human_url": "http://localhost:3000/admin/users/2/work_days/2019-11-12"
},
{
"id": 53,
"day": "2019-11-13",
"arrived_at": "2019-11-13T09:56:00.000Z",
"left_at": "2019-11-13T17:48:00.000Z",
"created_at": "2019-10-15T17:48:00.000Z",
"updated_at": "2019-10-15T17:48:00.000Z",
"url": "http://localhost:3000/admin/users/2/work_days/53",
"human_url": "http://localhost:3000/admin/users/2/work_days/2019-11-13"
},
...
]
}
Updates an existing report associated to a user
PATCH /admin/users/:user_id/report
Accept: application/json
Content-Type: application/json
Authorization: Bearer jwt_token
Name | Type | Description |
---|---|---|
user_id | number | A number representing the id of the user |
Name | Type | Description |
---|---|---|
report | object |
required An object containing the report data that needs to be updated. Keys and values of this object are described below |
start_date | string | The start date in YYYY-MM-DD format. It should be included inside the report object |
end_date | string | The end date in YYYY-MM-DD format. It should be included inside the report object |
{"report": { "start_date": "2019-11-13" } }
Note: Parameters omitted inside the body will be ignored when updating the report.
200
{
"id": 2,
"start_date": "2019-11-13",
"end_date": "2019-11-14",
"created_at": "2019-11-15T20:04:53.387Z",
"updated_at": "2019-11-15T20:04:53.387Z",
"url": "http://localhost:3000/admin/users/2/report",
"work_days": [
{
"id": 53,
"day": "2019-11-13",
"arrived_at": "2019-11-13T09:56:00.000Z",
"left_at": "2019-11-13T17:48:00.000Z",
"created_at": "2019-10-15T17:48:00.000Z",
"updated_at": "2019-10-15T17:48:00.000Z",
"url": "http://localhost:3000/admin/users/2/work_days/53",
"human_url": "http://localhost:3000/admin/users/2/work_days/2019-11-13"
},
...
]
}
Deletes an existing report associated to a user.
DELETE /admin/users/:user_id/report
Accept: application/json
Authorization: Bearer jwt_token
Name | Type | Description |
---|---|---|
user_id | number | A number representing the id of the user |
204
When something wrong happens with a request, an error object is returned. Depending on the type of error, the object can be one of three:
- Object with
error
key, string value with error details - Object with
errors
key, array value containing elements with error details - Object with generic keys, array values with error details
Note: Part of future work is to standardize errors.
The following categories of errors can occur:
It happens when the user is not authenticated.
401
{
"error": "You need to sign in before continuing."
}
It happens when the user is not authorized to request the resource.
403
{
"errors": [
{
"status": 403,
"title": "Forbidden",
"message": "You are not authorized to access this resource."
}
]
}
It happens when the requested resource could not be found.
404
{
"errors": [
{
"status": 404,
"title": "Record not Found",
"message": "We could not find the object you were looking for."
}
]
}
It happens when there is data validation error.
422
{
"some_field": [
"is not valid data"
]
}
Any error not covered by previous errors is considered a server error.
500
{
"errors": [
{
"status": 500,
"title": "Something went wrong",
"message": "We encountered unexpected error"
}
]
}