Skip to content

Commit

Permalink
feat: Add Comment types to the FavroApi typings.
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-coster committed Aug 30, 2021
1 parent 8c77de3 commit 6d808ed
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 12 deletions.
5 changes: 2 additions & 3 deletions src/lib/BravoClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -612,9 +612,8 @@ export class BravoClient extends FavroClient {
method: 'post',
body,
query: { filename: basename(filename) },
})) as FavroResponse<FavroApi.Card.ModelFieldValue.Attachment, this>;
const attachment =
(await res.getParsedBody()) as FavroApi.Card.ModelFieldValue.Attachment;
})) as FavroResponse<FavroApi.Attachment.Model, this>;
const attachment = (await res.getParsedBody()) as FavroApi.Attachment.Model;
assertBravoClaim(attachment?.fileURL, `Failed to add attachment`);
return attachment;
}
Expand Down
61 changes: 52 additions & 9 deletions src/types/FavroApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,22 @@ export namespace FavroApi {
}
}

/**
* Attachments are uploaded files stored on Cards and Comments.
*
* 📄 https://favro.com/developer/#attachments
*/
export namespace Attachment {
export interface Model {
/** The name of the file. */
name: string;
/** The URL of the file. */
fileURL: string;
/** Optional thumbnail URL of the file. */
thumbnailURL: string;
}
}

/**
* Cards are the the unit of getting work done. The
* data returned from the Favro API consists of
Expand All @@ -568,13 +584,6 @@ export namespace FavroApi {
userId: string;
completed: boolean;
}

/** 📄 https://favro.com/developer/#card-attachment */
export interface Attachment {
name: string;
fileURL: string;
thumbnailURL?: string;
}
/** 📄 https://favro.com/developer/#card-time-on-board */
export interface TimeOnBoard {
/**
Expand Down Expand Up @@ -688,7 +697,7 @@ export namespace FavroApi {
tasksDone: number;
/**
* The file attachments on the card. */
attachments: ModelFieldValue.Attachment[];
attachments: Attachment.Model[];
/**
* The custom fields that are set on the card and enabled in
* the organization. */
Expand Down Expand Up @@ -917,6 +926,40 @@ export namespace FavroApi {
}
}

/**
* Comments live on Cards, but are managed independently from
* Cards via the Favro API.
*
* 📄 https://favro.com/developer/#comments
*/
export namespace Comment {
export interface Model {
/** The id of the comment. */
commentId: string;
/** The id of the organization that this comment exists in. */
organizationId: string;
/** The common id of the card that this comment exists on. */
cardCommonId: string;
/** The text of the comment. */
comment: string;
/** The id of the user that posted the comment. */
userId: string;
/** The date that the comment was posted. */
created: Date;
/** The date that the comment was last edited. Only set if the comment has been edited. */
lastUpdated: Date;
/** The file attachments on the comment. See attachments. */
attachments: Attachment.Model[];
}

export interface CreateBody {
/** The common id of the card to post the comment on. Required. */
cardCommonId: string;
/** The body of the comment. Required. */
comment: string;
}
}

/**
* When a registered Webhook triggers,
* a payload is sent to the Webhook's address
Expand Down Expand Up @@ -985,7 +1028,7 @@ export namespace FavroApi {
EventName extends ModelFieldValue.CommentEventName = any,
> extends ModelFieldValue.EventModelBase {
action: ModelFieldValue.CommentEventNamesAndActions[EventName];
comment: any; // FavroApi.Comment.Model; // TODO: Not yet type!
comment: FavroApi.Comment.Model;
}

export interface CardEventModels {
Expand Down

0 comments on commit 6d808ed

Please sign in to comment.