mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-25 19:48:50 +03:00
Updated members uploader mapper logic to map all known types
This commit is contained in:
parent
21a0bc7aa9
commit
4f56e77db5
@ -15,24 +15,13 @@ import {inject as service} from '@ember/service';
|
||||
import {tracked} from '@glimmer/tracking';
|
||||
|
||||
class MembersFieldMapping {
|
||||
_supportedImportFields = [
|
||||
'email',
|
||||
'name',
|
||||
'note',
|
||||
'subscribed_to_emails',
|
||||
'stripe_customer_id',
|
||||
'complimentary_plan',
|
||||
'labels',
|
||||
'created_at'
|
||||
];
|
||||
|
||||
@tracked _mapping = {};
|
||||
|
||||
constructor(mapping) {
|
||||
// NOTE: there are only 2 distinguishable fields that could be automatically matched, which is the reason why code is just simple assignments
|
||||
if (mapping) {
|
||||
this.set(mapping.email, 'email');
|
||||
this.set(mapping.stripe_customer_id, 'stripe_customer_id');
|
||||
for (const [key, value] of Object.entries(mapping)) {
|
||||
this.set(value, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,7 +126,7 @@ export default Service.extend({
|
||||
},
|
||||
|
||||
/**
|
||||
* Detects validated data types:
|
||||
* Detects supported data types and auto-detects following two needed for validation:
|
||||
* 1. email
|
||||
* 2. stripe_customer_id
|
||||
*
|
||||
@ -135,6 +135,22 @@ export default Service.extend({
|
||||
* @param {Array} data sampled data containing non empty values
|
||||
*/
|
||||
_detectDataTypes(data) {
|
||||
const supportedTypes = [
|
||||
'email',
|
||||
'name',
|
||||
'note',
|
||||
'subscribed_to_emails',
|
||||
'stripe_customer_id',
|
||||
'complimentary_plan',
|
||||
'labels',
|
||||
'created_at'
|
||||
];
|
||||
|
||||
const autoDetectedTypes = [
|
||||
'email',
|
||||
'stripe_customer_id'
|
||||
];
|
||||
|
||||
let mapping = {};
|
||||
let i = 0;
|
||||
// loopping through all sampled data until needed data types are detected
|
||||
@ -154,6 +170,10 @@ export default Service.extend({
|
||||
mapping.stripe_customer_id = key;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!mapping[key] && supportedTypes.includes(key) && !(autoDetectedTypes.includes(key))) {
|
||||
mapping[key] = key;
|
||||
}
|
||||
}
|
||||
|
||||
i += 1;
|
||||
|
Loading…
Reference in New Issue
Block a user