Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
wmakeev committed Jul 24, 2021
1 parent db64300 commit c3be3ca
Show file tree
Hide file tree
Showing 27 changed files with 227 additions and 135 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.3",
"version": "0.3.4",
"description": "Объектная модель API МойСклад для TypeScript проектов",
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
Expand Down
7 changes: 3 additions & 4 deletions src/model/AbstractDemand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import type {
DocumentWithPositions,
DocumentWithPositionsPatch,
EntityRef,
HasVat,
HasVatPatch
HasVat
} from '.'

export type DemandMetaType = 'demand' | 'retaildemand'
Expand All @@ -25,5 +24,5 @@ export type AbstractDemand<
export type AbstractDemandPatch<
T extends DemandMetaType
> = DocumentWithPositionsPatch<T> &
HasVatPatch &
Partial<Pick<AbstractDemandFields, 'customerOrder'>>
Partial<Pick<AbstractDemandFields, 'customerOrder'>> &
Partial<HasVat>
8 changes: 5 additions & 3 deletions src/model/Account.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { Entity } from './Entity'
import type { HasUpdated } from './HasUpdated'
import type { Entity } from '.'

export type Account = Entity<'account'> & {
/** Момент последнего обновления */
readonly updated: string

export interface Account extends Entity<'account'>, HasUpdated {
/** Является ли счет основным счетом Контрагента */
isDefault: boolean

Expand Down
22 changes: 11 additions & 11 deletions src/model/Agent.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import type { Entity } from './Entity'
import type { HasAttributes } from './HasAttributes'
import type { HasCreated } from './HasCreated'
import type { HasUpdated } from './HasUpdated'
import type { Owned } from './Owned'
import type { Attribute, Entity, Owned } from '.'

export type AgentMetaType = 'employee' | 'counterparty' | 'organization'

export interface Agent<T extends AgentMetaType>
extends Entity<T>,
Owned,
HasCreated,
HasUpdated,
HasAttributes {
export interface Agent<T extends AgentMetaType> extends Entity<T>, Owned {
/** Дата создания сущности */
readonly created: string

/** Момент последнего обновления */
readonly updated: string

/** Наименование */
name: string

Expand All @@ -32,4 +29,7 @@ export interface Agent<T extends AgentMetaType>

/** Номер телефона */
phone?: string

/** Спосок пользовательских полей */
attributes?: Attribute[]
}
10 changes: 5 additions & 5 deletions src/model/AgentNote.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Entity } from './Entity'
import type { EntityRef } from './EntityRef'
import type { HasCreated } from './HasCreated'
import type { MetaType } from './MetaType'
import type { Entity, EntityRef } from '.'

export type AgentNote = Entity<'note'> & {
/** Дата создания сущности */
readonly created: string

export interface AgentNote extends Entity<'note'>, HasCreated {
description?: string

agent: EntityRef<'counterparty'>
Expand Down
10 changes: 5 additions & 5 deletions src/model/ContactPerson.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { Entity } from './Entity'
import type { EntityRef } from './EntityRef'
import type { HasUpdated } from './HasUpdated'
import type { MetaType } from './MetaType'
import type { Entity, EntityRef } from '.'

export interface ContactPerson extends Entity<'contactperson'>, HasUpdated {
export type ContactPerson = Entity<'contactperson'> & {
/** Наименование */
name: string

/** Момент последнего обновления */
readonly updated: string

/** Описание */
description?: string

Expand Down
3 changes: 2 additions & 1 deletion src/model/CustomerOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ export type CustomerOrderExpand = Pick<
OrderExpand<'customerorder'>

export type CustomerOrderPatch = OrderPatch<'customerorder'> &
Partial<Pick<CustomerOrderFields, 'taxSystem'>>
Partial<Pick<CustomerOrderFields, 'taxSystem'>> &
Partial<HasVat>
109 changes: 61 additions & 48 deletions src/model/Document.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import type { AttributePatch } from '.'
import type { Entity } from './Entity'
import type { EntityRef } from './EntityRef'
import type { HasAttributes } from './HasAttributes'
import type { HasCreated } from './HasCreated'
import type { HasDeleted } from './HasDeleted'
import type { HasFiles } from './HasFiles'
import type { HasProject } from './HasProject'
import type { HasRate } from './HasRate'
import type { HasState } from './HasState'
import type { HasUpdated } from './HasUpdated'
import type { Owned } from './Owned'
import type {
Attribute,
AttributePatch,
CollectionRef,
Entity,
EntityRef,
Rate,
Owned
} from '.'

// TODO | 'processingplan'
// TODO | 'processing'?
Expand Down Expand Up @@ -45,52 +42,68 @@ export type DocumentMetaType =
| 'salesreturn'
| 'supply'

export type DocumentFieds = HasCreated &
HasUpdated &
HasDeleted &
HasState &
HasProject &
HasRate &
HasAttributes &
HasFiles &
Owned & {
/** Наименование документа */
name: string
export type DocumentFieds = Owned & {
/** Наименование документа */
name: string

/** Проведено */
applicable: boolean
/** Проведено */
applicable: boolean

/** Комментарий */
description?: string
/** Дата создания сущности */
readonly created: string

/** Внешний код */
externalCode?: string
/** Момент последнего обновления */
readonly updated: string

/** Дата документа */
moment: string
/** Комментарий */
description?: string

readonly syncId?: string
/** Внешний код */
externalCode?: string

/** Договор */
contract?: EntityRef<'contract'>
/** Дата документа */
moment: string

/** Сумма документа */
readonly sum: number
/** Статус документа */
state?: EntityRef<'state'>

// TODO agent: общий тип можно экспандить только по пересечению
readonly syncId?: string

/** Контрагент */
agent: EntityRef<'counterparty' | 'organization'>
/** Договор */
contract?: EntityRef<'contract'>

/** Счет контрагента */
agentAccount?: EntityRef<'account'>
/** Проект */
project?: EntityRef<'project'>

/** Организация */
organization: EntityRef<'organization'>
/** Сумма документа */
readonly sum: number

/** Счет организации */
organizationAccount?: EntityRef<'account'>
}
// TODO agent: общий тип можно экспандить только по пересечению

/** Контрагент */
agent: EntityRef<'counterparty' | 'organization'>

/** Счет контрагента */
agentAccount?: EntityRef<'account'>

/** Организация */
organization: EntityRef<'organization'>

/** Счет организации */
organizationAccount?: EntityRef<'account'>

/** Спосок пользовательских полей */
attributes?: Attribute[]

/** Валюта документа */
rate: Rate

/** Вложенные файлы (максимальное кол-во файлов - 100) */
files?: CollectionRef<'files'>

/** Момент последнего удаления (помещения в корзину) */
readonly deleted?: string
}

export type Document<T extends DocumentMetaType> = Entity<T> & DocumentFieds

Expand All @@ -102,7 +115,7 @@ export type DocumentExpand<T extends DocumentMetaType> = Pick<
| 'agentAccount'
| 'attributes'
| 'contract'
| 'currency'
| 'rate'
| 'files'
| 'group'
| 'organization'
Expand All @@ -119,7 +132,7 @@ export type DocumentPatch = Partial<
| 'agentAccount'
| 'applicable'
| 'contract'
| 'currency'
| 'rate'
| 'description'
| 'externalCode'
| 'files'
Expand Down
2 changes: 1 addition & 1 deletion src/model/HasAttributes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Attribute } from './Attribute'

export interface HasAttributes {
export type HasAttributes = {
/** Спосок пользовательских полей */
attributes?: Attribute[]
}
2 changes: 1 addition & 1 deletion src/model/HasCreated.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface HasCreated {
export type HasCreated = {
/** Дата создания сущности */
readonly created: string
}
2 changes: 1 addition & 1 deletion src/model/HasDeleted.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface HasDeleted {
export type HasDeleted = {
/** Момент последнего удаления (помещения в корзину) */
readonly deleted?: string
}
3 changes: 1 addition & 2 deletions src/model/HasFiles.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { CollectionRef } from './CollectionRef'
import type { MetaType } from './MetaType'

export interface HasFiles {
export type HasFiles = {
/** Вложенные файлы (максимальное кол-во файлов - 100) */
files?: CollectionRef<'files'>
}
3 changes: 1 addition & 2 deletions src/model/HasProject.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { EntityRef } from './EntityRef'
import type { MetaType } from './MetaType'

export interface HasProject {
export type HasProject = {
project?: EntityRef<'project'>
}
8 changes: 0 additions & 8 deletions src/model/HasRate.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/model/HasState.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { EntityRef } from './EntityRef'
import type { MetaType } from './MetaType'

export interface HasState {
export type HasState = {
/** Статус документа */
state?: EntityRef<'state'>
}
2 changes: 1 addition & 1 deletion src/model/HasStore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { EntityRef } from './EntityRef'

export interface HasStore {
export type HasStore = {
/** Склад */
store?: EntityRef<'store'>
}
2 changes: 1 addition & 1 deletion src/model/HasUpdated.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface HasUpdated {
export type HasUpdated = {
/** Момент последнего обновления */
readonly updated: string
}
10 changes: 0 additions & 10 deletions src/model/HasVat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,3 @@ export type HasVat =
vatIncluded: boolean
vatSum: number
}

export type HasVatPatch =
| {
vatEnabled?: false
}
| {
vatEnabled: true
vatIncluded?: boolean
vatSum?: number
}
6 changes: 3 additions & 3 deletions src/model/Invoice.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type {
DocumentWithPositions,
DocumentWithPositionsPatch,
HasVat,
HasVatPatch
HasVat
} from '.'

export type InvoiceMetaType = 'invoicein' | 'invoiceout'
Expand All @@ -16,10 +15,11 @@ export type InvoiceFields = {
}

export type Invoice<T extends InvoiceMetaType> = DocumentWithPositions<T> &
InvoiceFields &
HasVat

export type InvoicePatch<
T extends InvoiceMetaType
> = DocumentWithPositionsPatch<T> &
Partial<Pick<InvoiceFields, 'paymentPlannedMoment'>> &
HasVatPatch
Partial<HasVat>
12 changes: 7 additions & 5 deletions src/model/Order.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import type {
DocumentWithPositions,
DocumentWithPositionsExpand,
DocumentWithPositionsPatch
} from './DocumentWithPositions'
import type { HasStore } from './HasStore'
DocumentWithPositionsPatch,
EntityRef
} from '.'

export type OrderMetaType = 'customerorder' | 'purchaseorder'

export type OrderFields = {
/** Планируемая дата отгрузки */
deliveryPlannedMoment?: string

/** Склад */
store?: EntityRef<'store'>
}

export type Order<T extends OrderMetaType> = DocumentWithPositions<T> &
HasStore &
OrderFields

export type OrderExpand<T extends OrderMetaType> = Pick<Order<T>, 'store'> &
Expand All @@ -22,4 +24,4 @@ export type OrderExpand<T extends OrderMetaType> = Pick<Order<T>, 'store'> &
export type OrderPatch<
T extends OrderMetaType
> = DocumentWithPositionsPatch<T> &
Partial<Pick<OrderFields, 'deliveryPlannedMoment'>>
Partial<Pick<OrderFields, 'deliveryPlannedMoment' | 'store'>>
Loading

0 comments on commit c3be3ca

Please sign in to comment.