Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/Add Sharepoint graphSearchQuery function #217

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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