Skip to content

Commit

Permalink
fix(EntityService): Implementing edit/many
Browse files Browse the repository at this point in the history
  • Loading branch information
escarre authored and jgodi committed Jun 6, 2018
1 parent 45b5322 commit 1a40c72
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 57 deletions.
47 changes: 19 additions & 28 deletions src/core/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,34 +169,25 @@ export class Entity<T extends Identity> extends StatefulSubject<T> {
});
return this;
}
// /**
// * Make http request to get entity. Objects 'data' property will be set to response, then promise will be resolved.
// * @param property - The TO_MANY Association field
// * @param fields - Additional fields to retrieve on the TO_MANY field
// */
// Many(property: string, fields: Array<string>): Promise<AxiosResponse> {
// Return this.http.get(`${this.endpoint}${this.value.id}/${property}`, {
// Params: {
// Fields: fields,
// ShowTotalMatched: true
// }
// }).then((response: AxiosResponse) => {
// If (!this.value.hasOwnProperty(property)) {
// Object.defineProperty(this, property, {
// Get: function getter() {
// Return this.value[property];
// },
// Set: function setter(value) {
// This.value[property] = value;
// },
// Configurable: true,
// Enumerable: true
// });
// }
// This.value[property] = response.data;
// Return response;
// });
// }
/**
* Make http request to get entity's many relationship. Response will update the value of the entity object.
* @param property - The TO_MANY Association field
* @param fields - Additional fields to retrieve on the TO_MANY field
*/
many(property: string, fields: string[]): Entity<T> {
// tslint:disable-next-line:no-floating-promises
this.$entity.many(property, fields, this.value).then((response: AxiosResponse) => {
if (!this._fields.includes(property)) {
this._proxy(property);
this._fields.push(property);
}
this.value[property] = response;
this.patch({ property: response });
this._setUpObservable(this.getValue());
return response;
});
return this;
}

/**
* Create or Updates the entity based on the presence of an 'id' property
Expand Down
55 changes: 26 additions & 29 deletions src/services/EntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class EntityService<T> {
this.http = Staffing.http();
this.meta = new MetaService(this.type);
this.parameters = {
fields: this._fields || ['id'],
fields: this._fields || ['id']
};
}

Expand Down Expand Up @@ -78,35 +78,32 @@ export class EntityService<T> {
return result;
}

// /**
// * Make http request to get entity. Objects 'data' property will be set to response, then promise will be resolved.
// * @param property - The TO_MANY Association field
// * @param fields - Additional fields to retrieve on the TO_MANY field
// */
// Many(property: string, fields: Array<string>): Promise<AxiosResponse> {
// Return this.http.get(`${this.endpoint}${this.value.id}/${property}`, {
// Params: {
// Fields: fields,
// ShowTotalMatched: true
// }
// }).then((response: AxiosResponse) => {
// If (!this.value.hasOwnProperty(property)) {
// Object.defineProperty(this, property, {
// Get: function getter() {
// Return this.value[property];
// },
// Set: function setter(value) {
// This.value[property] = value;
// },
// Configurable: true,
// Enumerable: true
// });
// }
/**
* Make http request to get entity with recordedit layout. Objects 'data' property will be set to response, then promise will be resolved.
* @param id - Id of the Model to retrieve
*/
async edit(id: number): Promise<BullhornEntityResponse<T>> {
const layout = 'RecordEdit';
const [response, meta] = await Promise.all([this.http.get(`${this.endpoint}/${id}`, { params: { layout } }), this.meta.getFull(this.parameters.fields, layout)]);
const result: BullhornEntityResponse<T> = response.data;
result.meta = meta;
return result;
}

// This.value[property] = response.data;
// Return response;
// });
// }
/**
* Make http request to get entity's full toMany relationship for a property.
* @param property - The TO_MANY Association field
* @param fields - Additional fields to retrieve on the TO_MANY field
*/
async many(property: string, fields: string[], value: any): Promise<AxiosResponse> {
const toManyData = await this.http.get(`${this.endpoint}/${value.id}/${property}`, {
params: {
fields,
showTotalMatched: true
}
});
return toManyData.data;
}

/**
* Create or Updates the entity based on the presence of an 'id' property
Expand Down

0 comments on commit 1a40c72

Please sign in to comment.