jitz-sharepoint-utilities

2.0.2 • Public • Published

JitzSharePointUtilities

Easily pluggable data layer for SharePoint Framework(SPFx) applications following Repository pattern and some SharePoint utilities

Prerequisites

Create the SPFx project according to Microsoft's documentation

How to use

Install the package using the command below

npm i jitz-sharepoint-utilities

Import the package in your project

import UtilityService from 'jitz-sharepoint-utilities/lib/services/UtilityService';
import UserService from 'jitz-sharepoint-utilities/lib/services/UserService';
import { IRepository } from 'jitz-sharepoint-utilities/lib/repositories/IRepository';
import Repository from 'jitz-sharepoint-utilities/lib/repositories/Repository';

export interface IProduct extends IModel{ 

}

Create the data model for the lists used on the project


import { IModel, IPersonOrGroup } from 'jitz-sharepoint-utilities/lib/common/IModels';

export interface IProduct extends IModel{ 
    customFieldsInTheList:string;
    ....
    ....
}


Create the repository class for the list


import { IWebPartContext } from '@microsoft/sp-webpart-base';
import {IProduct} from '../yourModelFile';
import Repository from 'jitz-sharepoint-utilities/lib/repositories/Repository';


export default class ProductRepository extends Repository<IProduct> {
    
    constructor(context: IWebPartContext,_listName:string="Products"){
        super(context,_listName);
    }
   

}

Use the repository


import { IRepository } from 'jitz-sharepoint-utilities/lib/repositories/IRepository';

private _productRepository:IRepository<IProduct>;

constructor(props: yourProps, state: yourState) {
        super(props);
        this.state = {
            ...
            ...
        };

        this._userService = new UserService(this.props.context);
        this._productRepository = new ProductRepository(this.props.context);
      }

getProducts = () => {
    this._productRepository.getAll().then((data)=>{
        ...
        ...
    });
}

Use User service

this._userService.getCurrentUser().then((user){});
this._userService.getCurrentUserGroups().then((groups){});
this._userService.checkIfCurrentUserInGroup(groupName).then((result){});
this._userService.checkIfUserIsInGroup(userId, groupName).then((result){});
this._userService.getUserById(id).then((user){});

Keywords

SPFx Typescript in SharePoint components SharePoint

Readme

Keywords

none

Package Sidebar

Install

npm i jitz-sharepoint-utilities

Weekly Downloads

4

Version

2.0.2

License

ISC

Unpacked Size

333 kB

Total Files

107

Last publish

Collaborators

  • jitz