当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript FormValidator.requestHandler方法代码示例

本文整理汇总了TypeScript中forms/validation/formValidator.FormValidator.requestHandler方法的典型用法代码示例。如果您正苦于以下问题:TypeScript FormValidator.requestHandler方法的具体用法?TypeScript FormValidator.requestHandler怎么用?TypeScript FormValidator.requestHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在forms/validation/formValidator.FormValidator的用法示例。


在下文中一共展示了FormValidator.requestHandler方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: renderView

import { Draft } from '@hmcts/draft-store-client'

function renderView (form: Form<DateOfBirth>, res: express.Response): void {
  res.render(Paths.claimantDateOfBirthPage.associatedView, { form: form })
}

/* tslint:disable:no-default-export */
export default express.Router()
  .get(Paths.claimantDateOfBirthPage.uri, (req: express.Request, res: express.Response) => {
    const draft: Draft<DraftClaim> = res.locals.claimDraft

    renderView(new Form((draft.document.claimant.partyDetails as IndividualDetails).dateOfBirth), res)
  })
  .post(
    Paths.claimantDateOfBirthPage.uri,
    FormValidator.requestHandler(DateOfBirth, DateOfBirth.fromObject),
    ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction) => {
      const form: Form<DateOfBirth> = req.body

      if (form.hasErrors()) {
        renderView(form, res)
      } else {
        const draft: Draft<DraftClaim> = res.locals.claimDraft
        const user: User = res.locals.user;

        (draft.document.claimant.partyDetails as IndividualDetails).dateOfBirth = form.model
        await new DraftService().save(draft, user.bearerToken)

        res.redirect(Paths.claimantMobilePage.uri)
      }
    }))
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:31,代码来源:claimant-dob.ts

示例2: renderView

/* tslint:disable:no-default-export */
export default express.Router()
  .get(
    page.uri,
    OptInFeatureToggleGuard.featureEnabledGuard('admissions'),
    PartialAdmissionGuard.requestHandler(),
    ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction) => {
      const draft: Draft<ResponseDraft> = res.locals.responseDraft
      renderView(new Form(draft.document.partialAdmission.whyDoYouDisagree), res)
    }))
  .post(
    page.uri,
    OptInFeatureToggleGuard.featureEnabledGuard('admissions'),
    PartialAdmissionGuard.requestHandler(),
    FormValidator.requestHandler(WhyDoYouDisagree, WhyDoYouDisagree.fromObject),
    ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction): Promise<void> => {
      const form: Form<WhyDoYouDisagree> = req.body

      if (form.hasErrors()) {
        renderView(form, res)
      } else {
        const draft: Draft<ResponseDraft> = res.locals.responseDraft
        const user: User = res.locals.user

        draft.document.partialAdmission.whyDoYouDisagree = form.model
        draft.document.fullAdmission = draft.document.rejectAllOfClaim = undefined

        await new DraftService().save(draft, user.bearerToken)

        const { externalId } = req.params
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:30,代码来源:why-do-you-disagree.ts

示例3: renderView

function renderView (form: Form<InterestEndDate>, res: express.Response): void {
  res.render(Paths.interestEndDatePage.associatedView, {
    form: form
  })
}

/* tslint:disable:no-default-export */
export default express.Router()
  .get(Paths.interestEndDatePage.uri, (req: express.Request, res: express.Response) => {
    const draft: Draft<DraftClaim> = res.locals.claimDraft

    renderView(new Form(draft.document.interestEndDate), res)
  })
  .post(
    Paths.interestEndDatePage.uri,
    FormValidator.requestHandler(InterestEndDate, InterestEndDate.fromObject),
    ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction) => {
      const form: Form<InterestEndDate> = req.body

      if (form.hasErrors()) {
        renderView(form, res)
      } else {
        const draft: Draft<DraftClaim> = res.locals.claimDraft
        const user: User = res.locals.user

        draft.document.interestEndDate = form.model
        await new DraftService().save(draft, user.bearerToken)

        res.redirect(Paths.totalPage.uri)
      }
    }))
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:31,代码来源:interest-end-date.ts

示例4: renderView

import { Draft } from '@hmcts/draft-store-client'

function renderView (form: Form<SoleTraderDetails>, res: express.Response): void {
  res.render(Paths.defendantSoleTraderOrSelfEmployedDetailsPage.associatedView, { form: form })
}

