2020-06-19 08:43:22 +02:00
|
|
|
import _ from 'lodash';
|
|
|
|
import {IdModel} from './id.model';
|
|
|
|
import {MaterialModel} from './material.model';
|
|
|
|
import {MeasurementModel} from './measurement.model';
|
2020-06-22 10:22:45 +02:00
|
|
|
import {BaseModel} from './base.model';
|
2020-06-19 08:43:22 +02:00
|
|
|
|
2020-06-22 10:22:45 +02:00
|
|
|
export class SampleModel extends BaseModel {
|
2020-06-19 08:43:22 +02:00
|
|
|
_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']);
|
|
|
|
}
|
|
|
|
}
|