import _ from 'lodash'; import {Deserializable} from './deserializable.model'; import {IdModel} from './id.model'; import {SendFormat} from './sendformat.model'; import {MaterialModel} from './material.model'; import {MeasurementModel} from './measurement.model'; export class SampleModel implements Deserializable, SendFormat { _id: IdModel = null; color = ''; number = ''; type = ''; batch = ''; condition: {condition_template: string, [prop: string]: string} | {} = {}; material_id: IdModel = null; material: MaterialModel; measurements: MeasurementModel[]; note_id: IdModel = null; user_id: IdModel = null; notes: {comment: string, sample_references: {sample_id: IdModel, relation: string}[], custom_fields: {[prop: string]: string}} = {comment: '', sample_references: [], custom_fields: {}}; deserialize(input: any): this { Object.assign(this, input); if (input.hasOwnProperty('material')) { this.material = new MaterialModel().deserialize(input.material); this.material_id = input.material._id; } if (input.hasOwnProperty('measurements')) { this.measurements = input.measurements.map(e => new MeasurementModel().deserialize(e)); } return this; } sendFormat() { return _.pick(this, ['color', 'type', 'batch', 'condition', 'material_id', 'notes']); } }