diff options
author | Marcin Zelent <marcin@zelent.net> | 2022-12-05 13:00:06 +0100 |
---|---|---|
committer | Marcin Zelent <marcin@zelent.net> | 2022-12-05 13:00:06 +0100 |
commit | 68a7c103b72910ac904cbf72afaffcfe56af1e4f (patch) | |
tree | a1d2d67229d52f6f06c76e0e7442678048b12fc3 /src/models | |
parent | af173870fa08d1a671dad50eac0a8d0894c5be3d (diff) |
Added sorting of groups
Diffstat (limited to 'src/models')
-rw-r--r-- | src/models/Group.ts | 4 | ||||
-rw-r--r-- | src/models/Trip.ts | 14 | ||||
-rw-r--r-- | src/models/index.guard.ts | 7 |
3 files changed, 21 insertions, 4 deletions
diff --git a/src/models/Group.ts b/src/models/Group.ts index 9b3aa6d..c0d281d 100644 --- a/src/models/Group.ts +++ b/src/models/Group.ts @@ -19,7 +19,7 @@ export default interface Group { description?: string;
/**
- * Medias in the group.
+ * Media in the group.
*/
media: MediaItem[];
@@ -32,4 +32,6 @@ export default interface Group { * Metadata that can be displayed in the description.
*/
metadata?: { [key: string]: string | number };
+
+ [key: string]: any;
}
diff --git a/src/models/Trip.ts b/src/models/Trip.ts index 7f92669..46c462d 100644 --- a/src/models/Trip.ts +++ b/src/models/Trip.ts @@ -19,10 +19,22 @@ export default interface Trip { /**
* URL to a JSON file containing data for the trip.
*/
- url: string;
+ url?: string;
/**
* Property indicating if the trip data has been already downloaded.
*/
downloaded: boolean;
+
+ /**
+ * A group property to use while sorting groups.
+ * Nested properties should be delimited with a dot.
+ * Default: name.
+ */
+ sortProperty?: string;
+
+ /**
+ * Sort order. true = descending, false = ascending.
+ */
+ sortOrder?: boolean;
}
diff --git a/src/models/index.guard.ts b/src/models/index.guard.ts index d564ff9..6e9265f 100644 --- a/src/models/index.guard.ts +++ b/src/models/index.guard.ts @@ -47,8 +47,11 @@ export function isTrip(obj: unknown): obj is Trip { typeof typedObj.id === 'string' &&
typeof typedObj.name === 'string' &&
(typeof typedObj.groups === 'undefined' ||
- (Array.isArray(typedObj.groups) && typedObj.groups.every((e: any) => isGroup(e)))
- );
+ (Array.isArray(typedObj.groups) && typedObj.groups.every((e: any) => isGroup(e)))) &&
+ (typeof typedObj.url === 'undefined' || typeof typedObj.url === 'string') &&
+ (typeof typedObj.downloaded === 'undefined' || typeof typedObj.downloaded === 'boolean') &&
+ (typeof typedObj.sortProperty === 'undefined' || typeof typedObj.sortProperty === 'string') &&
+ (typeof typedObj.sortOrder === 'undefined' || typeof typedObj.sortOrder === 'boolean');
if (!isValid) {
throw new Error(`Invalid object: ${JSON.stringify(obj)}`);
|