34 lines
757 B
TypeScript

import { isNumberFinite, isObject, isOptionalOf, isOptionalArrayOf, isString } from "common/utils";
export interface AlbumModel {
id: number;
name: string;
description?: string;
covers?: number[];
tracks?: number[];
};
export function isAlbumModel(data: any): data is AlbumModel {
if (!isObject(data)) {
return false;
}
if (!isNumberFinite(data.id)) {
return false;
}
if (!isString(data.name)) {
return false;
}
if (!isOptionalOf(data.description, isString)) {
return false;
}
if (!isOptionalArrayOf(data.cover, isNumberFinite)) {
return false;
}
if (!isOptionalArrayOf(data.tracks, isNumberFinite)) {
return false;
}
return true;
}