null/undefined cleanup
This commit is contained in:
parent
99407a8cdf
commit
3cfc0dd890
@ -40,7 +40,7 @@ export class ApiService {
|
||||
.subscribe(next);
|
||||
}
|
||||
|
||||
getNone<T>(path: any[], next: Next<void> | undefined = undefined): Subscription {
|
||||
getNone<T>(path: any[], next?: Next<void>): Subscription {
|
||||
return this.http.get<void>(getUrl('http', path)).subscribe(next);
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ export class ApiService {
|
||||
return this.http.get(getUrl('http', path), {responseType: "text"}).subscribe(next);
|
||||
}
|
||||
|
||||
getSingle<T>(path: any[], fromJson: FromJson<T>, next: Next<T> | undefined = undefined): Subscription {
|
||||
getSingle<T>(path: any[], fromJson: FromJson<T>, next?: Next<T>): Subscription {
|
||||
return this.http.get<any>(getUrl('http', path)).pipe(map(fromJson)).subscribe(next);
|
||||
}
|
||||
|
||||
@ -56,11 +56,11 @@ export class ApiService {
|
||||
return this.http.get<any[]>(getUrl('http', path)).pipe(map(list => list.map(fromJson))).subscribe(next);
|
||||
}
|
||||
|
||||
postNone(path: any[], data: any, next: Next<void> | undefined = undefined): Subscription {
|
||||
postNone(path: any[], data: any, next?: Next<void>): Subscription {
|
||||
return this.http.post<void>(getUrl('http', path), data).subscribe(next);
|
||||
}
|
||||
|
||||
postSingle<T>(path: any[], data: any, fromJson: FromJson<T>, next: Next<T> | undefined = undefined): Subscription {
|
||||
postSingle<T>(path: any[], data: any, fromJson: FromJson<T>, next?: Next<T>): Subscription {
|
||||
return this.http.post<any>(getUrl('http', path), data).pipe(map(fromJson)).subscribe(next);
|
||||
}
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ export class Value implements IValue {
|
||||
}
|
||||
|
||||
static map(iValue: IValue | null, mapping: GetValue): Value | null {
|
||||
if (!iValue || !iValue.value) {
|
||||
if (iValue === null || iValue.value === null) {
|
||||
return null;
|
||||
}
|
||||
const value = mapping(iValue.value);
|
||||
@ -54,14 +54,14 @@ export class Value implements IValue {
|
||||
}
|
||||
|
||||
static bi(a: IValue | null, b: IValue | null, combineValue: CombineValue) {
|
||||
if (!a) {
|
||||
if (a === null) {
|
||||
return new Value(null, null, b?.unit || null);
|
||||
}
|
||||
if (!b) {
|
||||
if (b === null) {
|
||||
return new Value(null, null, a?.unit || null);
|
||||
}
|
||||
const oldestDate = !a.date || !b.date ? null : dateMin(a.date, b.date);
|
||||
const difference = !a.value || !b.value ? null : combineValue(a.value, b.value);
|
||||
const oldestDate = a.date === null || b.date === null ? null : dateMin(a.date, b.date);
|
||||
const difference = a.value === null || b.value === null ? null : combineValue(a.value, b.value);
|
||||
return new Value(oldestDate, difference, a.unit);
|
||||
}
|
||||
|
||||
|
||||
@ -1,42 +1,42 @@
|
||||
import {FromJson} from "./types";
|
||||
|
||||
export function validateNumber(json: any): number {
|
||||
if (!(typeof json == "number")) {
|
||||
if (!(typeof json === "number")) {
|
||||
throw new Error("Not a number: " + json + " (" + typeof json + "): " + JSON.stringify(json));
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
export function validateNumberOrNull(json: any): number | null {
|
||||
if (json == null) {
|
||||
if (json === null || json === undefined) {
|
||||
return null;
|
||||
}
|
||||
return validateNumber(json);
|
||||
}
|
||||
|
||||
export function validateBoolean(json: any): boolean {
|
||||
if (!(typeof json == "boolean")) {
|
||||
if (!(typeof json === "boolean")) {
|
||||
throw new Error("Not a boolean: " + json + " (" + typeof json + "): " + JSON.stringify(json));
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
export function validateBooleanOrNull(json: any): boolean | null {
|
||||
if (json == null) {
|
||||
if (json === null || json === undefined) {
|
||||
return null;
|
||||
}
|
||||
return validateBoolean(json);
|
||||
}
|
||||
|
||||
export function validateString(json: any): string {
|
||||
if (!(typeof json == "string")) {
|
||||
if (!(typeof json === "string")) {
|
||||
throw new Error("Not a string: " + json + " (" + typeof json + "): " + JSON.stringify(json));
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
export function validateStringOrNull(json: any): string | null {
|
||||
if (json == null) {
|
||||
if (json === null || json === undefined) {
|
||||
return null;
|
||||
}
|
||||
return validateString(json);
|
||||
@ -47,7 +47,7 @@ export function validateDate(json: any): Date {
|
||||
}
|
||||
|
||||
export function validateDateOrNull(json: any): Date | null {
|
||||
if (json == null) {
|
||||
if (json === null || json === undefined) {
|
||||
return null;
|
||||
}
|
||||
return validateDate(json);
|
||||
@ -58,7 +58,7 @@ export function validateList<T>(json: any, fromJson: FromJson<T>): T[] {
|
||||
}
|
||||
|
||||
export function validateLocalDateOrNull(json: any): Date | null {
|
||||
if (json == null) {
|
||||
if (json === null || json === undefined) {
|
||||
return null;
|
||||
}
|
||||
return validateLocalDate(json);
|
||||
|
||||
@ -57,7 +57,7 @@ export class DashboardComponent implements OnInit {
|
||||
if (fresh.name !== name) {
|
||||
return old;
|
||||
}
|
||||
if (old == null || old.lastDate.getTime() <= fresh.lastDate.getTime()) {
|
||||
if (old === null || old.lastDate.getTime() <= fresh.lastDate.getTime()) {
|
||||
return fresh;
|
||||
}
|
||||
return old;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user