Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Commit

Permalink
check products and prodCategories
Browse files Browse the repository at this point in the history
  • Loading branch information
munkhsaikhan committed Oct 31, 2023
1 parent 8b359b8 commit ee39000
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 43 deletions.
7 changes: 7 additions & 0 deletions packages/plugin-syncerkhet-api/src/afterMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const afterMutationHandlers = async (subdomain, params) => {
'stageInSaleConfig',
{}
);

const moveConfigs = await models.Configs.getConfig(
'stageInMoveConfig',
{}
Expand Down Expand Up @@ -130,8 +131,14 @@ export const afterMutationHandlers = async (subdomain, params) => {
}

// create sale
console.log(
Object.keys(saleConfigs),
destinationStageId,
'ddddddddddddd'
);
if (Object.keys(saleConfigs).includes(destinationStageId)) {
const brandRules = saleConfigs[destinationStageId].brandRules || {};
console.log(brandRules, 'kkkkkkkkkkkkkkkkk');
const brandIds = Object.keys(brandRules).filter(b =>
Object.keys(mainConfigs).includes(b)
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { IContext } from '../../../connectionResolver';
import { getConfig } from '../../../utils/utils';
import { sendRequest } from '@erxes/api-utils/src/requests';
import { sendProductsMessage } from '../../../messageBroker';
import {
Expand All @@ -8,10 +7,15 @@ import {
} from '../../../utils/consumeInventory';

const inventoryMutations = {
async toCheckProducts(_root, _params, { subdomain, models }: IContext) {
const config = await models.Configs.getConfig('ERKHET', {});
async toCheckProducts(
_root,
{ brandId }: { brandId: string },
{ subdomain, models }: IContext
) {
const configs = await models.Configs.getConfig('erkhetConfig', {});
const config = configs[brandId || 'noBrand'];

if (!config.apiToken || !config.apiKey || !config.apiSecret) {
if (!config || !config.apiToken || !config.apiKey || !config.apiSecret) {
throw new Error('Erkhet config not found.');
}

Expand Down Expand Up @@ -96,6 +100,7 @@ const inventoryMutations = {
(categoryOfId[product.categoryId] || {}).code
) {
matchedCount = matchedCount + 1;
console.log(product.code);
} else {
updateProducts.push(resProd);
}
Expand Down Expand Up @@ -123,10 +128,15 @@ const inventoryMutations = {
};
},

async toCheckCategories(_root, _params, { subdomain, models }: IContext) {
const config = await models.Configs.getConfig('ERKHET', {});
async toCheckCategories(
_root,
{ brandId }: { brandId: string },
{ subdomain, models }: IContext
) {
const configs = await models.Configs.getConfig('erkhetConfig', {});
const config = configs[brandId || 'noBrand'];

if (!config.apiToken || !config.apiKey || !config.apiSecret) {
if (!config || !config.apiToken || !config.apiKey || !config.apiSecret) {
throw new Error('Erkhet config not found.');
}

Expand Down Expand Up @@ -202,10 +212,20 @@ const inventoryMutations = {

async toSyncCategories(
_root,
{ action, categories }: { action: string; categories: any[] },
{
brandId,
action,
categories
}: { brandId: string; action: string; categories: any[] },
{ subdomain, models }: IContext
) {
const config = models.Configs.getConfig('ERKHET', {});
const configs = await models.Configs.getConfig('erkhetConfig', {});
const config = configs[brandId || 'noBrand'];

if (!config || !config.apiToken || !config.apiKey || !config.apiSecret) {
throw new Error('Erkhet config not found.');
}

try {
switch (action) {
case 'CREATE': {
Expand Down Expand Up @@ -257,10 +277,20 @@ const inventoryMutations = {

async toSyncProducts(
_root,
{ action, products }: { action: string; products: any[] },
{
brandId,
action,
products
}: { brandId: string; action: string; products: any[] },
{ subdomain, models }: IContext
) {
const config = models.Configs.getConfig('ERKHET', {});
const configs = await models.Configs.getConfig('erkhetConfig', {});
const config = configs[brandId || 'noBrand'];

if (!config || !config.apiToken || !config.apiKey || !config.apiSecret) {
throw new Error('Erkhet config not found.');
}

try {
switch (action) {
case 'CREATE': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ export const mutations = `
toCheckSynced(ids: [String]): [CheckResponse]
toSyncDeals(dealIds: [String], configStageId: String, dateType: String): JSON
toSyncOrders(orderIds: [String]): JSON
toCheckProducts(productCodes: [String]): JSON
toCheckCategories(categoryCodes: [String]): JSON
toSyncCategories(action: String, categories: [JSON]): JSON
toSyncProducts(action: String, products: [JSON]): JSON
toCheckProducts(brandId: String): JSON
toCheckCategories(brandId: String): JSON
toSyncCategories(brandId: String, action: String, categories: [JSON]): JSON
toSyncProducts(brandId: String, action: String, products: [JSON]): JSON
`;
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import { __ } from '@erxes/ui/src/utils/core';
import React from 'react';
import Row from './InventoryCategoryRow';
import { menuSyncerkhet } from '../../constants';
import { BarItems } from '@erxes/ui/src/layout/styles';
import SelectBrands from '@erxes/ui/src/brands/containers/SelectBrands';

type Props = {
loading: boolean;
history: any;
queryParams: any;
toCheckCategories: () => void;
toSyncCategories: (action: string, categories: any[]) => void;
setBrand: (brandId: string) => void;
items: any;
};

Expand Down Expand Up @@ -130,7 +133,19 @@ class InventoryCategory extends React.Component<Props, State> {
};

const checkButton = (
<>
<BarItems>
<SelectBrands
label={__('Choose brands')}
onSelect={brand => this.props.setBrand(brand as string)}
initialValue={this.props.queryParams.brandId}
multi={false}
name="selectedBrands"
customOption={{
label: 'No Brand (noBrand)',
value: ''
}}
/>

<Button
btnStyle="warning"
size="small"
Expand All @@ -139,7 +154,7 @@ class InventoryCategory extends React.Component<Props, State> {
>
Check
</Button>
</>
</BarItems>
);
const header = <Wrapper.ActionBar right={checkButton} />;
const content = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ import {
Pagination
} from '@erxes/ui/src/components';
import { menuSyncerkhet } from '../../constants';
import SelectBrands from '@erxes/ui/src/brands/containers/SelectBrands';
import { BarItems } from '@erxes/ui/src/layout/styles';

type Props = {
loading: boolean;
queryParams: any;
toCheckProducts: () => void;
toSyncProducts: (action: string, products: any[]) => void;
setBrand: (brandId: string) => void;
items: any;
};

Expand Down Expand Up @@ -138,7 +141,18 @@ class InventoryProducts extends React.Component<Props, State> {
};

const checkButton = (
<>
<BarItems>
<SelectBrands
label={__('Choose brands')}
onSelect={brand => this.props.setBrand(brand as string)}
initialValue={this.props.queryParams.brandId}
multi={false}
name="selectedBrands"
customOption={{
label: 'No Brand (noBrand)',
value: ''
}}
/>
<span>
{items &&
items.matched &&
Expand All @@ -153,7 +167,7 @@ class InventoryProducts extends React.Component<Props, State> {
>
Check
</Button>
</>
</BarItems>
);

const header = <Wrapper.ActionBar right={checkButton} />;
Expand Down
23 changes: 16 additions & 7 deletions packages/plugin-syncerkhet-ui/src/containers/InventoryCategory.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import * as compose from 'lodash.flowright';
import Alert from '@erxes/ui/src/utils/Alert';
import { gql } from '@apollo/client';
import React from 'react';
import Spinner from '@erxes/ui/src/components/Spinner';
import { Bulk } from '@erxes/ui/src/components';
import { graphql } from '@apollo/client/react/hoc';
import { router } from '@erxes/ui/src';
import { Bulk } from '@erxes/ui/src/components';
import Spinner from '@erxes/ui/src/components/Spinner';
import { IRouterProps } from '@erxes/ui/src/types';
import { mutations } from '../graphql';
import Alert from '@erxes/ui/src/utils/Alert';
import { withProps } from '@erxes/ui/src/utils/core';
import * as compose from 'lodash.flowright';
import React from 'react';
import { withRouter } from 'react-router-dom';
import InventoryCategory from '../components/inventoryCategory/InventoryCategory';
import { mutations } from '../graphql';
import {
ToCheckCategoriesMutationResponse,
ToSyncCategoriesMutationResponse
Expand Down Expand Up @@ -41,6 +42,7 @@ class InventoryCategoryContainer extends React.Component<FinalProps, State> {

render() {
const { items, loading } = this.state;
const brandId = this.props.queryParams.brandId || 'noBrand';

const setSyncStatus = (data: any, action: string) => {
const createData = data[action].items.map(d => ({
Expand All @@ -62,11 +64,17 @@ class InventoryCategoryContainer extends React.Component<FinalProps, State> {
});
};

const setBrand = (brandId: string) => {
router.setParams(this.props.history, { brandId: brandId });
return router;
};

const toSyncCategories = (action: string, categories: any[]) => {
this.setState({ loading: true });
this.props
.toSyncCategories({
variables: {
brandId,
action: action,
categories: categories
}
Expand All @@ -91,7 +99,7 @@ class InventoryCategoryContainer extends React.Component<FinalProps, State> {
const toCheckCategories = () => {
this.setState({ loading: true });
this.props
.toCheckCategories({ variables: {} })
.toCheckCategories({ variables: { brandId } })
.then(response => {
let data = response.data.toCheckCategories;

Expand All @@ -117,6 +125,7 @@ class InventoryCategoryContainer extends React.Component<FinalProps, State> {
loading: loading,
toCheckCategories,
toSyncCategories,
setBrand,
items
};

Expand Down
23 changes: 16 additions & 7 deletions packages/plugin-syncerkhet-ui/src/containers/InventoryProducts.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import * as compose from 'lodash.flowright';
import Alert from '@erxes/ui/src/utils/Alert';
import { gql } from '@apollo/client';
import React from 'react';
import Spinner from '@erxes/ui/src/components/Spinner';
import { Bulk } from '@erxes/ui/src/components';
import { graphql } from '@apollo/client/react/hoc';
import { router } from '@erxes/ui/src';
import { Bulk } from '@erxes/ui/src/components';
import Spinner from '@erxes/ui/src/components/Spinner';
import { IRouterProps } from '@erxes/ui/src/types';
import { mutations } from '../graphql';
import Alert from '@erxes/ui/src/utils/Alert';
import { withProps } from '@erxes/ui/src/utils/core';
import * as compose from 'lodash.flowright';
import React from 'react';
import { withRouter } from 'react-router-dom';
import InventoryProducts from '../components/inventoryProducts/InventoryProducts';
import { mutations } from '../graphql';
import {
ToCheckProductsMutationResponse,
ToSyncProductsMutationResponse
Expand Down Expand Up @@ -41,6 +42,7 @@ class InventoryProductsContainer extends React.Component<FinalProps, State> {

render() {
const { items, loading } = this.state;
const brandId = this.props.queryParams.brandId || 'noBrand';

const setSyncStatus = (data: any, action: string) => {
const createData = data[action].items.map(d => ({
Expand All @@ -62,11 +64,17 @@ class InventoryProductsContainer extends React.Component<FinalProps, State> {
});
};

const setBrand = (brandId: string) => {
router.setParams(this.props.history, { brandId: brandId });
return router;
};

const toSyncProducts = (action: string, products: any[]) => {
this.setState({ loading: true });
this.props
.toSyncProducts({
variables: {
brandId: brandId,
action: action,
products: products
}
Expand All @@ -91,7 +99,7 @@ class InventoryProductsContainer extends React.Component<FinalProps, State> {
this.setState({ loading: true });
this.props
.toCheckProducts({
variables: {}
variables: { brandId }
})
.then(response => {
let data = response.data.toCheckProducts;
Expand All @@ -116,6 +124,7 @@ class InventoryProductsContainer extends React.Component<FinalProps, State> {
...this.props,
loading: loading,
toCheckProducts,
setBrand,
items,
toSyncProducts
};
Expand Down
8 changes: 4 additions & 4 deletions packages/plugin-syncerkhet-ui/src/graphql/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const toSyncOrders = `
`;

const toCheckProducts = `
mutation toCheckProducts($productCodes: [String]) {
toCheckProducts(productCodes: $productCodes)
mutation toCheckProducts($brandId: String) {
toCheckProducts(brandId: $brandId)
}
`;

Expand All @@ -43,8 +43,8 @@ const toSyncProducts = `
`;

const toCheckCategories = `
mutation toCheckCategories($categoryCodes: [String]) {
toCheckCategories(categoryCodes: $categoryCodes)
mutation toCheckCategories($brandId: String) {
toCheckCategories(brandId: $brandId)
}
`;

Expand Down
Loading

0 comments on commit ee39000

Please sign in to comment.