當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript DraftMiddleware.requestHandler方法代碼示例

本文整理匯總了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')))
  }
開發者ID:hmcts,項目名稱:cmc-citizen-frontend,代碼行數:26,代碼來源:index.ts

示例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)
開發者ID:hmcts,項目名稱:cmc-citizen-frontend,代碼行數:31,代碼來源:create-claim-draft.ts


注:本文中的@hmcts/cmc-draft-store-middleware.DraftMiddleware.requestHandler方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。