Last active
July 7, 2017 07:19
-
-
Save ypcode/38de7847d369a700d5a12eb7d9f491e4 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 pnp, { Web, NodeFetchClient } from "sp-pnp-js"; | |
import { IHardwareRequest } from "../model/IHardwareRequest"; | |
const HardwareRequestListTitle = "Hardware Requests"; | |
export class HardwareRequestService { | |
private web: Web; | |
constructor (web: Web) { | |
this.web = web; | |
} | |
public static createAppOnly(siteUrl: string, clientId: string, clientSecret: string) : HardwareRequestService { | |
pnp.setup({ | |
fetchClientFactory: () => { | |
return new NodeFetchClient(siteUrl, clientId, clientSecret); | |
} | |
}); | |
return new HardwareRequestService(new Web(siteUrl)); | |
} | |
public static createForCurrentWeb() : HardwareRequestService { | |
return new HardwareRequestService(pnp.sp.web); | |
} | |
public submitRequest(request: IHardwareRequest) : Promise<any> { | |
console.log(request); | |
return this.web.lists.getByTitle(HardwareRequestListTitle).items.add({ | |
Title: request.title || ("Request " + new Date().toUTCString()), | |
HW_HardwareType: request.type, | |
HW_Remark: request.remark, | |
HW_Quantity: request.quantity | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment