Closed lucasinocente closed 6 years ago
Hi, @lucassanchez please explain the use case of this feature.
Hey @zemuldo thanks for reply!
At the company I'm working we need validate some required fields besides size and type content. I dont put this config at formats.js
because in our case each processing code have differents fields to validate.
For that I create a config file to join the business rules of processing codes and fields:
[
{
"processing_code": "000000",
"required_fields": [0, 2, 4]
},
{
"processing_code": "000009",
"required_fields": [0]
}
]
I have some job to do yet, like import this config file for another path to people who will use the lib. For example:
const iso8583 = require('iso_8583');
let data = {
0: "0100",
2: "4761739001010119",
3: "000000",
[...]
};
let requiredConfig = ('../path/to/file.json');
let isopack = new iso8583(data,requiredConfig);
I dont know if this use case is the best for the lib. What you think?
I get it, it totally makes sense. what we can do is to let developers create the config as specified and supported then when they initialize the lib, then they can use the required fields config in validation.
Here is the current constructor of the main class
constructor(object, customFormats) {
if (object) {
this.MsgType = object[0];
this.Msg = object;
} else {
this.MsgType = null;
this.Msg = {};
}
Having required fields config will mean a new parametre to the cosntructor or ability to set the required config after the main class is initialized.
let isopack = new iso8583(data...);
isopack.requiredConfig = the_config_josn/_obj
This leaves the schema of the config file for required field as the only thing we need to discuss. Again its a good i dea and even my own use of the library has need for this. I have been doing this using ajv separately.
Nice, I'm glad to be helping. I will do this and update the PR. Thanks for tips!
Hi @zemuldo I updated the PR with external call of config file and one more feature, a filter for required fields with message type (bit [0]) too. Now this two structure works:
[
{
"processing_code": "000002",
"required_fields": [0]
},
{
"processing_code": "999999",
"required_fields":[
{
"0100": [3, 7],
"0500": [3, 7, 11]
}
]
}
]
I do this because here we have this use case too.
What you think?
Hey @lucasinocente , I am reviewing your pr. Will get back today.
Hi! I'm working on a way to verify some required fields.
What you think?