Skip to content

Commit

Permalink
fix(Attribute): add entity ref value
Browse files Browse the repository at this point in the history
  • Loading branch information
wmakeev committed Jul 29, 2022
1 parent 2c0b047 commit 1c870e0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/model/Attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import type { Entity } from './Entity'
import type { EntityPatchRef, EntityRef } from './EntityRef'
import type { MediaType } from './MediaType'

// TODO Надо отказываться от Enum (нельзя использовать просто строки там где
// в типе указан Enum) #djbqpgnsda

export enum AttributeType {
// Base type
String = 'string',
Expand Down Expand Up @@ -98,9 +101,9 @@ export type AttributePatch<T extends AttributeType = AttributeType> =
} | null
}

: T extends AttributeType.CustomEntity
: T extends EntityRefAttributeType
? EntityPatchRef<'attributemetadata'> & {
value: EntityRef<'customentity'>
value: EntityRef<T>
}

: EntityPatchRef<'attributemetadata'> & NullablePartial<Pick<Attribute<T>, 'value'>>
13 changes: 13 additions & 0 deletions test/model/attributes.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,16 @@ if ('file' in t11_1) {

expectType<null>({} as any as Extract<typeof t11_1['file'], null>)
}

const t12_1: AttributePatch = {
meta: {
type: 'attributemetadata',
href: ''
},
value: {
meta: {
type: AttributeType.Store, // TODO Отказаться от Enum (нельзя указать просто "store") #djbqpgnsda
href: ''
}
}
}
9 changes: 7 additions & 2 deletions test/model/common.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import type { EntityRef, Patch, PrefilledDocument } from '../../src'
import type {
AttributeType,
EntityRef,
Patch,
PrefilledDocument
} from '../../src'
import { testTypeEqual } from '../tools'

const customerorder: Patch<'customerorder'> = {}
Expand All @@ -14,7 +19,7 @@ invoiceOut.paymentPlannedMoment

//#region
const t10_1 = {} as EntityRef<'attributemetadata'> & {
value: EntityRef<'customentity'>
value: EntityRef<AttributeType.CustomEntity>
}

const t10_2: Patch<'customerorder'> = {
Expand Down
9 changes: 7 additions & 2 deletions test/model/utils/Patch.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {
import {
Attribute,
AttributeType,
CustomerOrder,
Expand Down Expand Up @@ -135,7 +135,12 @@ t1.attributes = [
href: ''
},
// foo: '', // #dhg06qfl
value: { meta: { type: 'customentity', href: '' } }
value: {
meta: {
type: AttributeType.CustomEntity,
href: ''
}
}
}
]
//#endregion
Expand Down

0 comments on commit 1c870e0

Please sign in to comment.