本文整理匯總了TypeScript中@hmcts/cmc-draft-store-middleware.DraftMiddleware.requestHandler方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript DraftMiddleware.requestHandler方法的具體用法?TypeScript DraftMiddleware.requestHandler怎麽用?TypeScript DraftMiddleware.requestHandler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@hmcts/cmc-draft-store-middleware.DraftMiddleware
的用法示例。
在下文中一共展示了DraftMiddleware.requestHandler方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: enableFor
enableFor (app: express.Express) {
const allMediation = '/case/*/mediation/*'
app.all(allMediation, requestHandler())
app.all(allMediation, ClaimMiddleware.retrieveByExternalId)
app.all(allMediation, CountyCourtJudgmentRequestedGuard.requestHandler)
app.all(allMediation,
DraftMiddleware.requestHandler(new DraftService(), 'mediation', 100, (value: any): MediationDraft => {
return new MediationDraft().deserialize(value)
}),
(req: express.Request, res: express.Response, next: express.NextFunction) => {
res.locals.draft = res.locals.mediationDraft
next()
})
app.all(allMediation,
DraftMiddleware.requestHandler(new DraftService(), 'response', 100, (value: any): ResponseDraft => {
return new ResponseDraft().deserialize(value)
}),
(req: express.Request, res: express.Response, next: express.NextFunction) => {
res.locals.draft = res.locals.responseDraft
next()
}
)
app.use('/', RouterFinder.findAll(path.join(__dirname, 'routes')))
}
示例2: ClaimStoreClient
import { Draft } from '@hmcts/draft-store-client'
import { DraftMiddleware } from '@hmcts/cmc-draft-store-middleware'
import { ClaimStoreClient } from 'claims/claimStoreClient'
const claimStoreClient: ClaimStoreClient = new ClaimStoreClient()
/* tslint:disable:no-default-export */
export default express.Router()
.get(Paths.createClaimDraftPage.uri,
ErrorHandling.apply(async (req: express.Request, res: express.Response) => {
res.render(Paths.createClaimDraftPage.associatedView)
})
)
.post(Paths.createClaimDraftPage.uri,
DraftMiddleware.requestHandler(new DraftService(), 'claim', 100, (value: any): DraftClaim => {
return new DraftClaim().deserialize(value)
}),
ErrorHandling.apply(async (req: express.Request, res: express.Response) => {
const draft: Draft<DraftClaim> = res.locals.claimDraft
const user: User = res.locals.user
draft.document = new DraftClaim().deserialize(prepareClaimDraft(user.email))
await new DraftService().save(draft, user.bearerToken)
const roles: string[] = await claimStoreClient.retrieveUserRoles(user)
if (roles && !roles.some(role => role.includes('cmc-new-features-consent'))) {
await claimStoreClient.addRoleToUser(user, 'cmc-new-features-consent-given')
}
res.redirect(ClaimPaths.checkAndSendPage.uri)