Skip to content

Commit

Permalink
fix: draft applications (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvayngrib committed Feb 28, 2018
1 parent bc875c9 commit 3ad77db
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions src/in-house-bot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ export default function createProductsBot ({
productsAPI.plugins.use(setNamePlugin({ bot, productsAPI }))
productsAPI.plugins.use(<IPluginLifecycleMethods>{
onmessage: async (req) => {
if (req.application && req.application.draft) {
req.skipChecks = true
}
},
['onmessage:tradle.ProductRequest']: async (req) => {
const { application } = req
if (!application) return

Expand All @@ -338,19 +343,14 @@ export default function createProductsBot ({
req.isFromEmployee = employeeManager.isEmployee(req.user)
if (!req.isFromEmployee) return

if (req.type === 'tradle.ProductRequest') {
logger.debug('setting application.draft, as this is an employee applying on behalf of a customer')
application.draft = true
await productsAPI.sendSimpleMessage({
req,
to: req.user,
message: `Note: this is a draft application. When you finish you will be given a set of links that can be used to import`
})
}

if (application.draft) {
req.skipChecks = true
}
logger.debug('setting application.draft, as this is an employee applying on behalf of a customer')
application.draft = true
req.skipChecks = true
await productsAPI.sendSimpleMessage({
req,
to: req.user,
message: `Note: this is a draft application. When you finish you will be given a set of links that can be used to import`
})
}
})

Expand Down
21 changes: 16 additions & 5 deletions src/in-house-bot/plugins/remediation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { TYPES } from '../constants'
import { IPluginOpts, IPluginExports, IPluginLifecycleMethods, IPBReq } from '../types'
import {
IPluginOpts,
IPluginExports,
IPluginLifecycleMethods,
IPBReq,
IUser,
IPBApp
} from '../types'
import { Remediation } from '../remediation'
import { appLinks } from '../../app-links'
const { DATA_CLAIM, PRODUCT_REQUEST } = TYPES
Expand All @@ -21,9 +28,13 @@ export const createPlugin = (opts:IPluginOpts):IRemediationPluginExports => {
})
}

plugin[`onmessage:${PRODUCT_REQUEST}`] = async ({ user, application, payload }: IPBReq) => {
const claimId = payload.contextId
if (application && remediation.isPrefillClaimId(claimId)) {
plugin.willCreateApplication = async ({ req, user, application }: {
req: IPBReq
user: IUser
application: IPBApp
}) => {
const claimId = req.payload.contextId
if (remediation.isPrefillClaimId(claimId)) {
try {
await remediation.handlePrefillClaim({ user, application, claimId })
} catch (err) {
Expand All @@ -41,7 +52,7 @@ export const createPlugin = (opts:IPluginOpts):IRemediationPluginExports => {
claimType: 'prefill'
})

const [mobile, web] = ['mobile', 'web'].map(platform => appLinks.getApplyForProductLink({
const [mobile, web] = ['mobile', 'web'].map(platform => bot.appLinks.getApplyForProductLink({
provider,
host: bot.apiBaseUrl,
product: application.requestFor,
Expand Down

0 comments on commit 3ad77db

Please sign in to comment.