Skip to content

Commit

Permalink
feat: работа над моделью
Browse files Browse the repository at this point in the history
- изменение MetaType на Union из строк
- добавление срезов полей сущностей для преобразований с Expand и Patch
- описание точек доступа API по методам
- доработка Expand
- изменение Patch на более простую структуру
- прочие доработки и тестирование
  • Loading branch information
wmakeev committed Jul 14, 2021
1 parent cb45690 commit f934867
Show file tree
Hide file tree
Showing 58 changed files with 1,140 additions and 469 deletions.
7 changes: 7 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@
```ts
Expand<CustomerOrder, 'agent.group,state'>
```
- [ ] Подумать как работать с обобщенными запросами

```ts
ms.GET(nextHref, query)
```

- [ ] Нужен еще один слой Create как и для Patch?
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.1.9",
"version": "0.2.0",
"description": "Объектная модель API МойСклад для TypeScript проектов",
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
Expand Down
31 changes: 0 additions & 31 deletions src/api.ts

This file was deleted.

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

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

Expand Down
4 changes: 2 additions & 2 deletions src/model/Address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type { MetaType } from './MetaType'
export interface Address {
postalCode?: string

country?: EntityRef<MetaType.Country>
country?: EntityRef<'country'>

region?: EntityRef<MetaType.Region>
region?: EntityRef<'region'>

city?: string

Expand Down
6 changes: 1 addition & 5 deletions src/model/Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ import type { Entity } from './Entity'
import type { HasAttributes } from './HasAttributes'
import type { HasCreated } from './HasCreated'
import type { HasUpdated } from './HasUpdated'
import type { MetaType } from './MetaType'
import type { Owned } from './Owned'

export type AgentMetaType =
| MetaType.Employee
| MetaType.Counterparty
| MetaType.Organization
export type AgentMetaType = 'employee' | 'counterparty' | 'organization'

export interface Agent<T extends AgentMetaType>
extends Entity<T>,
Expand Down
6 changes: 3 additions & 3 deletions src/model/AgentNote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import type { EntityRef } from './EntityRef'
import type { HasCreated } from './HasCreated'
import type { MetaType } from './MetaType'

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

agent: EntityRef<MetaType.Counterparty>
agent: EntityRef<'counterparty'>

author: EntityRef<MetaType.Employee>
author: EntityRef<'employee'>
}
26 changes: 15 additions & 11 deletions src/model/Attribute.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Entity } from './Entity'
import type { EntityRef } from './EntityRef'
import type { EntityPatchRef, EntityRef } from './EntityRef'
import type { MediaType } from './MediaType'
import type { MetaType } from './MetaType'

