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'),
|
2021-08-10 15:13:36 +03:00
|
|
|
status: attr('string'),
|
2019-11-28 14:30:21 +03:00
|
|
|
createdAtUTC: attr('moment-utc'),
|
2022-02-22 20:13:32 +03:00
|
|
|
lastSeenAtUTC: attr('moment-utc'),
|
2021-02-06 22:51:31 +03:00
|
|
|
subscriptions: attr('member-subscription'),
|
2022-08-19 23:39:18 +03:00
|
|
|
attribution: attr(),
|
2020-01-28 07:27:19 +03:00
|
|
|
subscribed: attr('boolean', {defaultValue: true}),
|
2020-02-14 12:34:01 +03:00
|
|
|
comped: attr('boolean', {defaultValue: false}),
|
2020-02-27 15:56:26 +03:00
|
|
|
geolocation: attr('json-string'),
|
2020-12-10 13:15:42 +03:00
|
|
|
emailCount: attr('number', {defaultValue: 0}),
|
|
|
|
emailOpenedCount: attr('number', {defaultValue: 0}),
|
2020-12-08 22:23:57 +03:00
|
|
|
emailOpenRate: attr('number'),
|
2022-05-09 15:29:45 +03:00
|
|
|
avatarImage: attr('string'),
|
2020-02-27 06:50:15 +03:00
|
|
|
|
2022-05-11 20:11:54 +03:00
|
|
|
tiers: attr('member-tier'),
|
2022-04-14 17:40:04 +03:00
|
|
|
newsletters: hasMany('newsletter', {embedded: 'always', async: false}),
|
2022-11-18 14:55:21 +03:00
|
|
|
emailSuppression: attr(),
|
2021-04-26 19:28:39 +03:00
|
|
|
|
2020-12-10 14:38:38 +03:00
|
|
|
labels: hasMany('label', {embedded: 'always', async: false}),
|
|
|
|
|
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* () {
|
2022-01-21 22:25:47 +03:00
|
|
|
let url = this.get('ghostPaths.url').api('members', this.id, 'signin_urls');
|
2020-02-27 06:50:15 +03:00
|
|
|
|
|
|
|
let response = yield this.ajax.request(url);
|
|
|
|
|
|
|
|
return response.member_signin_urls[0];
|
|
|
|
}).drop()
|
2019-01-22 20:18:44 +03:00
|
|
|
});
|