本文整理汇总了TypeScript中@hmcts/cmc-draft-store-middleware.DraftMiddleware类的典型用法代码示例。如果您正苦于以下问题:TypeScript DraftMiddleware类的具体用法?TypeScript DraftMiddleware怎么用?TypeScript DraftMiddleware使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DraftMiddleware类的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)