|
1 | 1 | import { SPHttpClient } from '@microsoft/sp-http';
|
2 | 2 |
|
3 | 3 | export class ListItemRepository {
|
4 |
| - constructor(protected SiteUrl: string, protected SPClient: SPHttpClient) { |
| 4 | + constructor(protected SiteUrl: string, protected SPClient: SPHttpClient) { |
5 | 5 |
|
6 |
| - } |
7 |
| - /** |
8 |
| - * |
9 |
| - * @param filterText text value of the filter part of oData query 'Id eq 1' |
10 |
| - * @param listId |
11 |
| - * @param internalColumnName |
12 |
| - * @param keyInternalColumnName |
13 |
| - * @param webUrl |
14 |
| - * @param top |
15 |
| - * @param orderBy text value of the filter part of oData query 'Title desc, Created' |
16 |
| - */ |
17 |
| - public async getListItemsByFilterClause(filterText: string, listId: string, internalColumnName: string, keyInternalColumnName?: string, webUrl?: string, top?: number, orderBy?: string): Promise<any[]> { |
18 |
| - try { |
19 |
| - const webAbsoluteUrl = !webUrl ? this.SiteUrl : webUrl; |
20 |
| - let apiUrl = `${webAbsoluteUrl}/_api/web/lists('${listId}')/items?$select=${keyInternalColumnName || 'Id'},${internalColumnName}&$filter=${filterText}&$top=${top}`; |
21 |
| - if (orderBy) { |
22 |
| - apiUrl += `&$orderBy=${orderBy}`; |
23 |
| - } |
24 |
| - const data = await this.SPClient.get(apiUrl, SPHttpClient.configurations.v1); |
25 |
| - if (data.ok) { |
26 |
| - const results = await data.json(); |
27 |
| - if (results && results.value && results.value.length > 0) { |
28 |
| - return results.value; |
29 |
| - } |
30 |
| - } |
31 |
| - |
32 |
| - return []; |
33 |
| - } catch (error) { |
34 |
| - return Promise.reject(error); |
| 6 | + } |
| 7 | + /** |
| 8 | + * |
| 9 | + * @param filterText text value of the filter part of oData query 'Id eq 1' |
| 10 | + * @param listId |
| 11 | + * @param internalColumnName |
| 12 | + * @param keyInternalColumnName |
| 13 | + * @param webUrl |
| 14 | + * @param top |
| 15 | + * @param orderBy text value of the filter part of oData query 'Title desc, Created' |
| 16 | + */ |
| 17 | + public async getListItemsByFilterClause( |
| 18 | + filterText: string, |
| 19 | + listId: string, |
| 20 | + internalColumnName: string, |
| 21 | + keyInternalColumnName?: string, |
| 22 | + webUrl?: string, |
| 23 | + top?: number, |
| 24 | + orderBy?: string |
| 25 | + ): Promise<any[]> { // eslint-disable-line @typescript-eslint/no-explicit-any |
| 26 | + try { |
| 27 | + const webAbsoluteUrl = !webUrl ? this.SiteUrl : webUrl; |
| 28 | + let apiUrl = `${webAbsoluteUrl}/_api/web/lists('${listId}')/items?$select=${keyInternalColumnName || 'Id'},${internalColumnName}&$filter=${filterText}&$top=${top}`; |
| 29 | + if (orderBy) { |
| 30 | + apiUrl += `&$orderBy=${orderBy}`; |
| 31 | + } |
| 32 | + const data = await this.SPClient.get(apiUrl, SPHttpClient.configurations.v1); |
| 33 | + if (data.ok) { |
| 34 | + const results = await data.json(); |
| 35 | + if (results && results.value && results.value.length > 0) { |
| 36 | + return results.value; |
35 | 37 | }
|
| 38 | + } |
| 39 | + |
| 40 | + return []; |
| 41 | + } catch (error) { |
| 42 | + return Promise.reject(error); |
36 | 43 | }
|
| 44 | + } |
37 | 45 | }
|
0 commit comments