Ghost/ghost/admin/mirage/config/invites.js
Kevin Ansfield cb59388c5b 💄🐷 sort-imports eslint rule (#712)
no issue

- adds `eslint-plugin-sort-imports-es6-autofix` dependency
  - implements ESLint's base `sort-imports` rule but has a distinction in that `import {foo} from 'bar';` is considered `multiple` rather than `single`
  - fixes ESLint's autofix behaviour so `eslint --fix` will actually fix the sort order
- updates all unordered import rules by using `eslint --fix`

With the increased number of `import` statements since Ember+ecosystem started moving towards es6 modules I've found it frustrating at times trying to search through randomly ordered import statements. Recently I've been sorting imports manually when I've added new code or touched old code so I thought I'd add an ESLint rule to codify it.
2017-05-29 20:50:03 +02:00

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: [{
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').valueOf();
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/');
}