๐This API was built using MySQL as the database, Express as the server framework, Sequelize as the ORM, and Jest for conducting unit tests. It provides functionality to create suppliers, load invitations from a CSV file, and retrieve a list of existing invitations ๐๏ธ.
- Node-Typescript
- Express
- MySQL
Postman https://www.postman.com/downloads/
- To get a local copy up and running follow these steps.
- Clone the repository:
- git clone https://github.com/Pipe1098/Valee-challenge-tc.git
Before running the server, you need to set up the database connection. Open the db.ts file in the config folder and modify the following line to connect to your MySQL database:
const sequelize = new Sequelize("your_database_name", "your_username", "your_password", {
host: "your_database_host",
port: 3306,
dialect: "mysql",
});
Replace "your_database_name", "your_username", "your_password", and "your_database_host" with your actual MySQL database credentials.
Create the supplier table:
CREATE TABLE supplier (
id bigint(20) NOT NULL AUTO_INCREMENT,
name varchar(256) NOT NULL,
code varchar(45) DEFAULT NULL,
is_active bit(1) DEFAULT b'1',
entry_date datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id)
);
Create the supplier_invitation table along with the foreign key reference to the supplier table:
CREATE TABLE supplier_invitation (
id bigint(20) NOT NULL AUTO_INCREMENT,
supplier_id bigint(20) DEFAULT NULL,
commerce_cell_phone varchar(256) DEFAULT NULL,
entry_date datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
FOREIGN KEY (supplier_id) REFERENCES supplier (id)
);
npm install
npm run build
npm run start
or
npm run dev
- you can use postman to test the following enpoints:
โ๏ธ๐ Endpoint: POST /URL: http://localhost:3000/api/v1/invitations
Request Type: POST
Endpoint: /invitation/csv
Request Headers:
Content-Type: multipart/form-data
Accept: application/json
-
Request Body: File CSV: Upload a CSV file containing the invitations (prueba.csv).
-
Response: Status Code: 200 (OK)
-
Example Response:
{
"code": 0,
"message": "Invitations loaded successfully"
}
๐งโ๐ผ Endpoint: POST /URL: http://localhost:3000/api/v1/suppliers:
Method: POST
Request Header:
Summary: Create a new supplier.
Description: This endpoint allows you to create a new supplier and store it in the database.
Parameters: JSON object containing supplier details (name, code).
Request Body:
{
"name": "company2",
"code": "PROV147"
}
- Example Response: Status: 201 Created Body:
{
"id": 1,
"name": "company2",
"code": "PROV147",
"isActive": true,
"entryDate": "2023-07-27T12:34:56.000Z"
}
๐๏ธ๐ฉ Endpoint: GET /URL: http://localhost:3000/api/v1/invitations
Request Type: GET
Request Headers:
Accept: application/json
Status: 200 OK
Example Response:
{
"apiResponse": {
"code": 0,
"message": "OK"
},
"list": [
{
"supplierId": 1,
"supplierName": "company2",
"commerceCellPhone": "+123456789012"
}
]
}
npm run test
Contributions are welcome! Please feel free to open a pull request.