Skip to content

Commit

Permalink
Merge pull request #217 from friggframework/feature/lef-418-search-fi…
Browse files Browse the repository at this point in the history
…lter-ui-from-filter-options-endpoint

Feature/Add Sharepoint graphSearchQuery function
  • Loading branch information
leofmds authored Sep 6, 2023
2 parents f536e4c + dc55463 commit 93dc0b4
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions api-module-library/frontify/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,7 @@ describe(`${Config.label} API Tests`, () => {
let scope;

beforeEach(() => {

scope = nock(baseUrl)
.post('', (body ) => body.query.replace(/\s/g, '') === buildQl().replace(/\s/g, ''))
.reply(200, {
Expand Down
32 changes: 31 additions & 1 deletion api-module-library/sharepoint/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Api extends OAuth2Requester {
`/drives/${driveId}/root/search(q='${query}')?top=20&$select=id,image,name,file,parentReference,size,lastModifiedDateTime,@microsoft.graph.downloadUrl&$filter=`,
uploadFile: ({ driveId, childId, filename }) =>
`/drives/${driveId}/items/${childId}:/${filename}:/content`,
createUploadSession: ({ driveId, childId,filename }) =>
createUploadSession: ({ driveId, childId, filename }) =>
`/drives/${driveId}/${childId}:/${filename}:/createUploadSession`
};

Expand Down Expand Up @@ -127,6 +127,36 @@ class Api extends OAuth2Requester {
return response;
}

async graphSearchQuery(query) {
const organizationId = query.organizationId;
const fileExtension = query.filter?.fileTypes;

let formattedTypes = '';
if (fileExtension) formattedTypes = fileExtension.map(type => `filetype:${type}`).join(' OR ');

const options = {
url: `${this.baseUrl}/search/query`,
headers: {
'Content-Type': 'application/json',
},
body: {
"requests": [
{
"entityTypes": [
"driveItem"
],
"query": {
"queryString": `${query.query} driveId:${organizationId} ${formattedTypes}`
},
"from": `${query.nextPage || 0}`,
"size": `${query.limit || 25}`
}
]
},
};
return await this._post(options);
}

async getFile(query) {
const params = {
driveId: query.driveId,
Expand Down
26 changes: 26 additions & 0 deletions api-module-library/sharepoint/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,32 @@ describe(`${Config.label} API Tests`, () => {
expect(scope.isDone()).toBe(true);
});
});

describe('Perform a graphSearchQuery', () => {
let scope;

beforeEach(() => {
scope = nock(baseUrl)
.post('/search/query')
.reply(200, {
results: 'results'
});
});

it('should hit the correct endpoint', async () => {
const query = {
organizationId: 'driveId',
query: 'query',
filter: {
fileTypes: ['jpg']
}
};

const results = await api.graphSearchQuery(query);
expect(results).toEqual({ results: 'results' });
expect(scope.isDone()).toBe(true);
});
});
});

describe('#getFile', () => {
Expand Down

0 comments on commit 93dc0b4

Please sign in to comment.