Skip to content

Commit

Permalink
feat: Add overload to allow finding a column given only its ID, for c…
Browse files Browse the repository at this point in the history
…ases where we have that but not the Widget the column comes from.
  • Loading branch information
adam-coster committed Sep 27, 2021
1 parent cdf34a8 commit 0e1681b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/lib/BravoClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,14 +472,32 @@ export class BravoClient extends FavroClient {
return await find(await this.listColumns(widgetCommonId), matchFunction);
}

async findColumnById(widgetCommonId: string, columnId: string) {
const column = await find(
await this.listColumns(widgetCommonId),
(col) => col.columnId == columnId,
);
async findColumnById(
columnCommonId: string,
): Promise<BravoColumn | undefined>;
async findColumnById(
widgetCommonId: string,
columnId: string,
): Promise<BravoColumn | undefined>;
async findColumnById(
widgetOrColumnId: string,
columnId?: string,
): Promise<BravoColumn | undefined> {
const column = columnId
? await find(
await this.listColumns(widgetOrColumnId),
(col) => col.columnId == columnId,
)
: ((await (
await this.requestWithReturnedEntities(
`columns/${widgetOrColumnId}`,
{ method: 'get' },
BravoColumn,
)
).getFirstEntity()) as BravoColumn);
assertBravoClaim(
column,
`Column with id ${columnId} does not exist on Widget with id ${widgetCommonId}`,
`Column with id ${columnId} does not exist on Widget with id ${widgetOrColumnId}`,
);
return column;
}
Expand Down
5 changes: 5 additions & 0 deletions src/test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,11 @@ describe('BravoClient', function () {
const foundColumn = await testWidget.findColumnByName(testColumnName);
assertBravoTestClaim(foundColumn);
expect(foundColumn!.equals(testColumn)).to.be.true;

expect(
(await client.findColumnById(testColumn.columnId))?.equals(foundColumn),
'Should be able to directly find',
).to.be.true;
});

it('can create a webhook', async function () {
Expand Down

0 comments on commit 0e1681b

Please sign in to comment.