Last active
May 19, 2017 14:14
-
-
Save jquintozamora/43d61763771078d72a81890a63605ebc 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 { Item, ODataEntity } from "sp-pnp-js"; | |
export class MyItem extends Item { | |
public static Fields = ["Id", "Title", "Category", "Quantity"]; | |
public Id: number; | |
public Title: string; | |
public Category: string; | |
public Quantity: number; | |
// override get to enfore select for our fields to always optimize | |
// but allow it to be overridden by any supplied values | |
public get(): Promise<MyItem> { | |
// use apply and call to manipulate the request into the form we want | |
// if another select isn't in place, let's default to only ever getting our fields. | |
const query = this._query.getKeys().indexOf("$select") > -1 ? this : this.select.apply(this, MyItem.Fields); | |
// call the base get, but in our case pass the appropriate ODataEntity def so we are returning | |
// a MyItem instance | |
return super.get.call(query, ODataEntity(MyItem), arguments[1] || {}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment