Skip to content

Commit

Permalink
feat(api): mxik details
Browse files Browse the repository at this point in the history
  • Loading branch information
azabroflovski committed Jun 24, 2022
1 parent 4b9f49c commit 9a1e23d
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 5 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,22 @@ async function doSomething() {
```


### Get items by mxik code
### Search items by mxik code

```js
async function doSomething() {
const response = await MXIKSearchByCode('06109001001000000', { limit: 10 })
}
```

### Get mxik code details

```js
async function doSomething() {
const response = await MXIKDetails('06109001001000000')
}
```

## API

#### `MXIKSearch(keyword: string, options: object)`
Expand All @@ -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

Expand Down
17 changes: 16 additions & 1 deletion src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { AxiosResponse } from 'axios'

import {
MXIKSearchParamsObj,
MXIKSearchSymbolResponseObj
MXIKSearchSymbolResponseObj,
MXIKCode,
MXIKDetail
} from '../typings'

export const http = createHttpClient({
Expand Down Expand Up @@ -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<AxiosResponse<MXIKDetail>> {
return http.get('cls-api/mxik/get/by-mxik', {
params: {
mxikCode: code
}
})
}
17 changes: 15 additions & 2 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -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'

/**
Expand Down Expand Up @@ -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<MXIKDetail>}
*/
export async function MXIKDetails(code: MXIKCode) {
try {
return await MXIKByCode(code)
} catch (error) {
throw new MXIKUnknownException('Something wrong')
}
}
5 changes: 4 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -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 })
Expand All @@ -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<HTMLDivElement>('#app')!
app.innerHTML = `<h1>mxik</h1>`
49 changes: 49 additions & 0 deletions src/typings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
}

0 comments on commit 9a1e23d

Please sign in to comment.