From a85328f0e5b2f1d0d7194ab61f76423a5a2d0fda Mon Sep 17 00:00:00 2001 From: Fabien O'Carroll Date: Wed, 25 Sep 2019 16:26:52 +0700 Subject: [PATCH] Passed the set/get metadata methods to members-api no-issue --- core/server/services/members/api.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/core/server/services/members/api.js b/core/server/services/members/api.js index 5dd337ee80..a4097683bc 100644 --- a/core/server/services/members/api.js +++ b/core/server/services/members/api.js @@ -27,6 +27,25 @@ function getMember(data, options = {}) { }); } +async function setMemberMetadata(member, module, metadata) { + if (module !== 'stripe') { + return; + } + await models.Member.edit({ + stripe_info: metadata + }, {id: member.id, withRelated: ['stripe_info']}); + return; +} + +async function getMemberMetadata(member, module) { + if (module !== 'stripe') { + return; + } + const model = await models.Member.where({id: member.id}).fetch({withRelated: ['stripe_info']}); + const metadata = await model.related('stripe_info'); + return metadata.toJSON(); +} + function deleteMember(options) { options = options || {}; return models.Member.destroy(options).catch(models.Member.NotFoundError, () => { @@ -121,6 +140,8 @@ function createApiInstance() { paymentConfig: { stripe: getStripePaymentConfig() }, + setMemberMetadata, + getMemberMetadata, createMember, getMember, deleteMember,