adding Service

This commit is contained in:
Peter Paul Kirschner 2021-02-26 23:05:40 +01:00
parent 40fbaaf3b4
commit 0d5698dcaf
1 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,36 @@
import { WebPartContext } from "@microsoft/sp-webpart-base";
import { graph } from "@pnp/graph";
export interface IGraphUser {
mail?: string;
displayName?: string;
jobTitle?: string;
}
const graphUserSelect: string[] = ['displayName', 'mail', 'jobTitle'];
export default class GraphServices {
constructor(private context: WebPartContext) {
graph.setup({
spfxContext: this.context
});
}
public async getUser(upn: string): Promise<IGraphUser> {
return await graph.users.getById(upn).select(...graphUserSelect).get() as IGraphUser;
}
public async getUserManger(upn: string): Promise<IGraphUser> {
return await graph.users.getById(upn).manager.select(...graphUserSelect).get() as IGraphUser;
}
public async getUserDirectReports(upn: string) {
return await graph.users.getById(upn).directReports.select(...graphUserSelect).get() as IGraphUser[];
}
}