52b6668955
- remove lodash from bower - move all resources to /mirage instead of /app/mirage - update endpoints to use ORM - general cleanup
37 lines
1.0 KiB
JavaScript
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/');
|
|
}
|