Skip to content

Commit

Permalink
feat(model): add CustomEntity
Browse files Browse the repository at this point in the history
  • Loading branch information
wmakeev committed Jul 31, 2021
1 parent c754cfd commit 886e33a
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "moysklad-api-model",
"version": "0.4.2",
"version": "0.4.3",
"description": "Объектная модель API МойСклад для TypeScript проектов",
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
Expand Down
21 changes: 21 additions & 0 deletions src/model/CustomEntity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { Entity } from '.'

export type CustomEntityFields = {
updated: string

name: string

code?: string

externalCode?: string

description?: string
}

// TODO CustomEntity: meta.metadataHref

export type CustomEntity = Entity<'customentity'> & CustomEntityFields

export type CustomEntityPatch = Partial<
Pick<CustomEntityFields, 'code' | 'description' | 'externalCode' | 'name'>
>
3 changes: 2 additions & 1 deletion src/model/MetaType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
ContactPerson,
Contract,
Counterparty,
CustomEntity,
CustomerOrder,
CustomerOrderPosition,
Demand,
Expand Down Expand Up @@ -145,7 +146,7 @@ export type EntityByMetaType = {
counterparty: Counterparty
country: Entity<'country'>
currency: Entity<'currency'>
customentity: Entity<'customentity'>
customentity: CustomEntity
customentitymetadata: Entity<'customentitymetadata'>
customerorder: CustomerOrder
customerorderposition: CustomerOrderPosition
Expand Down
1 change: 1 addition & 0 deletions src/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export * from './Company'
export * from './ContactPerson'
export * from './Contract'
export * from './Counterparty'
export * from './CustomEntity'
export * from './CustomerOrder'
export * from './CustomerOrderPosition'
export * from './Demand'
Expand Down
2 changes: 1 addition & 1 deletion src/model/utils/Expand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export type ExpandedField<T, K extends string> =
: T[K] extends EntityRef<M> | undefined
? EntityByMetaType[M] | undefined

: '[Error] never-eus8s'
: '[Error] never-pDw3s'

: T[K]

Expand Down
2 changes: 2 additions & 0 deletions src/model/utils/Patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
CashInPatch,
CashOutPatch,
ContractPatch,
CustomEntityPatch,
CustomerOrderPatch,
CustomerOrderPositionPatch,
DemandPatch,
Expand Down Expand Up @@ -32,6 +33,7 @@ export type PatchByMetaType = {
product: ProductPatch
productfolder: ProductFolderPatch
retaildemand: RetailDemand
customentity: CustomEntityPatch
}

export type Patch<T extends MetaType> = T extends keyof PatchByMetaType
Expand Down
5 changes: 5 additions & 0 deletions test/model/utils/Expand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ if (t55_attr?.type === AttributeType.Counterparty) {
const t55_val: Counterparty = t55_attr.value
t55_val.inn
}

if (t55_attr?.type === AttributeType.CustomEntity) {
const t55_val = t55_attr.value
const code: string | undefined = t55_val.code
}
//#endregion

//#region Expand deep agent.attributes.value
Expand Down

0 comments on commit 886e33a

Please sign in to comment.