Skip to content

Commit

Permalink
feat(inventory): add product admin dashboard functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
jerlyrosa committed Nov 17, 2023
1 parent f9a7039 commit a48ea99
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 8 deletions.
25 changes: 18 additions & 7 deletions src/modules/inventory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
GET_VARIANTS,
GET_VARIANTS_BY_STATUS,
GET_WAREHOUSES,
PRODUCT_ADMIN_DASHBOARD,
PRODUCT_DASHBOARD,
} from '../../queries/inventory.query';
import {
Expand Down Expand Up @@ -42,6 +43,8 @@ import {
AllCreatedVariants,
deleteVariant,
AllCreatedVariantsbyStatus,
InputStatusParams,
ProductAdminDashboardInterface,
} from '../../types';

export class Inventory {
Expand All @@ -57,14 +60,11 @@ export class Inventory {
return response.data;
}

public async createStatus(name: string, is_default?:boolean): Promise<CreatedStatus> {
public async createStatus(data: InputStatusParams): Promise<CreatedStatus> {
const response = await this.client.mutate({
mutation: CREATE_STATUS,
variables: {
input: {
name: name,
is_default: is_default
},
input: data,
},
});
return response.data;
Expand Down Expand Up @@ -208,6 +208,17 @@ export class Inventory {

return response.data;
}
public async productAdminDashboard(): Promise<
ProductAdminDashboardInterface
> {
const response = await this.client.query({
query: PRODUCT_ADMIN_DASHBOARD,
fetchPolicy: 'network-only',
partialRefetch: true,
});

return response.data;
}

public async getVariants(
options: {
Expand Down Expand Up @@ -267,7 +278,7 @@ export class Inventory {
page,
whereCondition,
search,
orderByCondition
orderByCondition,
} = options;

const response = await this.client.query({
Expand All @@ -280,7 +291,7 @@ export class Inventory {
page,
whereCondition,
search,
orderByCondition
orderByCondition,
},
fetchPolicy: 'network-only',
partialRefetch: true,
Expand Down
1 change: 1 addition & 0 deletions src/mutations/inventory.mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export const CREATE_STATUS = gql`
id
name
is_default
slug
}
}
`;
Expand Down
15 changes: 15 additions & 0 deletions src/queries/inventory.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,21 @@ export const PRODUCT_DASHBOARD = gql`
}
`;

export const PRODUCT_ADMIN_DASHBOARD = gql`
query getProductAdminDashboard {
productAdminDashboard {
total_products
total_variants
product_status {
status_id
status_name
status_slug
total_amount
}
}
}
`;

export const GET_VARIANTS = gql`
query getVariants(
$first: Int
Expand Down
24 changes: 23 additions & 1 deletion src/types/inventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export interface ProductWarehouse {
export interface StatusInterface {
id: string;
name: string;
is_default: boolean;
is_default?: boolean;
slug: string;
}

export interface OrderBy {
Expand Down Expand Up @@ -354,3 +355,24 @@ export interface ProductDashboardInterface {
export interface deleteVariant {
deleteVariant: boolean;
}

export interface InputStatusParams {
name: string;
is_default?: boolean;
company_id?: number | number;
}

export interface ProductAdminDashboardInterface {
productAdminDashboard: {
total_products: number;
total_variants: number;
product_status: ProductAdminStatusDashboard[];
};
}

export interface ProductAdminStatusDashboard {
status_id: number | string;
status_name: string;
status_slug: string;
total_amount: number;
}

0 comments on commit a48ea99

Please sign in to comment.