0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Refactored member metadata logic into @tryghost/members-api package

refs c059e8e32e

- Reason why the refactor was needed can be found in refed commit
- The logic was extracted into members-api through passing models
directly as member-api module constructor parameters
- Bumped @tryghost/members-api to 0.11.0. Needed to work after the
refactor
This commit is contained in:
Nazar Gargol 2020-01-13 16:42:15 +07:00
parent 1e5f7852e6
commit 72ae194fbc
3 changed files with 12 additions and 54 deletions

View file

@ -8,48 +8,6 @@ const signupEmail = require('./emails/signup');
const subscribeEmail = require('./emails/subscribe');
const config = require('./config');
async function setMetadata(module, metadata) {
if (module !== 'stripe') {
return;
}
if (metadata.customer) {
await models.MemberStripeCustomer.upsert(metadata.customer, {
customer_id: metadata.customer.customer_id
});
}
if (metadata.subscription) {
await models.StripeCustomerSubscription.upsert(metadata.subscription, {
subscription_id: metadata.subscription.subscription_id
});
}
return;
}
async function getMetadata(module, member) {
if (module !== 'stripe') {
return;
}
const customers = (await models.MemberStripeCustomer.findAll({
filter: `member_id:${member.id}`
})).toJSON();
const subscriptions = await customers.reduce(async (subscriptionsPromise, customer) => {
const customerSubscriptions = await models.StripeCustomerSubscription.findAll({
filter: `customer_id:${customer.customer_id}`
});
return (await subscriptionsPromise).concat(customerSubscriptions.toJSON());
}, []);
return {
customers: customers,
subscriptions: subscriptions
};
}
const ghostMailer = new mail.GhostMailer();
module.exports = createApiInstance;
@ -165,8 +123,8 @@ function createApiInstance() {
paymentConfig: {
stripe: config.getStripePaymentConfig()
},
setMetadata,
getMetadata,
memberStripeCustomerModel: models.MemberStripeCustomer,
stripeCustomerSubscriptionModel: models.StripeCustomerSubscription,
memberModel: models.Member,
logger: common.logging
});

View file

@ -41,7 +41,7 @@
"dependencies": {
"@nexes/nql": "0.3.0",
"@tryghost/helpers": "1.1.20",
"@tryghost/members-api": "0.10.2",
"@tryghost/members-api": "0.11.0",
"@tryghost/members-ssr": "0.7.3",
"@tryghost/social-urls": "0.1.5",
"@tryghost/string": "^0.1.3",

View file

@ -227,22 +227,22 @@
dependencies:
"@tryghost/kg-clean-basic-html" "^0.1.4"
"@tryghost/magic-link@^0.3.2":
version "0.3.2"
resolved "https://registry.yarnpkg.com/@tryghost/magic-link/-/magic-link-0.3.2.tgz#dba8b1854d88d86b287be1e91be49d15a27e60b6"
integrity sha512-r5UTsHco7cQ17JvUdcqS1afs04D6ZxdUMSSiKcg2rRqx/POA/sFwsahm5Neek93goB03pPQoAsS7vQLPifsvdw==
"@tryghost/magic-link@^0.3.3":
version "0.3.3"
resolved "https://registry.yarnpkg.com/@tryghost/magic-link/-/magic-link-0.3.3.tgz#bd1124f8feb4639c06f8554246e3957eca71d061"
integrity sha512-uU0p8cTKvBMRWS/QFCnijNlrBcJIDJzgGI5UvfbURAkOHsTdiF+l7PbQXXfcWuwkHQl7riYWtIi1VGFc39MLug==
dependencies:
bluebird "^3.5.5"
ghost-ignition "^3.1.0"
jsonwebtoken "^8.5.1"
lodash "^4.17.15"
"@tryghost/members-api@0.10.2":
version "0.10.2"
resolved "https://registry.yarnpkg.com/@tryghost/members-api/-/members-api-0.10.2.tgz#c28d83a7e9817310a6e7a843f8a2a4669b52856e"
integrity sha512-dbA/NO6fpIxDu+b6tH3TN3i2tUrCGnue4vvOuSm0tctEWOTSIceaaiS64HFpncrsJ8obqvqY6ekilgASQWnZ1w==
"@tryghost/members-api@0.11.0":
version "0.11.0"
resolved "https://registry.yarnpkg.com/@tryghost/members-api/-/members-api-0.11.0.tgz#94a6ca7b11bf5132b7c8102dc92501965bf2e766"
integrity sha512-WV+8y1TzYnvoZGnw9kXH8hMuJhgebHbOskeJiy8X8yn45UD/hlMMuF+y015W1lrMYblEhBS5E4eGfAX+laKqOw==
dependencies:
"@tryghost/magic-link" "^0.3.2"
"@tryghost/magic-link" "^0.3.3"
bluebird "^3.5.4"
body-parser "^1.19.0"
cookies "^0.8.0"