Use JSON file format for your requests' body
To authenricate this use JSON web token.
Simply add this to your headers and you will be able to use any routes.
Authorization : Bearer {TOKEN}
To get the token you need to make a POST request on /auth/register with fields
| Name | Type | Required |
|---|---|---|
| login | string | + |
| password | string | + |
Be aware that login mist be unique
Sample response
{
"message": "You are succesfully registered. Please login to get your JWT"
}Than POST /auth/login with the same fields and you will get a token.
Sample response
{
"token": "TOKEN",
"user": {
"user_id": "ID",
"iat": 1580301086,
"exp": 1582893086
}
}Sample not found error
data[property] = value;
return {
message: `${entity} with such ${property} is not found`,
data,
}; GET /student/some_id
{
"message": "Student with such id is not found",
"data": {
"id": "some_id"
}
}Error handler
const status = err.status || 500;
res.status(status);
res.json({
status,
error: {
message: err.message,
},
});For each entity there is at least 4 routes to interact with
| Method | Route | Description |
|---|---|---|
GET |
/{entityName}/search |
Finds entities with parameters needed. All params have to be included in request query. limit and offset are optoinal. Default ones are 10 and 0 accordingly |
GET |
/{entityName}/:id |
Finds the entity by id and returns it |
DELETE |
/{entityName}/:id |
Deletes the entity by id and returns it |
PUT |
/{entityName}/:id |
Updates the entity by id and returns it. For each entity you can not update certain fields. More about it further |
POST |
/{entityName}/new |
Create new entity |
Sample search example
GET /student/search/?name=an
{
"count": 1,
"students": [
{
"group": "QAXzfRHb",
"_id": "A5mca8tj",
"name": "anrii koval"
}
]
}Sample getting group by id
GET /group/GW_GzGea
{
"group": {
"students": [
{
"group": "GW_GzGea",
"_id": "w2bTKGgI",
"name": "newName"
}
],
"_id": "GW_GzGea",
"name": "newName",
"specialisationCode": 121
}
}Note that required fields have to be submited in request for creating a new entity
| Property | Type | Required |
|---|---|---|
| name | String |
+ |
| teacher | String(id) |
+ |
| groups | String(id)[] |
- |
| place | String |
- |
| indexNumber | Int |
- |
| Property | Type | Required |
|---|---|---|
| name | String |
+ |
| students | String(id)[] |
+ |
| specialisationCode | Int |
+ |
Note that name value shiuld be unique for each group
| Property | Type | Required |
|---|---|---|
| name | String |
+ |
| group | String(id) |
- |
| Property | Type | Required |
|---|---|---|
| name | String |
+ |
| salary | Int |
+ |
| worksSince | Date |
- |
Editing _id value for any entity is forbidden
Editing group property for student and students for group is foebidden. Use additional route for group.
| Method | Route | Description |
|---|---|---|
POST |
/group/:id/addStudents |
Add students to group |
POST |
/group/:id/removeStudents |
Remove students from group |
In request body provide the list of students' ids than you want to add/remove
| Property | Type | Required |
|---|---|---|
| students | String(id)[] |
+ |