chore: server code formatting
This commit is contained in:
parent
aedabcbdee
commit
68517170e2
234 changed files with 9824 additions and 6195 deletions
|
|
@ -2,5 +2,5 @@ module.exports = {
|
|||
PENDING: 'PENDING',
|
||||
RETRY: 'RETRY',
|
||||
APPROVED: 'APPROVED',
|
||||
REJECTED: 'REJECTED'
|
||||
}
|
||||
REJECTED: 'REJECTED',
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
const uuid = require('uuid')
|
||||
|
||||
const {APPROVED} = require('../consts')
|
||||
const { APPROVED } = require('../consts')
|
||||
|
||||
const CODE = 'mock-compliance'
|
||||
|
||||
|
|
@ -8,18 +8,19 @@ const createLink = (settings, userId, level) => {
|
|||
return `this is a mock external link, ${userId}, ${level}`
|
||||
}
|
||||
|
||||
const getApplicantStatus = (account, userId) => {
|
||||
const getApplicantStatus = account => {
|
||||
return Promise.resolve({
|
||||
service: CODE,
|
||||
status: {
|
||||
level: account.applicantLevel, answer: APPROVED
|
||||
}
|
||||
level: account.applicantLevel,
|
||||
answer: APPROVED,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const createApplicant = () => {
|
||||
return Promise.resolve({
|
||||
id: uuid.v4()
|
||||
id: uuid.v4(),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -27,5 +28,5 @@ module.exports = {
|
|||
CODE,
|
||||
createApplicant,
|
||||
getApplicantStatus,
|
||||
createLink
|
||||
createLink,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ const _ = require('lodash/fp')
|
|||
const FormData = require('form-data')
|
||||
|
||||
const axiosConfig = {
|
||||
baseURL: 'https://api.sumsub.com'
|
||||
baseURL: 'https://api.sumsub.com',
|
||||
}
|
||||
|
||||
const getSigBuilder = (apiToken, secretKey) => config => {
|
||||
|
|
@ -25,10 +25,13 @@ const getSigBuilder = (apiToken, secretKey) => config => {
|
|||
return config
|
||||
}
|
||||
|
||||
const request = ((account, config) => {
|
||||
const request = (account, config) => {
|
||||
const instance = axios.create(axiosConfig)
|
||||
instance.interceptors.request.use(getSigBuilder(account.apiToken, account.secretKey), Promise.reject)
|
||||
instance.interceptors.request.use(
|
||||
getSigBuilder(account.apiToken, account.secretKey),
|
||||
Promise.reject,
|
||||
)
|
||||
return instance(config)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = request
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ const request = require('./request')
|
|||
|
||||
const createApplicant = (account, userId, level) => {
|
||||
if (!userId || !level) {
|
||||
return Promise.reject(`Missing required fields: userId: ${userId}, level: ${level}`)
|
||||
return Promise.reject(
|
||||
`Missing required fields: userId: ${userId}, level: ${level}`,
|
||||
)
|
||||
}
|
||||
|
||||
const config = {
|
||||
|
|
@ -10,12 +12,12 @@ const createApplicant = (account, userId, level) => {
|
|||
url: `/resources/applicants?levelName=${level}`,
|
||||
data: {
|
||||
externalUserId: userId,
|
||||
sourceKey: 'lamassu'
|
||||
sourceKey: 'lamassu',
|
||||
},
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
Accept: 'application/json',
|
||||
},
|
||||
}
|
||||
|
||||
return request(account, config)
|
||||
|
|
@ -23,7 +25,9 @@ const createApplicant = (account, userId, level) => {
|
|||
|
||||
const createLink = (account, userId, level) => {
|
||||
if (!userId || !level) {
|
||||
return Promise.reject(`Missing required fields: userId: ${userId}, level: ${level}`)
|
||||
return Promise.reject(
|
||||
`Missing required fields: userId: ${userId}, level: ${level}`,
|
||||
)
|
||||
}
|
||||
|
||||
const config = {
|
||||
|
|
@ -31,8 +35,8 @@ const createLink = (account, userId, level) => {
|
|||
url: `/resources/sdkIntegrations/levels/${level}/websdkLink?ttlInSecs=${600}&externalUserId=${userId}`,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
Accept: 'application/json',
|
||||
},
|
||||
}
|
||||
|
||||
return request(account, config)
|
||||
|
|
@ -47,9 +51,9 @@ const getApplicantByExternalId = (account, id) => {
|
|||
method: 'GET',
|
||||
url: `/resources/applicants/-;externalUserId=${id}/one`,
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
}
|
||||
|
||||
return request(account, config)
|
||||
|
|
@ -64,9 +68,9 @@ const getApplicantStatus = (account, id) => {
|
|||
method: 'GET',
|
||||
url: `/resources/applicants/${id}/status`,
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
}
|
||||
|
||||
return request(account, config)
|
||||
|
|
@ -81,9 +85,9 @@ const getApplicantById = (account, id) => {
|
|||
method: 'GET',
|
||||
url: `/resources/applicants/${id}/one`,
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
}
|
||||
|
||||
return request(account, config)
|
||||
|
|
@ -94,5 +98,5 @@ module.exports = {
|
|||
createApplicant,
|
||||
getApplicantByExternalId,
|
||||
getApplicantById,
|
||||
getApplicantStatus
|
||||
getApplicantStatus,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,48 +6,53 @@ const { PENDING, RETRY, APPROVED, REJECTED } = require('../consts')
|
|||
const CODE = 'sumsub'
|
||||
|
||||
const getApplicantByExternalId = (account, userId) => {
|
||||
return sumsubApi.getApplicantByExternalId(account, userId)
|
||||
.then(r => r.data)
|
||||
return sumsubApi.getApplicantByExternalId(account, userId).then(r => r.data)
|
||||
}
|
||||
|
||||
const createApplicant = (account, userId, level) => {
|
||||
return sumsubApi.createApplicant(account, userId, level)
|
||||
return sumsubApi
|
||||
.createApplicant(account, userId, level)
|
||||
.then(r => r.data)
|
||||
.catch(err => {
|
||||
if (err.response.status === 409) return getApplicantByExternalId(account, userId)
|
||||
if (err.response.status === 409)
|
||||
return getApplicantByExternalId(account, userId)
|
||||
throw err
|
||||
})
|
||||
}
|
||||
|
||||
const createLink = (account, userId, level) => {
|
||||
return sumsubApi.createLink(account, userId, level)
|
||||
.then(r => r.data.url)
|
||||
return sumsubApi.createLink(account, userId, level).then(r => r.data.url)
|
||||
}
|
||||
|
||||
const getApplicantStatus = (account, userId) => {
|
||||
return sumsubApi.getApplicantByExternalId(account, userId)
|
||||
.then(r => {
|
||||
const levelName = _.get('data.review.levelName', r)
|
||||
const reviewStatus = _.get('data.review.reviewStatus', r)
|
||||
const reviewAnswer = _.get('data.review.reviewResult.reviewAnswer', r)
|
||||
const reviewRejectType = _.get('data.review.reviewResult.reviewRejectType', r)
|
||||
return sumsubApi.getApplicantByExternalId(account, userId).then(r => {
|
||||
const levelName = _.get('data.review.levelName', r)
|
||||
const reviewStatus = _.get('data.review.reviewStatus', r)
|
||||
const reviewAnswer = _.get('data.review.reviewResult.reviewAnswer', r)
|
||||
const reviewRejectType = _.get(
|
||||
'data.review.reviewResult.reviewRejectType',
|
||||
r,
|
||||
)
|
||||
|
||||
// if last review was from a different level, return the current level and RETRY
|
||||
if (levelName !== account.applicantLevel) return { level: account.applicantLevel, answer: RETRY }
|
||||
// if last review was from a different level, return the current level and RETRY
|
||||
if (levelName !== account.applicantLevel)
|
||||
return { level: account.applicantLevel, answer: RETRY }
|
||||
|
||||
let answer = PENDING
|
||||
if (reviewStatus === 'init') answer = RETRY
|
||||
if (reviewAnswer === 'GREEN' && reviewStatus === 'completed') answer = APPROVED
|
||||
if (reviewAnswer === 'RED' && reviewRejectType === 'RETRY') answer = RETRY
|
||||
if (reviewAnswer === 'RED' && reviewRejectType === 'FINAL') answer = REJECTED
|
||||
let answer = PENDING
|
||||
if (reviewStatus === 'init') answer = RETRY
|
||||
if (reviewAnswer === 'GREEN' && reviewStatus === 'completed')
|
||||
answer = APPROVED
|
||||
if (reviewAnswer === 'RED' && reviewRejectType === 'RETRY') answer = RETRY
|
||||
if (reviewAnswer === 'RED' && reviewRejectType === 'FINAL')
|
||||
answer = REJECTED
|
||||
|
||||
return { level: levelName, answer }
|
||||
})
|
||||
return { level: levelName, answer }
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
CODE,
|
||||
createApplicant,
|
||||
getApplicantStatus,
|
||||
createLink
|
||||
}
|
||||
createLink,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue