Ghost/ghost/admin/mirage/config/users.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

37 lines
1.0 KiB
JavaScript

export default function mockUsers(server) {
// /users/me = Always return the user with ID=1
server.get('/users/me/', function ({users}) {
return users.find(1);
});
server.get('/users/');
server.get('/users/slug/:slug/', function ({users}, {params, queryParams}) {
let user = users.findBy({slug: params.slug});
user.postCount = queryParams.include.match(/count\.posts/);
return user;
});
server.get('/users/:id', function ({users}, {params, queryParams}) {
let user = users.find(params.id);
user.postCount = queryParams.include.match(/count\.posts/);
return user;
});
server.put('/users/:id/', function ({users}, {params}) {
let {id} = params;
if (id === 'password') {
return {
password: [{message: 'Password changed successfully.'}]
};
} else {
let attrs = this.normalizedRequestAttrs();
return users.find(id).update(attrs);
}
});
server.del('/users/:id/');
}