Created
May 24, 2019 10:03
-
-
Save whisher/4016fae10c587065a35d0fc2891ab1e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function ifExists<T>(obj: T | null | undefined, callback: (obj: T) => void) { | |
if (exists(obj)) { | |
callback(obj as T); | |
} | |
} | |
addCurrency(currencyType: Currency, amount: number) { | |
obj.ifExists(this.model, (dto) => { | |
for (const currency of dto.currency) { | |
if (currency.first === currencyType) { | |
currency.second = Number(amount); | |
return; | |
} | |
} | |
const newCurrency = { | |
first: currencyType, | |
second: Number(amount) | |
}; | |
dto.currency = dto.currency.concat(newCurrency); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment