0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00
ghost/core/server/api/canary/offers-public.js
Rishabh Garg 725c2673ea
Added offer read endpoint to content API (#14794)
refs TryGhost/Team#1599

- allows offer details to be fetched via content API directly
2022-05-12 18:16:10 +05:30

28 lines
669 B
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',
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]
};
}
}
};