baosystems / dish2

Dish2 is a command line tool for DHIS 2 Web API interaction
6 stars 8 forks source link

remove_org_units falsely reports success #13

Open hardingt opened 7 years ago

hardingt commented 7 years ago
Timothys-MacBook-Pro:dish2 tharding$ node bin/remove_org_units.js --file /Users/tharding/Documents/dish_files/playdev/removeme.csv 
Using DHIS2_HOME environment variable pointing to: /Users/tharding/Documents/dish_files/playdev/dish.json
Data for org unit successfully deleted, id: DiszpKrYNg8, name: undefined
Org unit successfully deleted: DiszpKrYNg8, undefined
Process completed!
Org units deleted: 1
Total no of org units: 1
Errors occured: 0
Timothys-MacBook-Pro:dish2 tharding$ 

But visiting: https://play.dhis2.org/dev/api/26/organisationUnits/DiszpKrYNg8.json

Shows it still there.

Also note that rerunning it will give the exact same output.

hardingt commented 7 years ago

I made a small change while debugging and you can see the return code is 404:

Using DHIS2_HOME environment variable pointing to: /Users/tharding/Documents/dish_files/playdev/dish.json
Data for org unit successfully deleted, id: undefined, name: Ngelehun CHC
{ type: 'buffer',
  status: 404,
  headers: 
   { server: 'nginx/1.4.6 (Ubuntu)',
     date: 'Thu, 26 Jan 2017 17:20:34 GMT',

Curious, I checked out the code checker in configManager.js:

cnf.is2xx = function(code) {
  return parseInt(code/100);
}

which returns the 100s place it looks like, rather than if the number is between 200 and 299.

console.log(conf.is2xx(delOuResp.status));
4

Suggest we edit this function to return FALSE (or the JS equivalent) if not between 200 and 299