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:
parent
ec303e5bec
commit
dd214d71dc
1 changed files with 15 additions and 25 deletions
|
@ -60,30 +60,20 @@ const members = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
permissions: true,
|
permissions: true,
|
||||||
query(frame) {
|
async query(frame) {
|
||||||
// NOTE: Promise.resolve() is here for a reason! Method has to return an instance
|
try {
|
||||||
// of a Bluebird promise to allow reflection. If decided to be replaced
|
const member = await membersService.api.members.create(frame.data.members[0], {
|
||||||
// with something else, e.g: async/await, CSV export function
|
sendEmail: frame.options.send_email,
|
||||||
// would need a deep rewrite (see failing tests if this line is removed)
|
emailType: frame.options.email_type
|
||||||
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);
|
|
||||||
});
|
});
|
||||||
|
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) => {
|
return Promise.all(result.map((entry) => {
|
||||||
const api = require('./index');
|
const api = require('./index');
|
||||||
|
|
||||||
return api.members.add.query({
|
return Promise.resolve(api.members.add.query({
|
||||||
data: {
|
data: {
|
||||||
members: [{
|
members: [{
|
||||||
email: entry.email,
|
email: entry.email,
|
||||||
|
@ -179,7 +169,7 @@ const members = {
|
||||||
context: frame.options.context,
|
context: frame.options.context,
|
||||||
options: {send_email: false}
|
options: {send_email: false}
|
||||||
}
|
}
|
||||||
}).reflect();
|
})).reflect();
|
||||||
})).each((inspection) => {
|
})).each((inspection) => {
|
||||||
if (inspection.isFulfilled()) {
|
if (inspection.isFulfilled()) {
|
||||||
fulfilled = fulfilled + 1;
|
fulfilled = fulfilled + 1;
|
||||||
|
|
Loading…
Add table
Reference in a new issue