Skip to content

Commit

Permalink
feat: Add methods for listing and finding member Groups.
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-coster committed Sep 27, 2021
1 parent c0f4af2 commit b2da2d0
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/lib/BravoClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { BravoTagDefinition } from './entities/BravoTag.js';
import type { BravoEntity } from './BravoEntity.js';
import type { FavroApi } from '$types/FavroApi.js';
import { BravoWebhookDefinition } from './entities/BravoWebhook.js';
import { BravoGroup } from '$/types/Bravo.js';

export { FavroClientAuth as BravoClientAuth } from './clientLib/FavroClient.js';

Expand Down Expand Up @@ -815,6 +816,28 @@ export class BravoClient extends FavroClient {

//#endregion

//#region GROUPS

async listGroups() {
const res = (await this.requestWithReturnedEntities(
`groups`,
{ method: 'get' },
BravoGroup,
)) as BravoResponseEntities<FavroApi.Group.Model, BravoGroup>;
return res;
}

async findGroupById(groupId: string) {
const res = (await this.requestWithReturnedEntities(
`groups/${groupId}`,
{ method: 'get' },
BravoGroup,
)) as BravoResponseEntities<FavroApi.Group.Model, BravoGroup>;
return res.getFirstEntity();
}

//#endregion

private async deleteEntity(url: string) {
const res = await this.request(url, {
method: 'delete',
Expand Down
37 changes: 37 additions & 0 deletions src/lib/entities/BravoGroup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { FavroApi } from '$types/FavroApi';
import { BravoEntity } from '$lib/BravoEntity.js';

/** Hydrated Favro Organization. */
export class BravoGroup extends BravoEntity<FavroApi.Group.Model> {
get name() {
return this._data.name;
}

get groupId() {
return this._data.groupId;
}

get organizationId() {
return this._data.organizationId;
}

get creatorUserId() {
return this._data.creatorUserId;
}

get memberCount() {
return this._data.memberCount;
}

get members() {
return [...this._data.members];
}

equals(group: BravoGroup) {
return (
this.hasSameConstructor(group) &&
this.organizationId === group.organizationId &&
this.groupId === group.groupId
);
}
}
1 change: 1 addition & 0 deletions src/types/Bravo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export { BravoTagDefinition } from '$lib/entities/BravoTag.js';
export { BravoUser } from '$lib/entities/BravoUser.js';
export { BravoWidget } from '$lib/entities/BravoWidget.js';
export { BravoWebhookDefinition } from '$lib/entities/BravoWebhook.js';
export { BravoGroup } from '$lib/entities/BravoGroup.js';
19 changes: 19 additions & 0 deletions src/types/FavroApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,24 @@ export namespace FavroApi {
}
}

export namespace Group {
/**
* The data model returned by the Favro API for Groups.
*/
export interface Model {
groupId: string;
organizationId: string;
name: string;
creatorUserId: string;
memberCount: number;
members: { userId: string; role: FavroApi.Group.ModelFieldValue.Role }[];
}

export namespace ModelFieldValue {
export type Role = 'administrator' | 'member';
}
}

/** Favro API Model model for Collections. */
export namespace Collection {
/**
Expand Down Expand Up @@ -584,6 +602,7 @@ export namespace FavroApi {
export interface Assignment {
userId: string;
completed: boolean;
isGroup?: boolean;
}
/** 📄 https://favro.com/developer/#card-time-on-board */
export interface TimeOnBoard {
Expand Down

0 comments on commit b2da2d0

Please sign in to comment.