Fetch Pass/fail Count for each request of collection

I have a collection of more than 20 requests. Each request contains several tests. I want to fetch the total number of failed and passed requests and store it in an environment variable.

My condition for a failed request: IF any test of a particular request fails, the request will be marked as failed.

My condition for passing a test: IF all tests for a request pass, the request will be marked pass.

can anyone share what should be my postman script(code) for this?