diff --git a/src/lib/BravoClient.ts b/src/lib/BravoClient.ts index 809bf54..a90bfab 100644 --- a/src/lib/BravoClient.ts +++ b/src/lib/BravoClient.ts @@ -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'; @@ -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; + return res; + } + + async findGroupById(groupId: string) { + const res = (await this.requestWithReturnedEntities( + `groups/${groupId}`, + { method: 'get' }, + BravoGroup, + )) as BravoResponseEntities; + return res.getFirstEntity(); + } + + //#endregion + private async deleteEntity(url: string) { const res = await this.request(url, { method: 'delete', diff --git a/src/lib/entities/BravoGroup.ts b/src/lib/entities/BravoGroup.ts new file mode 100644 index 0000000..6c30534 --- /dev/null +++ b/src/lib/entities/BravoGroup.ts @@ -0,0 +1,37 @@ +import type { FavroApi } from '$types/FavroApi'; +import { BravoEntity } from '$lib/BravoEntity.js'; + +/** Hydrated Favro Organization. */ +export class BravoGroup extends BravoEntity { + 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 + ); + } +} diff --git a/src/types/Bravo.ts b/src/types/Bravo.ts index d71f43c..33b1d09 100644 --- a/src/types/Bravo.ts +++ b/src/types/Bravo.ts @@ -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'; diff --git a/src/types/FavroApi.ts b/src/types/FavroApi.ts index 177954c..2a831f8 100644 --- a/src/types/FavroApi.ts +++ b/src/types/FavroApi.ts @@ -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 { /** @@ -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 {