2020-02-14 12:34:01 +03:00
|
|
|
import Model, {attr, hasMany} from '@ember-data/model';
|
2019-11-28 14:30:21 +03:00
|
|
|
import ValidationEngine from 'ghost-admin/mixins/validation-engine';
|
2019-01-22 20:18:44 +03:00
|
|
|
|
2019-11-28 14:30:21 +03:00
|
|
|
export default Model.extend(ValidationEngine, {
|
|
|
|
validationType: 'member',
|
|
|
|
|
2019-01-22 20:18:44 +03:00
|
|
|
name: attr('string'),
|
|
|
|
email: attr('string'),
|
2019-10-10 14:59:35 +03:00
|
|
|
note: attr('string'),
|
2019-11-28 14:30:21 +03:00
|
|
|
createdAtUTC: attr('moment-utc'),
|
2019-11-05 14:00:07 +03:00
|
|
|
stripe: attr('member-subscription'),
|
2020-01-28 07:27:19 +03:00
|
|
|
subscribed: attr('boolean', {defaultValue: true}),
|
2020-02-14 12:34:01 +03:00
|
|
|
labels: hasMany('label', {embedded: 'always', async: false}),
|
|
|
|
comped: attr('boolean', {defaultValue: false}),
|
|
|
|
// remove client-generated labels, which have `id: null`.
|
|
|
|
// Ember Data won't recognize/update them automatically
|
|
|
|
// when returned from the server with ids.
|
|
|
|
// https://github.com/emberjs/data/issues/1829
|
|
|
|
updateLabels() {
|
|
|
|
let labels = this.labels;
|
|
|
|
let oldLabels = labels.filterBy('id', null);
|
|
|
|
|
|
|
|
labels.removeObjects(oldLabels);
|
|
|
|
oldLabels.invoke('deleteRecord');
|
|
|
|
}
|
2019-01-22 20:18:44 +03:00
|
|
|
});
|