mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-25 19:48:50 +03:00
36ba447de0
refs 2bf311edc8
- added missing relationship definitions for included relationships on member model
- cleaned up unnecessary forcing of `id: 99` when creating new records of some models
45 lines
1.2 KiB
JavaScript
45 lines
1.2 KiB
JavaScript
import {paginatedResponse} from '../utils';
|
|
|
|
export default function mockProducts(server) {
|
|
server.post('/products/');
|
|
|
|
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/', function ({products, productBenefits}, {params}) {
|
|
const attrs = this.normalizedRequestAttrs();
|
|
const product = products.find(params.id);
|
|
|
|
const benefitAttrs = attrs.benefits;
|
|
delete attrs.benefits;
|
|
|
|
product.update(attrs);
|
|
|
|
benefitAttrs.forEach((benefit) => {
|
|
if (benefit.id) {
|
|
const productBenefit = productBenefits.find(benefit.id);
|
|
productBenefit.product = product;
|
|
productBenefit.save();
|
|
} else {
|
|
product.createProductBenefit(benefit);
|
|
product.save();
|
|
}
|
|
});
|
|
|
|
return product.save();
|
|
});
|
|
|
|
server.del('/products/:id/');
|
|
}
|