Skip to content

question: @Param not type casted #1157

Open
@NicholasMKim

Description

@NicholasMKim

I was trying to...
Context:

  • Migrating from serverless to sst
  • Added @vendia/serverless-express during migration (but not 100% sure if this is necessary but without this sst threw an error of stream.listeners is not a function)

The problem:
After migrating to sst @Param doesn't cast id: number into number.

app.ts

import "reflect-metadata";
import { createExpressServer } from "routing-controllers";
import serverlessExpress from "@vendia/serverless-express";
import { APIGatewayProxyHandlerV2 } from "aws-lambda";


const app = createExpressServer({
  classTransformer: true,
  controllers: [/** controllers */]
});

export const handler: APIGatewayProxyHandlerV2 = (event, context) => {
  const instance = serverlessExpress({ app });
  return instance(event, context, () => {
    console.log("Server started");
  });
};

oneOfTheControllers.ts

@JsonController("/api/v1")
export class ListingController {
  @Get("/listing/agent-team/:agentTeamId")
  @OnUndefined(404)
  @OnNull(404)
  async getListingsByAgentTeamId(
    @CurrentUser() user: any,
    @Param("agentTeamId") agentTeamId: number
  ) {
    // agentTeamId is string
    authValidator(Number(agentTeamId), user, "agentTeamId");
    const listings = await ListingModel.getListingsByAgentTeamId(
      user.agentTeamId
    );
    return listings;
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: questionQuestions about the usage of the library.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions