Best way to validate your mongo Schemas and best practices of response API.
Features
Focused on backend, lot-validate has the following characteristics
- Response standardization
- Fast development
- Validation of mongo Schemas
How to use
Installing
Node.js
npm i lot-validate
Importing
const { DefaultResponse, SchemaValidate } = require("lot-validate")
Using
For response with error
var response = ;if1 != 2response;Response:
"errors":"field": "number_field""error": "Different number""messageOk": """data": {}"hasError": true
For response with success
var response = SchemaValidate;if !responsehasErrorvar dataUser = await Userresponse;return response;
Response:
"errors":"messageOk": "Salvo com sucesso!""data":"_id": "5b11da28775d7939748f7d47""email": "eliveltongama@hotmail.com""password": "123456""username": "elivelton.gama""hasError": false
Validating mongo Schema
public DefaultResponsereturn SchemaValidate;Return: object DTO of Response (DefaultResponse)
Class
Below is the return class and its attributes
DefaultResponse
errors: ErrorsResponsemessageOk: string;data: {}hasError: boolean;
ErrorsResponse
field : stringerror: string;