mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-28 21:33:24 +03:00
c4c48d4104
refs https://github.com/TryGhost/Admin/pull/2209 - `miragejs` has been extracted to a framework-independent library, the re-exports of `miragejs` elements in `ember-cli-mirage` have been deprecated making our test logs very noisy - added `miragejs` as a top-level dependency - updated all relevant imports to pull from `miragejs` instead of `ember-cli-mirage`
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
import moment from 'moment';
|
|
import {Response} from 'miragejs';
|
|
import {paginatedResponse} from '../utils';
|
|
|
|
export default function mockInvites(server) {
|
|
server.get('/invites/', paginatedResponse('invites'));
|
|
|
|
server.get('/invites/:id', function (schema, request) {
|
|
let {id} = request.params;
|
|
let invite = schema.invites.find(id);
|
|
|
|
return invite || new Response(404, {}, {
|
|
errors: [{
|
|
type: 'NotFoundError',
|
|
message: 'Invite not found.'
|
|
}]
|
|
});
|
|
});
|
|
|
|
server.post('/invites/', function ({invites}) {
|
|
let attrs = this.normalizedRequestAttrs();
|
|
let oldInvite = invites.findBy({email: attrs.email});
|
|
|
|
if (oldInvite) {
|
|
oldInvite.destroy();
|
|
}
|
|
|
|
/* eslint-disable camelcase */
|
|
attrs.token = `${invites.all().models.length}-token`;
|
|
attrs.expires = moment.utc().add(1, 'day').valueOf();
|
|
attrs.createdAt = moment.utc().format();
|
|
attrs.createdBy = 1;
|
|
attrs.updatedAt = moment.utc().format();
|
|
attrs.updatedBy = 1;
|
|
attrs.status = 'sent';
|
|
/* eslint-enable camelcase */
|
|
|
|
return invites.create(attrs);
|
|
});
|
|
|
|
server.del('/invites/:id/');
|
|
}
|