Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(inventory): add product admin dashboard functionality #114

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{

"version": "0.0.61",
"version": "0.0.62",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
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;
}