Last active
May 17, 2019 23:13
-
-
Save ktutnik/7efa5734c1fd1a9180ab6ea7e71691f6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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