Witam.
Angularem dodaje do API kontrahenta. Gdy kontrahent doda się poprawnie, zwracam jego ID i przechodzę w edycję, aby poczynić dalsze działania. W momencie gdy taki kontrahent jest już w bazie. Zamiast konkretnego ID zwracam 0.
this.customersService.PostCustomer(customer).subscribe((result: number) => {
if (!result) {
this.snackBar.open('Wystąpił błąd podczas dodawania podatnika do systemu.', '', {
duration: 3 * 1000,
verticalPosition: 'bottom',
horizontalPosition: 'end',
panelClass: ['error-snackbar']
});
} else {
if (result === 0) {
this.snackBar.open('Podatnik o podanym numerze NIP już istnieje w systemie.', '', {
duration: 3 * 1000,
verticalPosition: 'bottom',
horizontalPosition: 'end',
panelClass: ['error-snackbar']
});
} else if (result !== 0) {
this.router.navigate(['/customers/edit', result]);
this.snackBar.open('Pomyślnie dodałem podatnika do systemu', '', {
duration: 3 * 1000,
verticalPosition: 'bottom',
horizontalPosition: 'end',
panelClass: ['success-snackbar']
});
}
}
});
Pierwszy if (!result)
zwraca true
. Dlaczego? Czy javascript traktuje to 0
jako false
?