mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-29 13:52:10 +03:00
696d8e3c49
no-issue This was also missing as part of the Offers API.
79 lines
1.8 KiB
JavaScript
79 lines
1.8 KiB
JavaScript
const tpl = require('@tryghost/tpl');
|
|
const errors = require('@tryghost/errors');
|
|
const offersService = require('../../services/offers');
|
|
|
|
const messages = {
|
|
offerNotFound: 'Offer not found.'
|
|
};
|
|
|
|
module.exports = {
|
|
docName: 'offers',
|
|
|
|
browse: {
|
|
options: [
|
|
'filter'
|
|
],
|
|
permissions: true,
|
|
async query(frame) {
|
|
const offers = await offersService.api.listOffers(frame.options);
|
|
frame.response = {
|
|
offers
|
|
};
|
|
}
|
|
},
|
|
|
|
read: {
|
|
data: ['id'],
|
|
permissions: true,
|
|
async query(frame) {
|
|
const offer = await offersService.api.getOffer(frame.data);
|
|
if (!offer) {
|
|
throw new errors.NotFoundError({
|
|
message: tpl(messages.offerNotFound)
|
|
});
|
|
}
|
|
|
|
frame.response = {
|
|
offers: [offer]
|
|
};
|
|
}
|
|
},
|
|
|
|
edit: {
|
|
options: ['id'],
|
|
permissions: true,
|
|
headers: {
|
|
cacheInvalidate: true
|
|
},
|
|
async query(frame) {
|
|
const offer = await offersService.api.updateOffer({
|
|
...frame.data.offers[0],
|
|
id: frame.options.id
|
|
});
|
|
|
|
if (!offer) {
|
|
throw new errors.NotFoundError({
|
|
message: tpl(messages.offerNotFound)
|
|
});
|
|
}
|
|
|
|
frame.response = {
|
|
offers: [offer]
|
|
};
|
|
}
|
|
},
|
|
|
|
add: {
|
|
permissions: true,
|
|
headers: {
|
|
cacheInvalidate: true
|
|
},
|
|
async query(frame) {
|
|
const offer = await offersService.api.createOffer(frame.data.offers[0]);
|
|
frame.response = {
|
|
offers: [offer]
|
|
};
|
|
}
|
|
}
|
|
};
|