Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: optional typed request #1270

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ConorCorp
Copy link

Issue

Closes #1269

Solution and steps

This exposes a custom request object and extends Foal's request object, thus allowing you to manually type your request params and body, to make typescript happy. Makes working with validation easier.

This works, but a better solution would just be to make ValidatePathParam and ValidateBody automatically type ctx.

Please let me know if this makes sense and I can add some docs.

Example Usage

  @Get()
  @ValidatePathParam('versionId', { type: 'string', format: 'uuid' })
  async getDocumentVersionApprovers(ctx: Context<UserContext, object, Request<undefined, {versionId: string}>>) {
    const {
      request: {
        params: { versionId },
      },
      user,
    } = ctx;

Checklist

  • Add/update/check docs (code comments and docs/ folder).
  • Add/update/check tests.
  • Update/check the cli generators.

@ConorCorp
Copy link
Author

Small side note:
npm run start-docker fails on the m1 macs due to the old versions of postgres and mysql not support arm processors. I had to run higher versions of each of those images.

@ConorCorp ConorCorp changed the title add: request type add: optional typed request Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make A Controller's Request Typed
1 participant