affe6743e5
refs: https://github.com/TryGhost/Team/issues/1145 - this should allow us to remove the /products endpoint in v5 It avoids: - `kg-product-card`, that really is meant to say product - `product-cadence` on offers Co-authored-by: Rishabh <zrishabhgarg@gmail.com>
45 lines
1.2 KiB
JavaScript
45 lines
1.2 KiB
JavaScript
import {paginatedResponse} from '../utils';
|
|
|
|
export default function mockTiers(server) {
|
|
server.post('/tiers/');
|
|
|
|
server.get('/tiers/', paginatedResponse('tiers'));
|
|
|
|
server.get('/tiers/:id/', function ({tiers}, {params}) {
|
|
let {id} = params;
|
|
let tier = tiers.find(id);
|
|
|
|
return tier || new Response(404, {}, {
|
|
errors: [{
|
|
type: 'NotFoundError',
|
|
message: 'Tier not found.'
|
|
}]
|
|
});
|
|
});
|
|
|
|
server.put('/tiers/:id/', function ({tiers, tierBenefits}, {params}) {
|
|
const attrs = this.normalizedRequestAttrs();
|
|
const tier = tiers.find(params.id);
|
|
|
|
const benefitAttrs = attrs.benefits;
|
|
delete attrs.benefits;
|
|
|
|
tier.update(attrs);
|
|
|
|
benefitAttrs.forEach((benefit) => {
|
|
if (benefit.id) {
|
|
const tierBenefit = tierBenefits.find(benefit.id);
|
|
tierBenefit.tier = tier;
|
|
tierBenefit.save();
|
|
} else {
|
|
tier.createTierBenefit(benefit);
|
|
tier.save();
|
|
}
|
|
});
|
|
|
|
return tier.save();
|
|
});
|
|
|
|
server.del('/tiers/:id/');
|
|
}
|