export enum AttributeType {
// Base type
Expand Down Expand Up @@ -39,22 +38,22 @@ export type AttributeJsTypeMap = {
[AttributeType.Link]: string

// Embedded entity
[AttributeType.Organization]: EntityRef<MetaType.Organization>
[AttributeType.Counterparty]: EntityRef<MetaType.Counterparty>
[AttributeType.Employee]: EntityRef<MetaType.Employee>
[AttributeType.Contract]: EntityRef<MetaType.Contract>
[AttributeType.Product]: EntityRef<MetaType.Product>
[AttributeType.Project]: EntityRef<MetaType.Project>
[AttributeType.Store]: EntityRef<MetaType.Store>
[AttributeType.Organization]: EntityRef<'organization'>
[AttributeType.Counterparty]: EntityRef<'counterparty'>
[AttributeType.Employee]: EntityRef<'employee'>
[AttributeType.Contract]: EntityRef<'contract'>
[AttributeType.Product]: EntityRef<'product'>
[AttributeType.Project]: EntityRef<'project'>
[AttributeType.Store]: EntityRef<'store'>

// Custom entity
[AttributeType.CustomEntity]: EntityRef<MetaType.CustomEntity> & {
[AttributeType.CustomEntity]: EntityRef<'customentity'> & {
readonly name: string
}
}

export interface AttributeBase<T extends AttributeType = AttributeType>
extends Entity<MetaType.AttributeMetadata> {
extends Entity<'attributemetadata'> {
/** Наименование пользовательского поля */
readonly name: string

Expand All @@ -74,3 +73,8 @@ export type Attribute<
}
}
: AttributeBase<T>

export type AttributePatch<T extends AttributeType = AttributeType> = Partial<
Pick<Attribute<T>, 'value'>
> &
EntityPatchRef<'attributemetadata'>
5 changes: 5 additions & 0 deletions src/model/CashIn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { FinanceIn, FinanceInPatch } from './FinanceIn'

export type CashIn = FinanceIn<'cashin'>

export type CashInPatch = FinanceInPatch
5 changes: 5 additions & 0 deletions src/model/CashOut.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { FinanceOut, FinanceOutPatch } from './FinanceOut'

export type CashOut = FinanceOut<'cashout'>

export type CashOutPatch = FinanceOutPatch
6 changes: 3 additions & 3 deletions src/model/Company.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { CollectionRef } from './CollectionRef'
import type { EntityRef } from './EntityRef'
import type { MetaType } from './MetaType'

export type CompanyMetaType = MetaType.Counterparty | MetaType.Organization
export type CompanyMetaType = 'counterparty' | 'organization'

export enum CompanyType {
Legal = 'legal',
Expand All @@ -13,7 +13,7 @@ export enum CompanyType {
}

export interface CompanyDiscountData {
discount: EntityRef<MetaType.Discount>
discount: EntityRef<'discount'>

personalDiscount: number // double

Expand All @@ -28,7 +28,7 @@ export interface Company<T extends CompanyMetaType> extends Agent<T> {
| CompanyType.Legal

/** Счета */
accounts: CollectionRef<MetaType.Account>
accounts: CollectionRef<'account'>

/** Полное наименование */
legalTitle?: string
Expand Down
6 changes: 2 additions & 4 deletions src/model/ContactPerson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import type { EntityRef } from './EntityRef'
import type { HasUpdated } from './HasUpdated'
import type { MetaType } from './MetaType'

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

Expand All @@ -21,5 +19,5 @@ export interface ContactPerson

position?: string

agent: EntityRef<MetaType.Counterparty>
agent: EntityRef<'counterparty'>
}
8 changes: 4 additions & 4 deletions src/model/Counterparty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import type { MetaType } from './MetaType'
import type { Person } from './Person'
import type { PriceType } from './PriceType'

export interface CounterpartyBase extends Company<MetaType.Counterparty> {
export interface CounterpartyBase extends Company<'counterparty'> {
/** Статус */
state: EntityRef<MetaType.State>
state: EntityRef<'state'>

/** Группы (теги) */
tags: string[]

/** Контактные лица */
contactpersons: CollectionRef<MetaType.ContactPerson>
contactpersons: CollectionRef<'contactperson'>

/** События */
notes: EntityRef<MetaType.Note>
notes: EntityRef<'note'>

/** Номер дисконтной карты */
discountCardNumber?: string
Expand Down
45 changes: 26 additions & 19 deletions src/model/CustomerOrder.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
import type { EntityRef } from './EntityRef'
import type { HasVat } from './HasVat'
import type { MetaType } from './MetaType'
import type { Order, OrderExpand } from './Order'
import type { TaxSystem } from './TaxSystem'
import type {
EntityRef,
HasVat,
Order,
OrderExpand,
OrderPatch,
TaxSystem
} from '.'

export type CustomerOrder = Order<MetaType.CustomerOrder> &
HasVat & {
taxSystem?: TaxSystem
export type CustomerOrderFields = HasVat & {
taxSystem?: TaxSystem

readonly reservedSum: number
readonly reservedSum: number

purchaseOrders?: EntityRef<MetaType.PurchaseOrder>[]
purchaseOrders?: EntityRef<'purchaseorder'>[]

// TODO Проверить связи (нет в документации?)
// TODO Проверить связи (нет в документации?)

readonly shippedSum: number
demands?: EntityRef<MetaType.Demand>[]
readonly shippedSum: number
demands?: EntityRef<'demand'>[]

readonly invoicedSum: number
invoicesOut?: EntityRef<MetaType.InvoiceOut>[]
readonly invoicedSum: number
invoicesOut?: EntityRef<'invoiceout'>[]

readonly payedSum: number
payments?: EntityRef<MetaType.PaymentOut | MetaType.PaymentIn>[]
}
readonly payedSum: number
payments?: EntityRef<'paymentout' | 'paymentin'>[]
}

export type CustomerOrder = Order<'customerorder'> & CustomerOrderFields

export type CustomerOrderExpand = Pick<
CustomerOrder,
'purchaseOrders' | 'demands' | 'invoicesOut' | 'payments'
> &
OrderExpand<MetaType.CustomerOrder>
OrderExpand<'customerorder'>

export type CustomerOrderPatch = OrderPatch<'customerorder'> &
Partial<Pick<CustomerOrderFields, 'taxSystem'>>
18 changes: 14 additions & 4 deletions src/model/CustomerOrderPosition.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import type { MetaType } from './MetaType'
import type { Position } from './Position'
import type { Position, PositionPatch } from './Position'

export interface CustomerOrderPosition
extends Position<MetaType.CustomerOrderPosition> {
export type CustomerOrderPositionFields = {
/**
* НДС
*/
vat: number

shipped: number

/**
* Зарезервированное кол-во товара в позиции
*/
reserve: number
}

export type CustomerOrderPosition = Position<'customerorderposition'> &
CustomerOrderPositionFields

export type CustomerOrderPositionPatch = PositionPatch<'customerorderposition'> &
Partial<Pick<CustomerOrderPositionFields, 'vat' | 'reserve' | 'shipped'>>
2 changes: 1 addition & 1 deletion src/model/Demand.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import type { DocumentWithPositions, HasVat, MetaType } from '.'

export type Demand = DocumentWithPositions<MetaType.Demand> & HasVat
export type Demand = DocumentWithPositions<'demand'> & HasVat
5 changes: 2 additions & 3 deletions src/model/Discount.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { Entity } from './Entity'
import type { EntityRef } from './EntityRef'
import type { MetaType } from './MetaType'

export interface Discount extends Entity<MetaType.Discount> {
export interface Discount extends Entity<'discount'> {
name: string

active: boolean
Expand All @@ -11,5 +10,5 @@ export interface Discount extends Entity<MetaType.Discount> {

agentTags: string[]

assortment?: EntityRef<MetaType.Product>[] // TODO Проверить
assortment?: EntityRef<'product'>[] // TODO Проверить
}
Loading

0 comments on commit f934867

Please sign in to comment.