Skip to content

Commit

Permalink
Merge pull request #11 from ge-tracker/typing
Browse files Browse the repository at this point in the history
Add favourite items typing
  • Loading branch information
gtjamesa authored Oct 19, 2023
2 parents cd7c337 + cc4c6e3 commit 3bce04c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/endpoints/DashboardWrapper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import APIBaseWrapper from './APIBaseWrapper';
import type {ItemArrayDataWrappedWithMeta, ItemDataWrapped} from '../types';
import type {DataWrappedWithMeta, ItemDataWrapped} from '../types';

export type DashboardTotal = {
invested: number;
Expand All @@ -17,8 +17,8 @@ export type DashboardTiles = {
};

export type Dashboard = {
favouriteItems: ItemArrayDataWrappedWithMeta;
suggestedItems: ItemArrayDataWrappedWithMeta;
favouriteItems: DataWrappedWithMeta;
suggestedItems: DataWrappedWithMeta;
tiles: {
data: DashboardTiles;
};
Expand Down
15 changes: 9 additions & 6 deletions src/endpoints/FavouriteItemsWrapper.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import APIBaseWrapper from './APIBaseWrapper';
import type {Item, ItemListPromise} from '../types';

export interface FavouriteItemReorder {
export type FavouriteItemReorder = {
item_id: number;
order: number;
}
};

export type FavouriteItemReorderRequest = Array<FavouriteItemReorder>;

export type FavouriteItem = Item & {favouriteItemsId: number};

export default class FavouriteItemsWrapper extends APIBaseWrapper {
getItems(): ItemListPromise<FavouriteItem> {
return this._wrapGet('favourite-items');
}

addItem(itemId: number) {
return this._wrapPost(`favourite-items`, {
item_id: itemId,
Expand All @@ -22,10 +29,6 @@ export default class FavouriteItemsWrapper extends APIBaseWrapper {
return this._wrapDelete(`favourite-items/itemId/${itemId}`);
}

getItems(opts = {filters: false}) {
return this._wrapGet(this.parseOptions('favourite-items', opts));
}

/**
* Update favourite items sort order
*
Expand Down
8 changes: 5 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ export interface Item {

export type MetaCount = {count: number};

export type ItemListPromise = Promise<Item[]>;
export type ItemPromise = Promise<Item>;
export type ItemListPromise<T = Item> = Promise<T[]>;
export type ItemPromise<T = Item> = Promise<T>;
export type DataWrapped<T> = {data: T};
export type DataWrappedWithMeta<T = Item> = {data: T[]; meta: MetaCount};
export type ItemDataWrapped = DataWrapped<Item>;
export type ItemArrayDataWrapped = DataWrapped<Item[]>;
export type ItemArrayDataWrappedWithMeta = {data: Item[]; meta: MetaCount};

export interface StatusResponse {
status_code: number;
Expand Down Expand Up @@ -178,3 +178,5 @@ export type Paginated = {
export type PaginatedResponse<T, PaginationType = LegacyPaginated> = {
data: T[];
} & PaginationType;

export type MaybePromise<T> = T | Promise<T>;

0 comments on commit 3bce04c

Please sign in to comment.