-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathperson.ts
37 lines (27 loc) · 1.04 KB
/
person.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { computed, get } from '@ember/object';
import DS from 'ember-data';
export default class Person extends DS.Model.extend({
name: DS.attr(),
email: DS.attr('string'),
mobile: DS.attr('string'),
landline: DS.attr('string'),
medium: DS.attr('string'),
active: DS.attr('boolean', { defaultValue: true }),
notes: DS.attr('string'),
selfNotes: DS.attr('string'),
reimbursements: DS.hasMany('reimbursement'),
drivings: DS.hasMany('ride', {inverse: 'driver'}),
carOwnings: DS.hasMany('ride', {inverse: 'carOwner'}),
lastRide: computed('drivings.@each.start', function() {
return this.get('drivings').sortBy('start').get('lastObject');
}),
calendarSecret: DS.attr('string'),
validationErrors: computed('errors.[]', function() {
const attributes = get(this.constructor, 'attributes');
return attributes._keys.list.reduce((response: ValidationDictionary, key: string) => {
const errors = this.get(`errors.${key}`) || [];
response[key] = errors.mapBy('message');
return response;
}, {});
})
}) {}