mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
refs https://github.com/TryGhost/Team/issues/1240 We were selectively invalidating cache on tier/product edit which was consistent with pattern for other APIs, but in case of tier/product, the model changed method always returns false due to how its setup. This change updates the edit to always invalidate cache, similar to tier add, to ensure sites don't see old tier values.
120 lines
2.6 KiB
JavaScript
120 lines
2.6 KiB
JavaScript
const errors = require('@tryghost/errors');
|
|
const membersService = require('../../services/members');
|
|
|
|
const tpl = require('@tryghost/tpl');
|
|
|
|
const allowedIncludes = ['monthly_price', 'yearly_price', 'benefits'];
|
|
|
|
const messages = {
|
|
productNotFound: 'Tier not found.'
|
|
};
|
|
|
|
module.exports = {
|
|
docName: 'tiers',
|
|
|
|
browse: {
|
|
options: [
|
|
'limit',
|
|
'fields',
|
|
'include',
|
|
'filter',
|
|
'order',
|
|
'debug',
|
|
'page'
|
|
],
|
|
permissions: {
|
|
docName: 'products'
|
|
},
|
|
validation: {
|
|
options: {
|
|
include: {
|
|
values: allowedIncludes
|
|
}
|
|
}
|
|
},
|
|
async query(frame) {
|
|
const page = await membersService.api.productRepository.list(frame.options);
|
|
|
|
return page;
|
|
}
|
|
},
|
|
|
|
read: {
|
|
options: [
|
|
'include'
|
|
],
|
|
headers: {},
|
|
data: [
|
|
'id'
|
|
],
|
|
validation: {
|
|
options: {
|
|
include: {
|
|
values: allowedIncludes
|
|
}
|
|
}
|
|
},
|
|
permissions: true,
|
|
async query(frame) {
|
|
const model = await membersService.api.productRepository.get(frame.data, frame.options);
|
|
|
|
if (!model) {
|
|
throw new errors.NotFoundError({
|
|
message: tpl(messages.productNotFound)
|
|
});
|
|
}
|
|
|
|
return model;
|
|
}
|
|
},
|
|
|
|
add: {
|
|
statusCode: 201,
|
|
headers: {
|
|
cacheInvalidate: true
|
|
},
|
|
validation: {
|
|
data: {
|
|
name: {required: true}
|
|
}
|
|
},
|
|
permissions: {
|
|
docName: 'products'
|
|
},
|
|
async query(frame) {
|
|
const model = await membersService.api.productRepository.create(
|
|
frame.data,
|
|
frame.options
|
|
);
|
|
return model;
|
|
}
|
|
},
|
|
|
|
edit: {
|
|
statusCode: 200,
|
|
options: [
|
|
'id'
|
|
],
|
|
headers: {
|
|
cacheInvalidate: true
|
|
},
|
|
validation: {
|
|
options: {
|
|
id: {
|
|
required: true
|
|
}
|
|
}
|
|
},
|
|
permissions: {
|
|
docName: 'products'
|
|
},
|
|
async query(frame) {
|
|
const model = await membersService.api.productRepository.update(
|
|
frame.data,
|
|
frame.options
|
|
);
|
|
|
|
return model;
|
|
}
|
|
}
|
|
};
|