Added new offers endpoint on members API

refs https://github.com/TryGhost/Team/issues/1138

Portal offer urls use offer id to load offer details UI and stripe checkout in frontend. This endpoint allows portal to fetch offer details from offer id to create Portal UI with relevant details for potential members.
This commit is contained in:
Rishabh Garg 2021-10-15 11:46:27 +05:30 committed by GitHub
parent b286142a6b
commit 7270baa99c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -1,6 +1,7 @@
const _ = require('lodash');
const logging = require('@tryghost/logging');
const membersService = require('./service');
const offersService = require('../offers/service');
const urlUtils = require('../../../shared/url-utils');
const ghostVersion = require('@tryghost/version');
const settingsCache = require('../../../shared/settings-cache');
@ -58,6 +59,14 @@ const getMemberData = async function (req, res) {
}
};
const getOfferData = async function (req, res) {
const offerId = req.params.id;
const offer = await offersService.api.getOffer({id: offerId});
return res.json({
offers: [offer]
});
};
const updateMemberData = async function (req, res) {
try {
const data = _.pick(req.body, 'name', 'subscribed');
@ -222,6 +231,7 @@ module.exports = {
createSessionFromMagicLink,
getIdentityToken,
getMemberData,
getOfferData,
updateMemberData,
getMemberSiteData,
deleteSession,

View File

@ -37,6 +37,7 @@ module.exports = function setupMembersApp() {
membersApp.put('/api/member', bodyParser.json({limit: '1mb'}), middleware.updateMemberData);
membersApp.post('/api/member/email', bodyParser.json({limit: '1mb'}), (req, res) => membersService.api.middleware.updateEmailAddress(req, res));
membersApp.get('/api/session', middleware.getIdentityToken);
membersApp.get('/api/offers/:id', labs.enabledMiddleware('offers'), middleware.getOfferData);
membersApp.delete('/api/session', middleware.deleteSession);
membersApp.get('/api/site', middleware.getMemberSiteData);