mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-05 09:50:34 +03:00
a7f4610381
no issue `ember-light-table` is falling behind Ember.js and other addon development and is increasingly causing issues with Ember deprecations and addon incompatibility. - swaps `ember-light-table` usage for a straightforward table using `vertical-collection` for occlusion - uses the same loading mechanism as the members screen with a slight optimisation where the initial load will fetch subscribers in batches of 200 until they are all loaded - removes now-unused pagination mixin - fixes duplicate subscriber validation handling
51 lines
1.5 KiB
JavaScript
51 lines
1.5 KiB
JavaScript
/* eslint-disable camelcase */
|
|
import {Response} from 'ember-cli-mirage';
|
|
import {paginatedResponse} from '../utils';
|
|
|
|
export default function mockSubscribers(server) {
|
|
server.get('/subscribers/', paginatedResponse('subscribers'));
|
|
|
|
server.post('/subscribers/', function ({subscribers}) {
|
|
let attrs = this.normalizedRequestAttrs();
|
|
let subscriber = subscribers.findBy({email: attrs.email});
|
|
|
|
if (subscriber) {
|
|
return new Response(422, {}, {
|
|
errors: [{
|
|
type: 'ValidationError',
|
|
message: 'Validation error, cannot save subscriber.',
|
|
context: 'Email address is already subscribed.',
|
|
property: null
|
|
}]
|
|
});
|
|
} else {
|
|
attrs.createdAt = new Date();
|
|
attrs.createdBy = 0;
|
|
|
|
return subscribers.create(attrs);
|
|
}
|
|
});
|
|
|
|
server.put('/subscribers/:id/');
|
|
|
|
server.post('/subscribers/csv/', function () {
|
|
// NB: we get a raw FormData object with no way to inspect it in Chrome
|
|
// until version 50 adds the additional read methods
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/FormData#Browser_compatibility
|
|
|
|
server.createList('subscriber', 50);
|
|
|
|
return {
|
|
meta: {
|
|
stats: {
|
|
imported: 50,
|
|
duplicates: 3,
|
|
invalid: 2
|
|
}
|
|
}
|
|
};
|
|
});
|
|
|
|
server.del('/subscribers/:id/');
|
|
}
|