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';
|
2020-02-27 06:50:15 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
import {task} from 'ember-concurrency';
|
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}),
|
2020-02-27 15:56:26 +03:00
|
|
|
geolocation: attr('json-string'),
|
2020-02-27 06:50:15 +03:00
|
|
|
|
|
|
|
ghostPaths: service(),
|
|
|
|
ajax: service(),
|
|
|
|
|
2020-02-14 12:34:01 +03:00
|
|
|
// 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');
|
2020-02-27 06:50:15 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
fetchSigninUrl: task(function* () {
|
|
|
|
let url = this.get('ghostPaths.url').api('members', this.get('id'), 'signin_urls');
|
|
|
|
|
|
|
|
let response = yield this.ajax.request(url);
|
|
|
|
|
|
|
|
return response.member_signin_urls[0];
|
|
|
|
}).drop()
|
2019-01-22 20:18:44 +03:00
|
|
|
});
|