Skip to content

Instantly share code, notes, and snippets.

@ktutnik
Last active May 17, 2019 23:13
Show Gist options
  • Save ktutnik/7efa5734c1fd1a9180ab6ea7e71691f6 to your computer and use it in GitHub Desktop.
Save ktutnik/7efa5734c1fd1a9180ab6ea7e71691f6 to your computer and use it in GitHub Desktop.
//base domain
@domain()
export class Animal {
constructor(public name:string, public age:number){}
}
//cat domain
@domain()
export class Cat extends Animal {
constructor(public name:string, public age:number, public microChip:string){
super(name, age)
}
}
//base controller
export class AnimalsBase {
constructor(private tableName:string){}
@route.get(":id")
get(id:number){
return db(this.tableName).where({id}).first()
}
@route.post("")
add(animal:Animal){
return db(this.tableName).insert(animal)
}
}
//cat controller
export class CatsController extends AnimalsBase {
constructor(){
super("Cats")
}
@route.post("")
add(cat:Cat) {
return super.add(cat)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment