ambisis_node_helper
v1.10.1
Published
Ambisis helper, funções úteis utilizadas em vários projetos do Ambisis
Downloads
1,183
Keywords
Readme
ambisis_node_helper
service integrator
Use it to comunicate with other services using private or public keys
import { ServiceIntegrator } from 'ambisis_node_helper';
const { integration } = EnvironmentSettings.instance;
export const mailServiceIntegrator = new ServiceIntegrator({
serviceHost: "localhost:3035",
privateKey: "12345",
});
await mailServiceIntegrator.post('/daily_report', {
foo: 'foo'
});
response = await mailServiceIntegrator.get('/foo?bar=123')
response.status
body = response.json()
console.log(body)
{
"code": 200,
"message": "SUCCESS"
}
validate_format
import { Application } from 'express';
import { body } from 'express-validator';
import { root } from '../../controllers/daily_report/POST';
import { validate_format } from 'ambisis_node_helper';
export default (app: Application) => {
app.post(
'/foo',
body('foo').isString().notEmpty(),
body('bar').isString().notEmpty(),
validate_format,
root
);
};
middleware package
import { Application } from 'express';
import { ambisisMiddlewarePackage } from 'ambisis_node_helper';
export default (app: Application) => {
ambisisMiddlewarePackage(app, {
privateKey: "12345",
});
};
Ambisis response
// Non error, without data
return ambisisResponse(res, 200, 'SUCCESS');
{
"code": 200,
"error": "SUCCESS"
}
// Non error, with data
return ambisisResponse(res, 200, 'SUCCESS', {id: 123});
{
"code": 200,
"error": "SUCCESS",
"data": {id: 123}
}
// Error
return ambisisResponse(res, 400, 'BAD_REQUEST');
{
"code": 400,
"error": "BAD_REQUEST"
}
// Error with data
return ambisisResponse(res, 422, 'BAD_REQUEST', {reason: "because you are dumb"});
{
"code": 422,
"error": "BAD_REQUEST",
"data": {reason: "because you are dumb"}
}