Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// ///////////////////////////////////////////////////////////////////// Imports
// -----------------------------------------------------------------------------
const Axios = require('axios')
const Path = require('path')

require('dotenv').config({ path: Path.resolve(__dirname, '../.env') })

// ////////////////////////////////////////////////////////////////////// Export
// -----------------------------------------------------------------------------
module.exports = async (eventData, upsertData = false) => {
try {
const options = {
headers: {
'Content-Type': 'application/json',
Authorization: `Api-Key ${process.env.LAUDSPEAKER_API_TOKEN}`
}
}
if (upsertData) {
await Axios.post('https://api.laudspeaker.com/customers/upsert', upsertData, options)
.then(async () => {
await Axios.post('https://api.laudspeaker.com/events', eventData, options)
})
} else {
await Axios.post('https://api.laudspeaker.com/events', eventData, options)
}
} catch (e) {
console.log('=========================[Logic: PushLaudspeakerNotification]')
console.log(e)
}
}
33 changes: 32 additions & 1 deletion packages/be/modules/user/rest/post-kyc-result.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { SendData } = require('@Module_Utilities')
const FindUser = require('@Module_User/logic/find-user')
const UpdateUser = require('@Module_User/logic/update-user')
const PushNotification = require('@Module_Notification/logic/push-notification')
const PushLaudspeakerNotification = require('@Module_Notification/logic/push-laudspeaker-notification')
const Moment = require('moment-timezone')

const MC = require('@Root/config')
Expand Down Expand Up @@ -50,7 +51,7 @@ MC.app.post('/post-kyc-result', async (req, res) => {
kycHistory.push(kyc)
const saved = await UpdateUser({ _id: user._id, kyc, kycHistory })
MC.socket.io.to(`${saved._id}`).emit('module|kyc-updated|payload', saved)
// ------------------------------------------------------- push notification
// ---------------------------- push notification + laudspeaker notification
const notification = {
ownerId: user._id,
bucket: 'kyc',
Expand All @@ -61,17 +62,47 @@ MC.app.post('/post-kyc-result', async (req, res) => {
failure: null
}
}
let upsertData
let eventData
if (kyc.event === 'success' || kyc.event === 'approve') {
notification.custom.success = {
createdAt: kyc.data.custom.createdAt
}
// data that needs to be added to Laudspeaker user for email template
upsertData = {
correlationKey: 'email',
correlationValue: kyc.data.custom.email,
githubUsername: kyc.data.custom.identifier
}
// data needed for event trigger in Journey
eventData = {
correlationKey: 'email',
correlationValue: kyc.data.custom.email,
source: 'custom',
event: `kyc-${kyc.event}`
}
} else if (kyc.event === 'failure') {
notification.custom.failure = {
createdAt: kyc.error.custom.createdAt,
name: kyc.error.name,
message: kyc.error.message
}
// data that needs to be added to Laudspeaker user for email template
upsertData = {
correlationKey: 'email',
correlationValue: kyc.error.custom.email,
githubUsername: kyc.error.custom.identifier,
failureMessage: kyc.error.message
}
// data needed for event trigger in Journey
eventData = {
correlationKey: 'email',
correlationValue: kyc.error.custom.email,
source: 'custom',
event: `kyc-${kyc.event}`
}
}
await PushLaudspeakerNotification(eventData, upsertData)
await PushNotification(notification)
// -------------------------------------------------------------------- send
SendData(res, 200, 'KYC result recorded successfully', saved)
Expand Down