/* tslint:disable:no-default-export */
export default express.Router()
  .get(Paths.defendantSoleTraderOrSelfEmployedDetailsPage.uri, (req: express.Request, res: express.Response) => {
    const draft: Draft<DraftClaim> = res.locals.claimDraft

    renderView(new Form(draft.document.defendant.partyDetails as SoleTraderDetails), res)
  })
  .post(
    Paths.defendantSoleTraderOrSelfEmployedDetailsPage.uri,
    FormValidator.requestHandler(SoleTraderDetails, SoleTraderDetails.fromObject, 'defendant'),
    ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction) => {
      const form: Form<SoleTraderDetails> = req.body

      if (form.hasErrors()) {
        renderView(form, res)
      } else {
        const draft: Draft<DraftClaim> = res.locals.claimDraft
        const user: User = res.locals.user;

        (draft.document.defendant.partyDetails as SoleTraderDetails) = form.model
        await new DraftService().save(draft, user.bearerToken)

        res.redirect(Paths.defendantEmailPage.uri)
      }
    }))
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:31,代码来源:defendant-sole-trader-details.ts

示例5: renderView

import { User } from 'idam/user'
import { TestingSupportClient } from 'testing-support/testingSupportClient'

function renderView (form: Form<UpdateResponseDeadlineRequest>, res: express.Response): void {
  res.render(Paths.updateResponseDeadlinePage.associatedView, { form: form })
}

