0

Edit: I' ve found a similar question and resolved this with this code:

testeTipoMySQLtoOracle(testeTipo: any) {

    var tipoNumber = {
        "aceitacao": 1,
        "integracao": 4,
        "interface-mobile": 5,
        "interface-web": 6,
        "performance": 7,      
        "unitario": 8,
    };
    var indice: keyof typeof tipoNumber = testeTipo; 

    if (indice in tipoNumber) {
        return tipoNumber[indice];
    }
}

I Want to receive a value and change it before sending a request to my DataBase. One DataBase send me a string and I must assign its equivalent number before sending it to the other DataBase.

Here is what I have so far:

testeTipoMySQL(testeTipo: string){
        if(testeTipo == "aceitacao"){
            return 1;
        }else if(testeTipo == "integracao"){
            return 4;
        }else if(testeTipo == "interface-mobile"){
            return 5;
        }else if(testeTipo == "interface-web"){
            return 6;
        }else if(testeTipo == "performance"){
            return 7;
        }else if(testeTipo == "unitario"){
            return 8;
        }
    } 

I want to know if is there another better way of doing it that I'm not seeing cause I'm new to JavasCript.

  • [`switch`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch) or a lookup [map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) or [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer) would be reasonable choices. – T.J. Crowder Feb 01 '22 at 17:11
  • Welcome to Stack Overflow! Please take the [tour] if you haven't already (you get a badge!), have a look around, and read through the [help], in particular [*How do I ask a good question?*](/help/how-to-ask) I also recommend Jon Skeet's [Writing the Perfect Question](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) and [Question Checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). – T.J. Crowder Feb 01 '22 at 17:11
  • Please do search thoroughly before posting. I found the linked question with [this search](/search?q=%5Bjs%5D+alternative+to+if+else) for instance. More about searching [here](/help/searching). – T.J. Crowder Feb 01 '22 at 17:11

0 Answers0