Reused _resolveContextSource method in member update

refs https://github.com/TryGhost/Toolbox/issues/386

- Reusing tontext mapping logic to improve maintainability. It seems like the `update` method was not updated properly or intentionally was left out from  'import' source as that should not ever happen theoretically. Probably the latter is most likely.
- My reasoning on reusing same context to source mapping is: it is better to attribute an appropriate "import" source here. Who knows, maybe we'll have logic in the future where the importer updates instead of skipping existing members. It would not make sense to attribute the source to 'member' in that case, amirite?
- This refactor also makes maintainability of this code way easier
This commit is contained in:
Naz 2022-08-23 12:29:55 +08:00
parent 32343a7adb
commit 6121451b5d

View File

@ -479,16 +479,7 @@ module.exports = class MemberRepository {
// Add subscribe events for all (un)subscribed newsletters
const context = options && options.context || {};
let source;
if (context.internal) {
source = 'system';
} else if (context.user) {
source = 'admin';
} else if (context.api_key) {
source = 'api';
} else {
source = 'member';
}
const source = this._resolveContextSource(context);
for (const newsletterToAdd of newslettersToAdd) {
await this._MemberSubscribeEvent.add({