Can I somehow convert it to switch-case?
You can (see below), but it probably wouldn't be best practice. You can simplify it a bit though:
private getClientBankAuthStatus(bankAuth: BankAuthenticationDto, isExpired: boolean): string {
if (!bankAuth) {
return "No";
}
return isExpired ? "Expired" : "Yes";
}
But for completeness, the switch
version might be:
private getClientBankAuthStatus(bankAuth: BankAuthenticationDto, isExpired: boolean): string {
switch (`${bankAuth ? "auth" : ""}-${isExpired ? "expired" : "ok"}`) {
case "auth-ok":
return "Yes";
case "auth-expired":
return "Expired";
default:
return "No";
}
}
...or there's Nina's version, but again, I wouldn't use switch
here at all.
Side note: I'd use a different return type on the function. Either use an enum rather than string literals, or use a union of string literals types:
private getClientBankAuthStatus(
bankAuth: BankAuthenticationDto,
isExpired: boolean
): "Yes" | "No" | "Expired" {
^^^^^^^^^^^^^^^^^^^^^^^^