Ghost/ghost/admin/mirage/config/invites.js
Austin Burdine 52b6668955 deps: ember-cli-mirage@0.2.0
- remove lodash from bower
- move all resources to /mirage instead of /app/mirage
- update endpoints to use ORM
- general cleanup
2017-01-13 15:59:37 +00:00

42 lines
1.2 KiB
JavaScript

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: [{
errorType: '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').unix();
attrs.created_at = moment.utc().format();
attrs.created_by = 1;
attrs.updated_at = moment.utc().format();
attrs.updated_by = 1;
attrs.status = 'sent';
/* eslint-enable camelcase */
return invites.create(attrs);
});
server.del('/invites/:id/');
}