0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Decoupled add from importCSV queries

no-issue
This commit is contained in:
Fabien O'Carroll 2019-10-09 14:14:26 +07:00
parent ec303e5bec
commit dd214d71dc

View file

@ -60,30 +60,20 @@ const members = {
}
},
permissions: true,
query(frame) {
// NOTE: Promise.resolve() is here for a reason! Method has to return an instance
// of a Bluebird promise to allow reflection. If decided to be replaced
// with something else, e.g: async/await, CSV export function
// would need a deep rewrite (see failing tests if this line is removed)
return Promise.resolve()
.then(() => {
return membersService.api.members.create(frame.data.members[0], {
sendEmail: frame.options.send_email,
emailType: frame.options.email_type
});
})
.then((member) => {
if (member) {
return Promise.resolve(member);
}
})
.catch((error) => {
if (error.code && error.message.toLowerCase().indexOf('unique') !== -1) {
return Promise.reject(new common.errors.ValidationError({message: common.i18n.t('errors.api.members.memberAlreadyExists')}));
}
return Promise.reject(error);
async query(frame) {
try {
const member = await membersService.api.members.create(frame.data.members[0], {
sendEmail: frame.options.send_email,
emailType: frame.options.email_type
});
return member;
} catch (error) {
if (error.code && error.message.toLowerCase().indexOf('unique') !== -1) {
throw new common.errors.ValidationError({message: common.i18n.t('errors.api.members.memberAlreadyExists')});
}
throw error;
}
}
},
@ -168,7 +158,7 @@ const members = {
return Promise.all(result.map((entry) => {
const api = require('./index');
return api.members.add.query({
return Promise.resolve(api.members.add.query({
data: {
members: [{
email: entry.email,
@ -179,7 +169,7 @@ const members = {
context: frame.options.context,
options: {send_email: false}
}
}).reflect();
})).reflect();
})).each((inspection) => {
if (inspection.isFulfilled()) {
fulfilled = fulfilled + 1;