mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-23 02:41:50 +03:00
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/');
|
||
|
}
|