Skip to content

Instantly share code, notes, and snippets.

@whisher
Created May 24, 2019 10:03
Show Gist options
  • Save whisher/4016fae10c587065a35d0fc2891ab1e3 to your computer and use it in GitHub Desktop.
Save whisher/4016fae10c587065a35d0fc2891ab1e3 to your computer and use it in GitHub Desktop.
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