Skip to content

Commit

Permalink
feat: add file attribute patch support
Browse files Browse the repository at this point in the history
  • Loading branch information
wmakeev committed Jul 21, 2021
1 parent c600599 commit 7f86686
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 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.3.0",
"version": "0.3.1",
"description": "Объектная модель API МойСклад для TypeScript проектов",
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
Expand Down
12 changes: 8 additions & 4 deletions src/model/Attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ export type Attribute<
}
: AttributeBase<T>

export type AttributePatch<T extends AttributeType = AttributeType> = Partial<
Pick<Attribute<T>, 'value'>
> &
EntityPatchRef<'attributemetadata'>
export type AttributePatch<T extends AttributeType = AttributeType> =
| (EntityPatchRef<'attributemetadata'> & {
file: {
filename: string
content: string
}
})
| (EntityPatchRef<'attributemetadata'> & Partial<Pick<Attribute<T>, 'value'>>)
2 changes: 2 additions & 0 deletions src/model/utils/PrefilledDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import type { Expand } from './Expand'

// TODO Указать конкретные типы документов которые можно создавать этим методом

// TODO Описать параметры необходимые для создания шаблона документа

// TODO API гибок и позволяет отправлять при создании объекта не обязательные
// и лишние поля. В типах нельзя позволять такую вольность, хотя на практике
// подобное может быть удобно.
Expand Down
17 changes: 16 additions & 1 deletion test/model/utils/Patch.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {
Attribute,
AttributeType,
CustomerOrder,
CustomerOrderPatch,
MetaType,
Expand Down Expand Up @@ -66,7 +67,14 @@ t1.attributes = [
type: 'attributemetadata',
href: ''
},
value: ''
value: '',
file: { filename: '', content: '' }
},
{
meta: {
type: 'attributemetadata',
href: ''
}
}
]

Expand All @@ -77,6 +85,13 @@ t1.attributes = [
}
]

t1.attributes = [
{
// @ts-expect-error
file: {}
}
]

t1.attributes = [
{
meta: {
Expand Down

0 comments on commit 7f86686

Please sign in to comment.