/* tslint:disable:no-default-export */
export default express.Router()
  .get(Paths.updateResponseDeadlinePage.uri,
    ErrorHandling.apply(async (req: express.Request, res: express.Response) => {
      renderView(new Form(new UpdateResponseDeadlineRequest()), res)
    })
  )
  .post(Paths.updateResponseDeadlinePage.uri,
    FormValidator.requestHandler(UpdateResponseDeadlineRequest, UpdateResponseDeadlineRequest.fromObject),
    ErrorHandling.apply(async (req: express.Request, res: express.Response) => {
      const form: Form<UpdateResponseDeadlineRequest> = req.body

      if (form.hasErrors()) {
        renderView(form, res)
      } else {
        TestingSupportClient.updateResponseDeadline(
          form.model,
          res.locals.user as User
        )

        res.redirect(Paths.indexPage.uri)
      }

    })
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:31,代码来源:update-response-deadline.ts

示例6: renderView

/* tslint:disable:no-default-export */
export default express.Router()
  .get(
    page.uri,
    OptInFeatureToggleGuard.featureEnabledGuard('admissions'),
    StatementOfMeansStateGuard.requestHandler(),
    ErrorHandling.apply(async (req: express.Request, res: express.Response) => {
      const draft: Draft<ResponseDraft> = res.locals.responseDraft
      renderView(new Form(draft.document.statementOfMeans.priorityDebt), res)
    }))
  .post(
    page.uri,
    OptInFeatureToggleGuard.featureEnabledGuard('admissions'),
    StatementOfMeansStateGuard.requestHandler(),
    FormValidator.requestHandler(
      PriorityDebt, PriorityDebt.fromObject, undefined, ['resetDebt']),
    actionHandler,
    ErrorHandling.apply(async (req: express.Request, res: express.Response): Promise<void> => {
      const form: Form<PriorityDebt> = req.body
      const { externalId } = req.params

      if (form.hasErrors()) {
        renderView(form, res)
      } else {
        const draft: Draft<ResponseDraft> = res.locals.responseDraft
        const user: User = res.locals.user

        draft.document.statementOfMeans.priorityDebt = form.model
        await new DraftService().save(draft, user.bearerToken)

        res.redirect(StatementOfMeansPaths.debtsPage.evaluateUri({ externalId: externalId }))
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:31,代码来源:priority-debts.ts

示例7: renderView

/* tslint:disable:no-default-export */
export default express.Router()
  .get(
    page.uri,
    StatementOfMeansStateGuard.requestHandler(),
    stateGuardRequestHandler,
    (req: express.Request, res: express.Response) => {
      const draft: Draft<ResponseDraft> = res.locals.responseDraft
      renderView(new Form(draft.document.statementOfMeans.education), res)
    })
  .post(
    page.uri,
    StatementOfMeansStateGuard.requestHandler(),
    stateGuardRequestHandler,
    FormValidator.requestHandler(Education, Education.fromObject),
    ErrorHandling.apply(async (req: express.Request, res: express.Response) => {
      const form: Form<Education> = req.body

      if (form.hasErrors()) {
        renderView(form, res)
      } else {
        const draft: Draft<ResponseDraft> = res.locals.responseDraft
        const user: User = res.locals.user

        draft.document.statementOfMeans.education = form.model
        await new DraftService().save(draft, user.bearerToken)

        const { externalId } = req.params

        // skip if defendant and partner are both disabled, or if defendant is severely disabled
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:30,代码来源:education.ts

示例8: Form

/* tslint:disable:no-default-export */
export default express.Router()
  .get(
    page.uri,
    StatementOfMeansStateGuard.requestHandler(),
    (req: express.Request, res: express.Response) => {
      const draft: Draft<ResponseDraft> = res.locals.responseDraft
      res.render(page.associatedView, {
        form: new Form(draft.document.statementOfMeans.disability)
      })
    })
  .post(
    page.uri,
    StatementOfMeansStateGuard.requestHandler(),
    FormValidator.requestHandler(Disability),
    ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction) => {
      const form: Form<Disability> = req.body
      const { externalId } = req.params

      if (form.hasErrors()) {
        res.render(page.associatedView, { form: form })
      } else {
        const draft: Draft<ResponseDraft> = res.locals.responseDraft
        const user: User = res.locals.user

        draft.document.statementOfMeans.disability = form.model
        if (form.model.option === DisabilityOption.NO) {
          draft.document.statementOfMeans.severeDisability = undefined
        }
        await new DraftService().save(draft, user.bearerToken)
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:30,代码来源:disability.ts

示例9: renderView

    form: form
  })
}

/* tslint:disable:no-default-export */
export default express.Router()
  .get(StatementOfMeansPaths.explanationPage.uri,
    StatementOfMeansStateGuard.requestHandler(),
    ErrorHandling.apply(async (req: express.Request, res: express.Response) => {
      const draft: Draft<ResponseDraft> = res.locals.responseDraft
      renderView(new Form(draft.document.statementOfMeans.explanation), res)
    }))
  .post(
    StatementOfMeansPaths.explanationPage.uri,
    StatementOfMeansStateGuard.requestHandler(),
    FormValidator.requestHandler(Explanation),
    ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction): Promise<void> => {
      const form: Form<Explanation> = req.body
      if (form.hasErrors()) {
        renderView(form, res)
      } else {
        const draft: Draft<ResponseDraft> = res.locals.responseDraft
        const user: User = res.locals.user

        draft.document.statementOfMeans.explanation = form.model
        await new DraftService().save(draft, user.bearerToken)
        const claim: Claim = res.locals.claim

        res.redirect(Paths.taskListPage.evaluateUri({ externalId: claim.externalId }))
      }
    }))
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:31,代码来源:explanation.ts

示例10: renderView

      return undefined
  }
}

/* tslint:disable:no-default-export */
export default express.Router()
  .get(
    Paths.acceptPaymentMethodPage.uri,
    ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction) => {
      const draft: Draft<DraftClaimantResponse> = res.locals.claimantResponseDraft
      renderView(new Form(draft.document.acceptPaymentMethod), res)
    }))

  .post(
    Paths.acceptPaymentMethodPage.uri,
    FormValidator.requestHandler(AcceptPaymentMethod, AcceptPaymentMethod.fromObject),
    ErrorHandling.apply(async (req: express.Request, res: express.Response, next: express.NextFunction): Promise<void> => {
      const form: Form<AcceptPaymentMethod> = req.body
      if (form.hasErrors()) {
        renderView(form, res)
      } else {
        const draft: Draft<DraftClaimantResponse> = res.locals.claimantResponseDraft
        const user: User = res.locals.user

        draft.document.acceptPaymentMethod = form.model
        draft.document.alternatePaymentMethod = undefined
        draft.document.formaliseRepaymentPlan = undefined
        draft.document.courtDetermination = undefined

        await new DraftService().save(draft, user.bearerToken)
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:30,代码来源:accept-payment-method.ts


注:本文中的forms/validation/formValidator.FormValidator.requestHandler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。