import { HALConfig } from '../hal.config'; import { LeadConverter } from './lead.converter'; import { LeadCollection } from './lead.collection'; export class LeadCollectionConverter { public constructor(private leadConverter: LeadConverter) {} public toCollection(json: any): LeadCollection { const collection: LeadCollection = new LeadCollection(); collection.total = json['total']; collection.count = json['count']; collection.unassignedTotal = json['total_unassigned']; collection.stageCount = { new: json['new'], decision: json['decision'], payment: json['payment'], rejected: json['rejected'], checkup: json['checkup'], won: json['won'], }; if (json[HALConfig.embedded] && json[HALConfig.embedded]['leads']) { collection.leads = this.leadConverter.toMany(json[HALConfig.embedded]['leads']); } return collection; } }