From 71061089a4cf78676fdae5d24f103afba8973e15 Mon Sep 17 00:00:00 2001 From: Kevin Nderitu Date: Fri, 23 Nov 2018 12:20:05 +0300 Subject: [PATCH] Added query parameter type --- src/functions/data.ts | 5 +++-- src/types.d.ts | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/functions/data.ts b/src/functions/data.ts index 425dd66..9aeb52c 100644 --- a/src/functions/data.ts +++ b/src/functions/data.ts @@ -9,7 +9,8 @@ import { AppData, Tag, IData, - PersistedAppData + PersistedAppData, + QueryParams } from "../types"; import { requests } from "../requests"; import { ServiceBase } from "../service-base"; @@ -44,7 +45,7 @@ export class Data extends ServiceBase implements IData{ * @param query (Optional) query * @returns Promise */ - public async getEntities(query?: any): Promise { + public async getEntities(query?: QueryParams): Promise { return await this.internalRequest(requests.data.getEntities, query); } diff --git a/src/types.d.ts b/src/types.d.ts index 1587118..a936c0b 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -49,6 +49,21 @@ export interface MenuItem { default?: boolean; } +export interface QueryMatch { + [fieldOrOp: string]: any; +} + +export interface QueryParams { + [key: string]: any; + query?: QueryMatch; + limit?: number; + skip?: number; + sort?: { + [field: string]: number; + }; + tags?: string[]; +} + export interface FileParams { name: string; public: boolean; @@ -109,7 +124,7 @@ interface HasTimestamps { export interface IData { createEntity(entity: EntityData): Promise; project(): Promise; - getEntities(query?: any): Promise; + getEntities(query?: QueryParams): Promise; getEntityById(id: string): Promise; addTagsToEntity(params: TagsParams): Promise; removeTagsFromEntity(params: TagsParams): Promise;