diff --git a/README.md b/README.md index 367fce8..905cf69 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ async function doSomething() { ``` -### Get items by mxik code +### Search items by mxik code ```js async function doSomething() { @@ -72,6 +72,14 @@ async function doSomething() { } ``` +### Get mxik code details + +```js +async function doSomething() { + const response = await MXIKDetails('06109001001000000') +} +``` + ## API #### `MXIKSearch(keyword: string, options: object)` @@ -90,6 +98,13 @@ async function doSomething() { | options `object` | { ... } | Search options | | options.limit `object` | 20 | Items count per page | +---- + +#### `MXIKDetails(code: string | number)` +| Param | Default value | Description | +|:---------------------|:--------------|:---------------------| +| code `string/number` | - | Pass a mxik code | + ## License diff --git a/src/api/index.ts b/src/api/index.ts index a5c53f5..7d25234 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -3,7 +3,9 @@ import { AxiosResponse } from 'axios' import { MXIKSearchParamsObj, - MXIKSearchSymbolResponseObj + MXIKSearchSymbolResponseObj, + MXIKCode, + MXIKDetail } from '../typings' export const http = createHttpClient({ @@ -40,3 +42,16 @@ export function MXIKSearchSymbol({ keyword = '', limit = 20 }: MXIKSearchParamsO } }) } + +/** + * Get MXIK details by code + * @param code {number} + * @return {AxiosResponse} + */ +export function MXIKByCode(code: MXIKCode): Promise> { + return http.get('cls-api/mxik/get/by-mxik', { + params: { + mxikCode: code + } + }) +} \ No newline at end of file diff --git a/src/lib/index.ts b/src/lib/index.ts index e125724..0c48192 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -1,5 +1,5 @@ -import { MXIKSearchSymbol, MXIKSearchByParams } from '../api' -import { MXIKSearchOptionsObj, MXIKSearchResponseObj } from '../typings' +import { MXIKSearchSymbol, MXIKSearchByParams, MXIKByCode } from '../api' +import { MXIKCode, MXIKSearchOptionsObj, MXIKSearchResponseObj } from '../typings' import { MXIKUnknownException } from '../exceptions' /** @@ -51,3 +51,16 @@ export async function MXIKSearch(keyword: string, { limit }: MXIKSearchOptionsOb throw new MXIKUnknownException('Something wrong') } } + +/** + * Get MXIK details by code + * @param code {number} + * @return Promise} + */ +export async function MXIKDetails(code: MXIKCode) { + try { + return await MXIKByCode(code) + } catch (error) { + throw new MXIKUnknownException('Something wrong') + } +} \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index b6d13d3..cc1bb16 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,5 @@ import './style.css' -import { MXIKSearch, MXIKSearchByCode } from './lib' +import { MXIKSearch, MXIKSearchByCode, MXIKDetails } from './lib' // Usage example const response = await MXIKSearch('футболка', { limit: 10 }) @@ -8,6 +8,9 @@ console.log(response) const res = await MXIKSearchByCode('06109001001000000', { limit: 20 }) console.log(res) +const details = await MXIKDetails('06109001001000000') +console.log(details) + const app = document.querySelector('#app')! app.innerHTML = `

mxik

` diff --git a/src/typings/index.ts b/src/typings/index.ts index d41833a..3b1c871 100644 --- a/src/typings/index.ts +++ b/src/typings/index.ts @@ -83,3 +83,52 @@ export interface MXIKSearchResponseObj { isLastPage: boolean } } + +export type MXIKCode = string | number + +export interface MXIKPackageItem { + code: number + parentCode: number + mxikCode: string + containerCode: number + containerName: string + containerNamePl: string | null + containerNamePl2: string | null + unitId: number + unitName: string + parentValue: number + name: string + type: string + childNames: string + childValues: string + isUnitPackage: string + createdAt: string + createdBy: string + children: string[] + childrenValue: string[] +} + +export interface MXIKDetail { + mxikCode: string + groupName: string + groupCode: string + className: string + classCode: string + positionName: string + positionCode: string + subPositionName: string + subPositionCode: string + brandName: string | null + brandCode: string + mxikName: string + attributeName: string | null + unitCode: string | null + unitName: string | null + commonUnitCode: string | null + commonUnitName: string | null + internationalCode: string | null + label: number + units: string | number + myProduct: number + packages: MXIKPackageItem[] +} \ No newline at end of file