Skip to content

Commit

Permalink
Revert "Merge pull request #4 from akhilkala/api_service_extended"
Browse files Browse the repository at this point in the history
This reverts commit dc0a525, reversing
changes made to f97a083.
  • Loading branch information
snyaggarwal committed Aug 21, 2021
1 parent aa000ba commit a4815d6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 29 deletions.
14 changes: 7 additions & 7 deletions src/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,36 +218,36 @@ const handleLookupValuesResponse = (data, callback, attr) => {
}

export const fetchLocales = callback => {
APIService.orgs('OCL').sources('Locales').concepts().get(null, null, {limit: 1000}).then(response => {
APIService.orgs('OCL').sources('Locales').appendToUrl('concepts/').get(null, null, {limit: 1000}).then(response => {
callback(orderBy(map(reject(response.data, {locale: null}), l => ({id: l.locale, name: `${l.display_name} [${l.locale}]`})), 'name'));});
}

export const fetchConceptClasses = callback => {
APIService.orgs('OCL').sources('Classes').concepts()
APIService.orgs('OCL').sources('Classes').appendToUrl('concepts/')
.get(null, null, {limit: 1000, brief: true})
.then(response => handleLookupValuesResponse(response.data, callback));
}

export const fetchMapTypes = callback => {
APIService.orgs('OCL').sources('MapTypes').concepts()
APIService.orgs('OCL').sources('MapTypes').appendToUrl('concepts/')
.get(null, null, {limit: 1000, brief: true})
.then(response => handleLookupValuesResponse(response.data, callback));
}

export const fetchDatatypes = callback => {
APIService.orgs('OCL').sources('Datatypes').concepts()
APIService.orgs('OCL').sources('Datatypes').appendToUrl('concepts/')
.get(null, null, {limit: 1000, brief: true})
.then(response => handleLookupValuesResponse(response.data, callback));
}

export const fetchNameTypes = callback => {
APIService.orgs('OCL').sources('NameTypes').concepts()
APIService.orgs('OCL').sources('NameTypes').appendToUrl('concepts/')
.get(null, null, {limit: 1000, brief: true})
.then(response => handleLookupValuesResponse(response.data, callback));
}

export const fetchDescriptionTypes = callback => {
APIService.orgs('OCL').sources('DescriptionTypes').concepts()
APIService.orgs('OCL').sources('DescriptionTypes').appendToUrl('concepts/')
.get(null, null, {limit: 1000, brief: true})
.then(response => handleLookupValuesResponse(response.data, callback));
}
Expand Down Expand Up @@ -340,7 +340,7 @@ export const getCurrentUserCollections = callback => {
.then(response => isArray(response.data) ? callback(response.data) : false);
APIService.users(username)
.orgs()
.collections()
.appendToUrl('collections/')
.get(null, null, {limit: 1000})
.then(response => isArray(response.data) ? callback(response.data) : false);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/ConceptClassAutoComplete.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const ConceptClassAutoComplete = ({ id, selected, multiple, minCharactersForSear
APIService
.orgs('OCL')
.sources('Classes')
.concepts()
.appendToUrl('concepts/')
.get(null, null, {limit: 25, q: searchStr, brief: true})
.then(response => {
setItems(orderBy(uniqBy(map(response.data, cc => ({id: cc.id, name: cc.id})), 'name'), 'name'))
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/LocaleAutoComplete.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const LocaleAutoComplete = ({ id, selected, multiple, minCharactersForSearch, re
APIService
.orgs('OCL')
.sources('Locales')
.concepts()
.appendToUrl('concepts/')
.get(null, null, {limit: 25, q: searchStr})
.then(response => {
const _locales = orderBy(map(response.data, l => ({id: l.locale || l.display_locale, name: `${l.display_name} [${l.locale || l.display_locale}]`, uuid: l.uuid})), 'name');
Expand Down
2 changes: 1 addition & 1 deletion src/components/concepts/ConceptForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class ConceptForm extends React.Component {
if(edit) {
service.put(fields).then(response => this.handleSubmitResponse(response))
} else {
service.concepts().post(fields).then(response => this.handleSubmitResponse(response))
service.appendToUrl('concepts/').post(fields).then(response => this.handleSubmitResponse(response))
}
}
}
Expand Down
32 changes: 13 additions & 19 deletions src/services/APIService.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const getAPIURL = () => {
}

class APIService {
constructor(name, id, relations, url) {
constructor(name, id, relations) {
const apiURL = getAPIURL();
if (name === 'empty') this.URL = `${apiURL}/`;
else this.URL = `${apiURL}/${name}/`;
Expand All @@ -33,24 +33,16 @@ class APIService {
Accept: 'application/json'
};

if(url) this.URL=url

if (id) this.URL += `${id}/`;

if (id) {
this.URL += `${id}/`;
}
if (relations) {
relations.forEach((relation) => {
const resource = RESOURCES.find(res=>res.name === relation)
if(!resource) return
if(resource.relations.length === 0) {
this[relation] = relationId => {
this.URL += `${relation}/${relationId ? `${relationId}/` : ''}`
return this
};
}
else {
this[relation] = (id, query) => new APIService(resource.name, id, resource.relations, query,this.URL);
}
})
relations.forEach(relation => {
this[relation] = relationId => {
this.URL += `${relation}/${relationId ? `${relationId}/` : ''}`;
return this;
};
});
}
}

Expand Down Expand Up @@ -126,7 +118,9 @@ class APIService {
}

getQueryParams(query) {
if (isPlainObject(query)) return query;
if (isPlainObject(query)) {
return query;
}
if (isString(query)) {
const questionMarkSplit = query.split('?');
if (questionMarkSplit.length === 2) {
Expand Down

0 comments on commit a4815d6

Please sign in to comment.