mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-23 10:53:34 +03:00
6b6f220300
no issue - added basic products mocked endpoint - fixed error when extracting filter param when filter is empty
28 lines
738 B
JavaScript
28 lines
738 B
JavaScript
import {paginatedResponse} from '../utils';
|
|
|
|
export default function mockProducts(server) {
|
|
server.post('/products/', function ({products}) {
|
|
let attrs = this.normalizedRequestAttrs();
|
|
|
|
return products.create(Object.assign({}, attrs, {id: 99}));
|
|
});
|
|
|
|
server.get('/products/', paginatedResponse('products'));
|
|
|
|
server.get('/products/:id/', function ({products}, {params}) {
|
|
let {id} = params;
|
|
let product = products.find(id);
|
|
|
|
return product || new Response(404, {}, {
|
|
errors: [{
|
|
type: 'NotFoundError',
|
|
message: 'Product not found.'
|
|
}]
|
|
});
|
|
});
|
|
|
|
server.put('/products/:id/');
|
|
|
|
server.del('/products/:id/');
|
|
}
|