import { List } from '@pnp/sp' ; import { DataSource , SPDataSourceItem } from '../../models/DataSource' ; export class DataSourceService { private list : List ; param { any } web param { string } listName constructor ( web , listName = 'Datakilder' ) { this . list = web . lists . getByTitle ( listName ) ; } param { string } name public async getByName ( name ) { const [ item ] = await this . list . items . select ( ... Object . keys ( new SPDataSourceItem ( ) ) ) . filter ( `Title eq '${ name }'` ) . get < SPDataSourceItem [ ] > ( ) ; if ( item ) { return new DataSource ( item ) ; } else { return null ; } } param { string } category public async getByCategory ( category ) { const items = await this . list . items . select ( ... Object . keys ( new SPDataSourceItem ( ) ) ) . filter ( `GtDataSourceCategory eq '${ category }'` ) . get < SPDataSourceItem [ ] > ( ) ; return items . map ( ( item ) => new DataSource ( item ) ) ; } }