Backend validation for supply partner resource
Currently, we have only basic validation to make sure that related resources - like facility, orderable - exist in the system. As part of this ticket, we should introduce additional validations to make sure that supply partner resource will be correct and to avoid problems with using resources by other services.
facilities in associations should be related to the given regular supervisory node by requisition group. In other words, it should be impossible to add any facility but only facilities from a req group which is connected to the given regular supervisory node.
only orderables for which FTAPs exists could be in associations. A list of available FTAPs should be retrieved based on facility types from facilities that are in the same association.
for example, if in an association there is a facility with a type, only orderables from FTAPs for the facility type should be in the association.
the given supply partner should have only one association for the given program/node combo
a new constraint on the database layer should be added
the given supply partner should have only one association for the given program/node/facility/orderable combo,
the check should be global. It means that other supply partner cannot have the same combo.
the user should see an appropriate error message
The validations happen when supply partner is modified and user clicks save
I checked again and everything works fine.
I checked this ticket again and everything works correctly, according to the acceptance criteria, I noticed only small typos:
After removing the name from json in the response I receive the message: "Supply parnter code is required" instead of "Supply partner name is required", also in the message is a typo "parnter", should be "partner".
After creating a new SP, and then sending a PUT with the same data as the existing Supply Partner, I get the answer in which there is a typo: "There is a supply partner that have assocation for the given program ARV(...)" should be an "association".
While checking this ticket I noticed several cases when instead of specific error information I receive 500 Internal Server Error:
When I use PUT api/supplyPartners/id for existing Supply Partner and I do not change any data;
Appears when I change the code or name for SP: changes can be made for the new Supply Partner, however, when I delete the name, the reply is given to the user that the code is required, not the name (400"Supply parnter code is required.");
When I enter the same facility again in associations;
When I enter a facility that does not belong to the correct requisition group(instead of the correct information);
When I enter the same program in associations again;
When I added another program in associations;
When I added the same program, facility, supervisoryNode and orderables as in the previous Supply Partner.
I updated ticket about checking what facilities and orderables could be in an association.