Skip to content

Commit

Permalink
- Fixed a bug with object construction where Object.entries() would t…
Browse files Browse the repository at this point in the history
…ry to use undefined for objects with no relationships

- URL Constructor will now only use `?` if there are queries to compile
  • Loading branch information
DavidArayan committed Dec 8, 2023
1 parent 0103db1 commit b277ace
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
38 changes: 21 additions & 17 deletions sdk-core/src/core/core-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,27 +146,31 @@ export abstract class CoreObject<Attributes extends CoreObjectAttributes> {

// assign new keys to our attributes
// NOTE: this could probably be optimized by using attributes directly instead of deep-copy
for (const [key, value] of Object.entries(data.object.attributes)) {
(<any>(this._attributes))[key] = value;
if (data.object.attributes) {
for (const [key, value] of Object.entries(data.object.attributes)) {
(<any>(this._attributes))[key] = value;
}
}

// we need to build the relationships of this object from the records section
// which includes all the records from any include query
for (const [_key, value] of Object.entries(data.object.relationships)) {
const relationRecord: any = (<any>value).data;

// check if the object exists in the includes section - the value
// can either be a single object or an array
// this only contains id or type but not the full record
if (Array.isArray(relationRecord)) {
const arrayRecord: Array<any> = relationRecord;

arrayRecord.forEach((record: any) => {
this._CreateRecord(data, record);
});
}
else {
this._CreateRecord(data, relationRecord);
if (data.object.relationships) {
for (const [_key, value] of Object.entries(data.object.relationships)) {
const relationRecord: any = (<any>value).data;

// check if the object exists in the includes section - the value
// can either be a single object or an array
// this only contains id or type but not the full record
if (Array.isArray(relationRecord)) {
const arrayRecord: Array<any> = relationRecord;

arrayRecord.forEach((record: any) => {
this._CreateRecord(data, record);
});
}
else {
this._CreateRecord(data, relationRecord);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion sdk-core/src/core/query/core-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export abstract class CoreQuery<T extends CoreObject<U>, U extends CoreObjectAtt
* Performs the primary request and returns the responses as an array
*/
protected async _Fetch(url: string, type: QueryFetchType): Promise<Array<T>> {
return CoreQuery.fetch<T>(this.service, this.instance, encodeURI(`${url}?${this.toString()}`), type, this._abort.signal);
return CoreQuery.fetch<T>(this.service, this.instance, encodeURI(`${url}${this._queries.length > 0 ? `?${this.toString()}` : ''}`), type, this._abort.signal);
}

/**
Expand Down

0 comments on commit b277ace

Please sign in to comment.