odata-v4-server
Version:
OData V4 Server
85 lines (70 loc) • 2.06 kB
text/typescript
import { Edm, odata, ODataController, ODataServer } from "../lib";
.namespace("InheritanceSchema")
export class Category{
.Key
.Computed
.Int32
id: number;
.String
title: string;
constructor(title:string){
this.id = Math.floor(Math.random() * 100);
this.title = title;
}
}
.namespace("Default")
export class Subcategory extends Category{
.String
subtitle: string;
constructor(title:string, subtitle:string){
super(title);
this.subtitle = subtitle;
}
}
.namespace("Default")
export class Subcategory2 extends Category{
.String
subtitle2: string;
constructor(title:string, subtitle:string){
super(title);
this.subtitle2 = subtitle;
}
}
export class SubcategoryDetails extends Subcategory{
.String
description: string;
.Key
.Int32
subid: number
constructor(title:string, subtitle:string, description:string){
super(title, subtitle);
this.description = description;
this.subid = Math.floor(Math.random() * 100) + 1000;
}
}
.type(Subcategory)
export class InheritanceController extends ODataController{
.GET
all(){
return [
{ id: 123, title: "Games", "@odata.type": Category },
new Category("Games"),
new Subcategory("Games", "Hearthstone"),
new Subcategory2("Games", "Diablo 3"),
new SubcategoryDetails("Games", "Diablo 3", "RPG game")
];
}
.GET
one(.key _: number, .key __: number){
return new SubcategoryDetails("Games", "Diablo 3", "RPG game");
}
.POST
insert(.body data:any, .type type:string){
console.log('@odata.type', type, data);
return data;
}
}
.controller(InheritanceController, true)
.controller(InheritanceController, "Inheritance2")
export class InheritanceServer extends ODataServer{}
InheritanceServer.create(3000);