mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-29 13:52:10 +03:00
d0a834b477
no issue - updates error handling to work with new v2 error response formats - `.errorType` -> `.error` - `.errorDetails` -> `.details`
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
import moment from 'moment';
|
|
import {Response} from 'ember-cli-mirage';
|
|
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/');
|
|
}
|