Skip to content

Commit

Permalink
add: fix #183 #2039
Browse files Browse the repository at this point in the history
  • Loading branch information
sirpy committed Jun 22, 2020
1 parent 99f1c06 commit 6b75e0e
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/server/mautic/__tests__/mauticAPI.js
Expand Up @@ -9,7 +9,7 @@ describe('Send', () => {
var mauticId = ''
it('should add new contact', async () => {
const res = await Mautic.createContact({ firstname: 'h', lastname: 'r', email: 'hadartest@gooddollar.org' })
mauticId = res.contact.fields.all.id
mauticId = res.contact.id
expect(res.contact.fields.all).toEqual(
expect.objectContaining({
id: expect.any(Number),
Expand Down
5 changes: 3 additions & 2 deletions src/server/mautic/mauticAPI.js
Expand Up @@ -59,15 +59,16 @@ export const Mautic = {
async createContact(user: UserRecord) {
const tags = ['dappuser']
if (user.email === undefined) {
log.warn('failed creating contact, no email.', { user })
return Promise.resolve()
log.error('failed creating contact, no email.', { user })
return Promise.reject('failed creating contact. no email.')
}
if (Config.isEtoro) tags.push('etorobeta')
tags.push(Config.version)
const mauticRecord = await this.baseQuery('/contacts/new', this.baseHeaders, { ...user, tags })

const mauticId = get(mauticRecord, 'contact.id', -1)
if (mauticId === -1) log.error('Mautic Error createContact failed', { user, tags, mauticRecord })
log.info('createContact result:', { mauticId, email: user.email })
await Mautic.deleteContactFromDNC({ mauticId })

return mauticRecord
Expand Down
2 changes: 1 addition & 1 deletion src/server/send/__tests__/sendAPI.js
Expand Up @@ -12,7 +12,7 @@ describe('sendAPÏ', () => {
let server
beforeAll(async done => {
const res = await Mautic.createContact({ firstname: 'h', lastname: 'r', email: 'hadartest@gooddollar.org' })
const mauticId = res.contact.fields.all.id
const mauticId = res.contact.id
//make sure fullname is set for user which is required for sending the recovery email
await UserDBPrivate.updateUser({
identifier: '0x7ac080f6607405705aed79675789701a48c76f55',
Expand Down
2 changes: 1 addition & 1 deletion src/server/storage/addUserSteps.js
Expand Up @@ -42,7 +42,7 @@ const updateMauticRecord = async (userRecord: UserRecord, logger: any) => {
logger.error('updateMauticRecord Create Mautic Record Failed', { e, errMessage: e.message, userRecord })
throw e
})
const mauticId = !userRecord.mauticId ? get(mauticRecord, 'contact.id', -1) : userRecord.mauticId
const mauticId = get(mauticRecord, 'contact.id', userRecord.mauticId)
await UserDBPrivate.updateUser({ identifier: userRecord.identifier, mauticId })
logger.debug('updateMauticRecord user mautic record updated', { userRecord, mauticId, mauticRecord })

Expand Down
4 changes: 2 additions & 2 deletions src/server/verification/verificationAPI.js
Expand Up @@ -356,7 +356,7 @@ const setup = (app: Router, verifier: VerificationAPI, gunPublic: StorageAPI, st
//otp might be undefined so we use spread operator instead of userRec.otp.tempId=
userRec.otp = {
...userRec.otp,
tempMauticId: mauticContact.contact.fields.all.id
tempMauticId: mauticContact.contact.id
}
log.debug('created new user mautic contact', userRec)
}
Expand Down Expand Up @@ -601,7 +601,7 @@ const setup = (app: Router, verifier: VerificationAPI, gunPublic: StorageAPI, st
if (w3User && w3User.email === email) {
currentUser.email = w3User.email
const mauticContact = await Mautic.createContact(currentUser)
const mauticId = mauticContact.contact.fields.all.id
const mauticId = mauticContact.contact.id
await storage.updateUser({
identifier: currentUser.loggedInAs,
mauticId,
Expand Down

0 comments on commit 6b75e0e

Please sign in to comment.