[ACA-1637] update searchApi to use alfresco-js-api-node (#561)

This commit is contained in:
Adina Parpalita
2018-08-10 22:12:57 +01:00
committed by Denys Vuika
parent a7abe9c422
commit 7c08488323
2 changed files with 17 additions and 23 deletions
@@ -23,19 +23,16 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { RepoApi } from '../repo-api';
import { RepoApiNew } from '../repo-api-new';
import { Utils } from '../../../../utilities/utils';
export class SearchApi extends RepoApi {
apiDefinition = 'search';
export class SearchApi extends RepoApiNew {
search(data: any[]): Promise<any> {
return this
.post(`/search`, { data }, this.apiDefinition)
.catch(this.handleError);
constructor(username?, password?) {
super(username, password);
}
queryRecentFiles(username: string): Promise<any> {
async queryRecentFiles(username: string) {
const data = {
query: {
query: '*',
@@ -48,22 +45,19 @@ export class SearchApi extends RepoApi {
]
};
return this
.post(`/search`, { data }, this.apiDefinition)
.catch(this.handleError);
await this.apiAuth();
return this.alfrescoJsApi.search.searchApi.search(data);
}
waitForApi(username, data) {
const recentFiles = () => {
return this.queryRecentFiles(username)
.then(response => response.data.list.pagination.totalItems)
.then(totalItems => {
if ( totalItems < data.expect) {
return Promise.reject(totalItems);
} else {
return Promise.resolve(totalItems);
}
});
async waitForApi(username, data) {
const recentFiles = async () => {
const totalItems = (await this.queryRecentFiles(username)).list.pagination.totalItems;
if ( totalItems < data.expect) {
return Promise.reject(totalItems);
} else {
return Promise.resolve(totalItems);
}
};
return Utils.retryCall(recentFiles);
+1 -1
View File
@@ -70,7 +70,7 @@ export class RepoClient {
}
get search() {
return new SearchApi(this.auth, this.config);
return new SearchApi(this.auth.username, this.auth.password);
}
}