Skip to content

Commit

Permalink
fix: refactor pagination into models and build complex listrespone ty…
Browse files Browse the repository at this point in the history
…pe issue #10
  • Loading branch information
algoflows committed Mar 4, 2022
1 parent c8a2810 commit aa2a4b8
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 31 deletions.
40 changes: 10 additions & 30 deletions types/Customer/Orders.d.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,18 @@
declare module 'aifi' {
namespace Aifi {
namespace Customer {
interface PaginationParams {
/**
* Count
*/
count?: number;

/**
* Sort oder ASC ascending or DESC descending
*/
direction?: string;

/**
* Pagination after
*/
after?: string;

/**
* Pagination before
*/
before?: string;

/**
* Id of the store where the order was placed
*/
storeId?: number;
}
/**
* Shape/structure for PaginatedListResponse
*/
type PaginatedListResponse = Array<
Aifi.Models.Order[] | Aifi.Models.PaginationResponse
>;

class OrdersResource {
list(
params: PaginationParams,
params: Aifi.Models.PaginatedParams,
options?: RequestOptions
): Promise<Aifi.Response<Aifi.Models.Order[]>>;
): Promise<Aifi.Response<PaginatedListResponse>>;
// TODO: Pagination Questions?! How?!

retrieve(
Expand All @@ -46,9 +26,9 @@ declare module 'aifi' {
): Promise<Aifi.Response<Aifi.Models.PaymentDetails>>;

listDrafts(
params: PaginationParams,
params: Aifi.Models.PaginatedParams,
options?: RequestOptions
): Promise<Aifi.Response<Aifi.Models.Order[]>>;
): Promise<Aifi.Response<PaginatedListResponse>>;

retrieveDraft(
draftOrderID: string,
Expand Down
47 changes: 47 additions & 0 deletions types/Models/Pagination.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
declare module 'aifi' {
namespace Aifi {
namespace Models {
interface PaginatedParams {
/**
* Count
*/
count?: number;

/**
* Sort oder ASC ascending or DESC descending
*/
direction?: string;

/**
* Pagination after
*/
after?: string;

/**
* Pagination before
*/
before?: string;

/**
* Id of the store where the order was placed
*/
storeId?: number;
}

interface PaginationResponse {
next: Next;
previous: Previous;
}

interface Next {
after: string;
count: number;
}

interface Previous {
before: string;
count: number;
}
}
}
}
3 changes: 2 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
///<reference path='./Models/Customer.d.ts'/>
///<reference path='./Models/Card.d.ts'/>
///<reference path='./Models/Order.d.ts'/>
///<reference path='./Models/Pagination.d.ts'/>
///<reference path='./Models/Product.d.ts'/>

// API specific resource types
// Resource Types
// Admin resource
///<reference path='./Admin/Auth.d.ts' />
///<reference path='./Admin/Customers.d.ts' />
Expand Down

0 comments on commit aa2a4b8

Please sign in to comment.