Tsed: Abstract Controller

Created on 12 Sep 2020  路  7Comments  路  Source: tsedio/tsed

Hi Team, My thought is to create a generic abstract controller which is extended all my controller, that abstract controller has all basic CRUD operation. but here the problem is if extend the abstract base class I can get only request and response value from method param but am expecting query params and body

  • Version: 5.x
  • Packages:

A few sentences describing the overall goals of the issue.

Example

http://localhost:8083/child/list?search=test

The expectation is search query param value(string) but iam getting the request object in list method in BaseCtrl class.

import {Get, QueryParams} from "@tsed/common";
import {SomeService} from "./SomeService";

export abstract class BaseCtrl {
  constructor(private someService: SomeService) {
  }

  @Get("/list")
  async list(@QueryParams("search") search: any) {
//expectation is search queryparam value but iam getting request object
    return this.someService.list(search);
  }
}

import {Controller, Get, PathParams} from "@tsed/common";
import {BaseCtrl} from "./BaseCtrl";

@Controller("/child")
export class ChildCtrl extends BaseCtrl {
  @Get("/name")
  get(@PathParams("id") id: string): any {
    return {id: id};
  }
}
  • [x] Criteria 1
bug released on @alpha

Most helpful comment

Fixed with v5.65.2 :)

All 7 comments

Hello,

Why have you abtract instruction on the child class? It should not have this right?

Hi Romakita, Actually I don't want to create CURD basic operation method in each controller. create one abstract class with all curd operation and pass respective service from child class and will use it. if want to change that in any one of the controllers I will override that method alone and will use it

This is not my point and I understand what you to ascomplish, you are not the first you want to do. Other contributors use this approach and it works. I just said, in your previous example, the ChildCtrl you use also the abtract instruction (childctrl should not have it). I just want to know if it鈥檚 just an error on your example.

I try to reproduce your issue :)

image
@Romakita please see here

Fixed with v5.65.2 :)

Fixed with v5.65.2 :)

Thanks @Romakita

:tada: This issue has been resolved in version 6.0.0-alpha.16 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

Was this page helpful?
0 / 5 - 0 ratings