Ghost/ghost/admin/mirage/config/products.js
Kevin Ansfield 6b6f220300 Fixed tests
no issue

- added basic products mocked endpoint
- fixed error when extracting filter param when filter is empty
2021-05-10 21:02:54 +01:00

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/');
}