🚧 Project under construction 🚧
This project is a example of an API for a English school. The database schema is shown below:
Install dependencies
Run server
in server's folder:
Method
Route
Description
BODY PARAMS
QUERY PARAMS
GET
/people
Return a list of all people
-
-
Method
Route
Description
BODY PARAMS
QUERY PARAMS
POST
/people
Store a person
{ "name": "Pedro", "active": true, "email": "testando@teste.com.br ", "role": "aluno" }
-
Name
Type
Description
name
string
required
active
boolean
required
email
string
required
role
string
required
Method
Route
Description
BODY PARAMS
QUERY PARAMS
GET
/person/{id}
Return a person's information by id
-
-
Method
Route
Description
BODY PARAMS
QUERY PARAMS
PUT
/person/{id}
Update a person's information by id
{ "name": "Pedro", "active": true, "email": "testando@teste.com.br ", "role": "aluno" }
-
Name
Type
Description
name
string
required
active
boolean
required
email
string
required
role
string
required
Method
Route
Description
BODY PARAMS
QUERY PARAMS
DELETE
/people/{id}
Delete a person by id
-
-
Method
Route
Description
BODY PARAMS
QUERY PARAMS
GET
/levels
Return a list of all levels
-
-
Method
Route
Description
BODY PARAMS
QUERY PARAMS
POST
/levels
Store a level
{ "description": "basic" }
-
Name
Type
Description
description
string
required
Method
Route
Description
BODY PARAMS
QUERY PARAMS
GET
/levels/{id}
Return the level's information by id
-
-
Method
Route
Description
BODY PARAMS
QUERY PARAMS
PUT
/levels/{id}
Update the levels's information by id
{ "description": "master" }
-
Name
Type
Description
description
string
required
Method
Route
Description
BODY PARAMS
QUERY PARAMS
DELETE
/levels/{id}
Delete a level by id
-
-
Method
Route
Description
BODY PARAMS
QUERY PARAMS
GET
/classes
Return a list of all classes
-
-
Method
Route
Description
BODY PARAMS
QUERY PARAMS
POST
/classes
Store a class
{ "start_date": "2023-07-01", "teacher_id": 6, "level_id": 1 }
-
Name
Type
Description
start_date
string "Y-m-d"
required
teacher_id
integer
required
level_id
integer
required
Method
Route
Description
BODY PARAMS
QUERY PARAMS
GET
/classes/{id}
Return the class's information by id
-
-
Method
Route
Description
BODY PARAMS
QUERY PARAMS
PUT
/classes/{id}
Update the levels's information by id
{ "start_date": "2023-07-01", "teacher_id": 6, "level_id": 1 }
-
Name
Type
Description
start_date
string "Y-m-d"
required
teacher_id
integer
required
level_id
integer
required
Method
Route
Description
BODY PARAMS
QUERY PARAMS
DELETE
/classes/{id}
Delete a class by id
-
-
4.1. Get a enrollment of a person
Method
Route
Description
BODY PARAMS
QUERY PARAMS
GET
/people/{person_id}/enrollments/{enrollment_id}
Return the enrollment's information of a person
-
-
Method
Route
Description
BODY PARAMS
QUERY PARAMS
POST
/{person_id}/enrollments
Store a enrollment for a person
{ "status" : "confirmed" ,"class_id": 4 }
-
Name
Type
Description
status
string
required
class_id
integer
required
4.3 Update a enrollment of a person
Method
Route
Description
BODY PARAMS
QUERY PARAMS
PUT
/{person_id}/enrollments/{enrollment_id}
Update the enrollment's information of a person by id
{ "status" : "confirmed" ,"class_id": 4 }
-
Name
Type
Description
status
string
required
class_id
integer
required
4.4 Delete a enrollment of a person
Method
Route
Description
BODY PARAMS
QUERY PARAMS
DELETE
/{person_id}/enrollments/{enrollment_id}
Delete a enrollment of a person by id
-
-
Getting started with Node.js
Installing Nodemon Library
npm install sequelize sequelize-cli path
Creating file .sequelizerc
https://sequelize.org/docs/v6/other-topics/migrations/#the-sequelizerc-file
npx sequelize-cli model:generate --name People --attributes name:string,active:boolean,email:string,role:string
npx sequelize-cli db:migrate
Creating migration to add a colunm
npx sequelize-cli migration:create --name modify_users_add_new_fields
npx sequelize-cli seed:generate --name people
npx sequelize-cli db:seed:all
In People's Model:
defaultScope: {
where: {
active: true,
}
}
scopes: {
all: {
where: {}
}
},
In the model:
People.init({
name: DataTypes.STRING,
active: DataTypes.BOOLEAN,
email: {
type: DataTypes.STRING,
validate: {
isEmail: {
args: true,
msg: 'Invalid E-mail'
}
}
},
role: DataTypes.STRING
}
name: {
type: DataTypes.STRING,
validate: {
validateFunction: function(data) {
if (data.length < 3) throw new Error('Name must have more than 3 characters.')
}
}
}