Skip to content

Commit

Permalink
Merge pull request #8 from bullhorn/fix/entity
Browse files Browse the repository at this point in the history
Fix/entity
  • Loading branch information
escarre authored May 30, 2018
2 parents 3a57681 + 06fa5fa commit 45b5322
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
9 changes: 4 additions & 5 deletions src/core/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,13 @@ export class Entity<T extends Identity> extends StatefulSubject<T> {
case 'params':
this.$entity.params(params.params);
break;
case 'id':
this.get(params.id);
break;
default:
console.warn(`Unknown key in params: ${key}`);
}
}
if (params.id) {
this.get(params.id);
}

});
if (this.hasValue()) {
this.fields(Object.keys(this.value));
Expand Down Expand Up @@ -114,7 +113,7 @@ export class Entity<T extends Identity> extends StatefulSubject<T> {
subject.next(value);
},
configurable: true,
enumerable: true
enumerable: true,
});
}

Expand Down
11 changes: 4 additions & 7 deletions src/services/EntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ export class EntityService<T> {
*/
constructor(type: string) {
this.type = type;
this.endpoint = `entity/${this.type}/`;
this.endpoint = `entity/${this.type}`;
this.http = Staffing.http();
this.meta = new MetaService(this.type);
this.parameters = {
fields: this._fields || ['id']
fields: this._fields || ['id'],
};
}

Expand Down Expand Up @@ -72,10 +72,7 @@ export class EntityService<T> {
* @param id - Id of the Model to retrieve
*/
async get(id: number): Promise<BullhornEntityResponse<T>> {
const [response, meta] = await Promise.all([
this.http.get(`${this.endpoint}${id}`, { params: this.parameters }),
this.meta.getFull(this.parameters.fields, this.parameters.layout)
]);
const [response, meta] = await Promise.all([this.http.get(`${this.endpoint}/${id}`, { params: this.parameters }), this.meta.getFull(this.parameters.fields, this.parameters.layout)]);
const result: BullhornEntityResponse<T> = response.data;
result.meta = meta;
return result;
Expand Down Expand Up @@ -117,7 +114,7 @@ export class EntityService<T> {
async save(value: any): Promise<AxiosResponse> {
// Update
if (value && value.id) {
return this.http.post(`${this.endpoint}${value.id}`, value);
return this.http.post(`${this.endpoint}/${value.id}`, value);
}
// Create
return this.http.put(this.endpoint, value);
Expand Down

0 comments on commit 45b5322

Please sign in to comment.