This is the 8º tutorial of a complete series of building a production NodeJS API using Express, MySQL and Sequelize”.

Full source code of this class is available at GitHub Martial Arts API Part 8

Image for post
Image for post
Photo by Sarah Kilian on Unsplash

HANDLING ERROR

After all CRUD operation of the previous tutorial, we may have a way to show the user a meaningful error message if something bad happens. This message will be also useful for you as a programmer.

We are performing our request inside a try/catch block, therefore we will handle the error at catch

Here is an example for our getAll() method.


This is the 7º tutorial of a complete series of building a production NodeJS API using Express, MySQL and Sequelize”.

Full source code of this class is available at GitHub Martial Arts API Part 7

EDITING OUR ROUTE

First of all, we will simply edit our rote so it handle every case of CRUD (Create, Read, Read By Id, Update, Delete). Each request will call a specific method in our controller.

Image for post
Image for post

EDITING OUR CONTROLLER

Before editing our controller we just need to understand where the body, query, parameters and another…


This is the 6º tutorial of a complete series of building a production NodeJS API using Express, MySQL and Sequelize”.

Full source code of this class is available at GitHub Martial Arts API Part 6

Image for post
Image for post
Photo by Markus Winkler on Unsplash

SETTING UP MYSQL

Before starting, we will configure our MySQL database. As this is not a MySQL tutorial, we will not go deep on this subject, if you have any problems I suggest you to take a course or just google your error.


This is the 5º tutorial of a complete series of building a production NodeJS API using Express, MySQL and Sequelize”.

Full source code of this class is available at GitHub Martial Arts API Part 5

UNDERSTANDING THE PROBLEM

Our project is not too big, but we already have 36 lines and a single endpoint. In a real application where we could have +100 endpoints our app.js would be a really mess.

To avoid that we will structure our app in Models/Controllers/Routes. In the most informal way these will mean.

Image for post
Image for post
explanation of our model/router/controller structure

Model: A representation of our table columns.

Routes: This will tell…


This is the 4º tutorial of a complete series of building a production NodeJS API using Express, MySQL and Sequelize”.

Full source code of this class is available at GitHub Martial Arts API Part 4

This particular class is thanks to Academind Building a Restful API with NodeJS. Awesome teacher! :)

Image for post
Image for post
Photo by Joshua Ness on Unsplash

ADDING HEADER MIDDLEWARE

Another thing that will be great in our project is to add some configuration headers to our application. To do so, we need to add it using express middleware, otherwise, we would need to add the same headers to every single request.

CONCLUSION

If you want to go deeper on this subject I recommend you to watch Parsing the Body & Handling CORS | Creating a REST API with Node.js.

Full source code of this class is available at GitHub Martial Arts API Part 4


This is the 3º tutorial of a complete series of building a production NodeJS API using Express, MySQL and Sequelize”.

Full source code of this class is available at GitHub Martial Arts API Part 3

Image for post
Image for post
Photo by Eerik Sandstrom on Unsplash

UNDERSTANDING THE PROBLEM

As you could see in the past tutorials, if you type localhost:8000/dojos you will get a JSON Object with one dojo (gym).

But if you type localhost:8000/ , localhost:8000/students or any other endpoint you will not get a meaningfull response.

It would be good to send Not Found to the user in case he typed something we do not support, for that we are going…


This is the 2º tutorial of a complete series of building a production NodeJS API using Express, MySQL and Sequelize”.

Full source code of this class is available at GitHub Martial Arts API Part 2

Image for post
Image for post
Photo by Bermix Studio on Unsplash

RETURNING SOME JSON DATA

Now we will return some data in our server, for that you just need to modify a bit your app.js file so it will look like this.


This is the 1º tutorial of a complete series of building a production NodeJS API using Express, MySQL and Sequelize”.

Full source code of this class is available at GitHub Martial Arts API Part 1

Image for post
Image for post
Photo by Serghei Trofimov on Unsplash

Before we begin you should install the following things on your computer.

NOTE: This tutorial will cover all the API being built based…


Image for post
Image for post
Photo by Carlos Muza on Unsplash

Incluir exportação para o Excel no seu software é uma máquina muito poderosa e rápida. Para o seu cliente que gosta de Excel é só ele exportar e continuar trabalhando por lá se quiser acrescentar algo.

Direto para o Código

No código vou utilizar TFDQuery e TDBGrid porém você pode fazer o mesmo com qualquer TClientDataSet ou outra maneira que você está utlizando.

1. Uses clauses

A principais uses clauses são:

uses
System.Win.ComObj, Vcl.DBGrids, FireDAC.Comp.Client, Datasnap.DBClient ...;

2. Criar o Objeto

Esse código cria o Objeto Excel.Application e adiciona a primeira página do excel.

procedure GerarExcel(AQuery: TFDQuery)…

Image for post
Image for post
Photo by Taylor Vick on Unsplash

Imagina você estar fazendo uma migração de dados em MySQL e descobrir que 10.000 dados não estão com CPF, CNPJ formatados em suas respectivas mask.

Não há problema algum em armazenar os dados com ou sem mask, depende da preferência do programador. No meu caso ficou mais fácil já armazenar o CPF e CNPJ com a mask, porém em uma migração descobri que o sistema antigo fazia o contrário e por isso tive que executar alguns códigos para realizar essa formatação.

No nosso exemplo vamos trabalhar com a table pessoas.

Essa table possui o campo cpf e cnpj.

Para formatar a mask do CPF:

UPDATE pessoas…

Soon Sam Santos

Flutter and Delphi Developer at Green. Teacher at SoonClass

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store