Removed invite before adding in v2

refs #9866

- the logic in v2 was missing
- it exists in v0.1
This commit is contained in:
kirrg001 2018-10-16 17:26:24 +02:00
parent b1c7781cc6
commit 14a1bdbcf6

View File

@ -107,7 +107,18 @@ module.exports = {
let invite;
let emailData;
return models.Invite.add(frame.data.invites[0], frame.options)
// CASE: ensure we destroy the invite before
return models.Invite.findOne({email: frame.data.invites[0].email}, frame.options)
.then((invite) => {
if (!invite) {
return;
}
return invite.destroy(frame.options);
})
.then(() => {
return models.Invite.add(frame.data.invites[0], frame.options);
})
.then((_invite) => {
invite = _invite;