UNPKG

amocrm-client

Version:
105 lines (79 loc) 3.15 kB
import { Type, Transform, Expose, plainToClassFromExist } from 'class-transformer'; import { ICustomFieldValue } from '../interfaces/custom_field'; import { ILeadEmbedded, ILossReason, ILeadAttributes } from '../interfaces/lead'; import ResourceEntity from '../api/ResourceEntity'; import { ILeadFactory } from '../api/factories/LeadFactory'; import { SelfLinkDTO } from './link.dto'; import { ResourceCollection } from '../api/ResourceCollection'; import { ITag } from '../api/models/Tag'; import { ICompany } from '../api/models/Company'; import { Contact, IContact } from '../api/models/Contact'; import { IResourceEntity, IResourceFactory } from '../interfaces/api'; import { TFactoryConstructor } from '../types'; import { ContactFactory } from '../api/factories/ContactFactory'; import { CollectionType, DateType } from '../util'; import { Moment } from '../interfaces/common'; import { CustomFieldDTO, CustomFieldValueDTO } from './custom_fields/field.dto'; import { CatalogElementFactory } from '../api/factories/CatalogElementFactory'; import { ICatalogElement } from '../api/models/CatalogElement'; import { ResourceEntityEmbedded } from '../api/ResourceEntityEmbedded'; @Expose() class LeadEmbeddedDTO extends ResourceEntityEmbedded<ILeadFactory, ILeadEmbedded> implements ILeadEmbedded { tags: ITag[]; companies: ICompany[]; @CollectionType() catalog_elements?: ICatalogElement[]; @CollectionType() loss_reason?: LossReasonDTO[]; @CollectionType() contacts?: IContact[]; constructor(factory: ILeadFactory, attributes: ILeadEmbedded) { super(factory, attributes); this.contacts = this.parseEmbedded(attributes?.contacts, ContactFactory); this.catalog_elements = this.parseEmbedded(attributes.catalog_elements, CatalogElementFactory); } } @Expose() export class LeadDTO extends ResourceEntity<ILeadFactory> implements ILeadAttributes { id: number; name: string; price: number; status_id: number; pipeline_id: number; loss_reason_id: number; responsible_user_id: number; group_id: number; is_deleted: boolean; score: number | null; is_price_modified_by_robot?: boolean; source_id?: string; request_id?: string; @CollectionType() custom_fields_values: CustomFieldValueDTO[]; @Type(() => LeadEmbeddedDTO) _embedded: LeadEmbeddedDTO; created_by: number; updated_by: number; @DateType() created_at: Date; @DateType() updated_at: Date; @DateType() closed_at: Date; @DateType() closest_task_at: Date; account_id: number | undefined; _links: SelfLinkDTO; constructor(factory: ILeadFactory, attributes: ILeadAttributes) { super(factory, attributes); if (attributes._embedded) this._embedded = new LeadEmbeddedDTO(factory, attributes._embedded); } } class LossReasonDTO implements ILossReason { id: number; name: string; sort: number; created_at: Date; updated_at: Date; _links: SelfLinkDTO; }