Created
April 25, 2017 10:37
-
-
Save ktutnik/e4704cd2370f66fd6df3aeee4b95e776 to your computer and use it in GitHub Desktop.
This file contains 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
import { ApiController, Core, val, HttpStatusError, interceptor } from "kamboja" | |
import { ItemIdCheckInterceptor } from "../interceptor/item-idcheck-interceptor" | |
import { MongooseHelper } from "kamboja-mongoose" | |
import { ItemModel } from "../model/item-model" | |
import { ItemOdm } from "../model/odm" | |
export class ItemsController extends ApiController { | |
get( @val.required() id: string) { | |
return ItemOdm.findById(id).exec() | |
} | |
async list(iOffset: number, iLimit: number, q:string) { | |
let data = await ItemOdm.find() | |
.limit(iLimit) | |
.skip(iOffset) | |
.exec() | |
let count = await ItemOdm.find().count().exec() | |
return { | |
count: count, | |
result: data | |
} | |
} | |
add( @val.type("ItemModel, model/item-model") model: ItemModel) { | |
let odm = new ItemOdm(model) | |
return odm.save() | |
} | |
@interceptor.add(new ItemIdCheckInterceptor()) | |
async put( @val.required() id: string, @val.type("ItemModel, model/item-model") model: ItemModel) { | |
await ItemOdm.findByIdAndUpdate(id, model).exec() | |
} | |
@interceptor.add(new ItemIdCheckInterceptor()) | |
async modify( @val.required() id: string, model: ItemModel) { | |
await ItemOdm.findByIdAndUpdate(id, model).exec() | |
} | |
@interceptor.add(new ItemIdCheckInterceptor()) | |
async delete( @val.required() id: string) { | |
await ItemOdm.findByIdAndRemove(id).exec() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment