Skip to content

Commit

Permalink
feat: Complete types for updating a Card.
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-coster committed Jul 6, 2021
1 parent 714cc1d commit 47dbdd9
Show file tree
Hide file tree
Showing 2 changed files with 181 additions and 126 deletions.
150 changes: 24 additions & 126 deletions src/types/FavroCardTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,7 @@ export type FavroApiGetCardsParams =

// FOR SETTING VALUES ON A CARD

interface DataFavroCustomFieldMembers {
/** The list of members, that will be added to the card custom field (array of userIds).*/
addUserIds: string[];
/** The list of members, that will be removed from card custom field (array of userIds).*/
removeUserIds: string[];
/** The list of card assignment, that will update their statuses on the custom field accordingly.*/
completeUsers: string[];
}
interface DataFavroCustomFieldTags {
/** The list of tag names or card tags that will be added to this card custom field. If the tag does not exist in the organization it will be created.*/
addTags: string[];
/** A list of tagIds that will be added to this card custom field.*/
addTagIds: string[];
/** The list of tag names, that will be removed from this card custom field.*/
removeTags: string[];
/** The list of tag IDs, that will be removed from this card custom field.*/
removeTagIds: string[];
}

/**
*
*
* {@link https://favro.com/developer/#card-custom-fields}
*/
export type DataFavroCardCustomField = { customFieldId: string } & (
Expand All @@ -88,51 +67,53 @@ export type DataFavroCardCustomField = { customFieldId: string } & (
| DataFavroCardFieldVote
);

interface DataFavroCardFieldNumber {
export interface DataFavroCardFieldNumber {
/** The total value of the field. */
total: number;
}
interface DataFavroCardFieldTime {

export interface DataFavroCardFieldTimeUserReport {
/** The id of the user entry. */
reportId: string;
/** The user entry value. Passing 0 will remove report entry. For custom fields with type "Time", this value is in milliseconds. */
value: number;
/** The description of the time report entry. */
description: string;
/** The report date in ISO format. */
createdAt: string;
}
export interface DataFavroCardFieldTime {
/** The total value of all time reported by all users. */
total: number;
/**
* The values reported by each user.
* The object key represents the userId of the user.
* The value is an array of user entries. Refer to custom field time user reports. */
reports: {
[userId: string]: {
/** The id of the user entry. */
reportId: string;
/** The user entry value. Passing 0 will remove report entry. For custom fields with type "Time", this value is in milliseconds. */
value: number;
/** The description of the time report entry. */
description: string;
/** The report date in ISO format. */
createdAt: string;
}[];
[userId: string]: DataFavroCardFieldTimeUserReport[];
};
}
interface DataFavroCardFieldText {
export interface DataFavroCardFieldText {
/** The value of the field. */
value: string;
}
interface DataFavroCardFieldRating {
export interface DataFavroCardFieldRating {
/** The value of the field. Valid value is integer from 0 to 5. */
total: 0 | 1 | 2 | 3 | 4 | 5;
}
interface DataFavroCardFieldVote {
export interface DataFavroCardFieldVote {
/** The id array of users that vote for the field. */
value: string[];
}
interface DataFavroCardFieldCheckbox {
export interface DataFavroCardFieldCheckbox {
/** The value of the field. */
value: boolean;
}
interface DataFavroCardFieldDate {
export interface DataFavroCardFieldDate {
/** The date value in ISO format. */
value: string;
}
interface DataFavroCardFieldTimeline {
export interface DataFavroCardFieldTimeline {
/** The value options of the field. See custom field timeline. */
timeline: {
/** The value of start date in ISO format. Required. */
Expand All @@ -143,7 +124,7 @@ interface DataFavroCardFieldTimeline {
showTime: boolean;
};
}
interface DataFavroCardFieldLink {
export interface DataFavroCardFieldLink {
/** The value options of the field. See custom field link. */
link: {
/** The url of the field. Required. */
Expand All @@ -160,11 +141,11 @@ interface DataFavroCardFieldTags {
/** The id array of tags that are added to card. */
value: string[];
}
interface DataFavroCardFieldStatus {
export interface DataFavroCardFieldStatus {
/** The id array of item that are added to card. */
value: string[];
}
interface DataFavroCardFieldMultipleSelect {
export interface DataFavroCardFieldMultipleSelect {
/** The id array of item that are added to card. */
value: string[];
}
Expand Down Expand Up @@ -192,7 +173,7 @@ interface DataFavroCardTimeOnBoard {
}

/** {@link https://favro.com/developer/#card-favro-attachment} */
interface DataFavroCardFavroAttachment {
export interface DataFavroCardFavroAttachment {
/**
* The cardCommonId of card or widgetCommonId of widget that
* is linked to the card. */
Expand Down Expand Up @@ -316,86 +297,3 @@ export interface DataFavroCard {
/** The Favro attachments on the card. See card favro attachment. */
favroAttachments: DataFavroCardFavroAttachment[];
}

/**
* Body parameters for updating a Card.
*
* Note that `cardId` must be specified in the URL,
* and `descriptionFormat` should be set to `'markdown'`
* in the query params so that the returned result will
* have a Markdown body.
*
* {@link https://favro.com/developer/#update-a-card}
*/
export interface FavroApiParamsCardUpdate {
/** The name of the card. */
name?: string;
/** The detailed description of the card. Supports formatting. */
detailedDescription?: string;
/** The widgetCommonId to commit the card in (if adding to a Widget). */
widgetCommonId?: string;
/** The columnId to commit the card in. It must belong to the widget specified in the widgetCommonId parameter. */
columnId?: string;
/** The laneId to commit the card in. This is only applicable if creating the card on a widget that has lanes enabled. */
laneId?: string;
/** The id of the parent card in the card hierarchy (sheet or card list), where the card will be commited. It must belong to the widget specified in the widgetCommonId parameter. */
parentCardId?: string;
/** 'commit' to commit card, 'move' to move card. 'commit' by default. */
dragMode?: 'commit' | 'move';
/**
* @deprecated
* Mapped to listPosition for right-pane widgets, and to sheetPosition for left-pane widgets.
*/
position?: number;
/** New position of the card in a column on a Kanban board, or in a todo list. */
listPosition?: number;
/** New position of the card in a hierarchical view (sheet or card list).*/
sheetPosition?: number;
/** The list of assignments, that will be added to card (array of userIds).*/
addAssignmentIds?: string[];
/** The list of assignments, that will be removed from card (array of userIds).*/
removeAssignmentIds?: string[];
/** The list of card assignment, that will update their statuses accordingly.*/
completeAssignments?: string[];
/** The list of tag names or card tags that will be added to the card. If the tag does not exist in the organization it will be created.*/
addTags?: string[];
/** A list of tagIds that will be added to card.*/
addTagIds?: string[];
/** The list of tag names, that will be removed from card.*/
removeTags?: string[];
/** The list of tag IDs, that will be removed from card.*/
removeTagIds?: string[];
/** The start date of card. Format ISO-8601. If null, start date will be removed.*/
startDate?: string;
/** The due date of card. Format ISO-8601. If null, due date will be removed.*/
dueDate?: string;
/** The list of card tasklists, that will be added to card.*/
addTasklists?: {
name: string;
tasks: (string | { name: string; completed?: boolean })[];
}[];
/**
* The list of card attachments URLs, that will be removed from the card.
*
* @note Unclear what URL is being referenced here. Best guess is the
* `fileURL` field from an attachment object.
*/
removeAttachments?: string[];
/**
* The list of card custom field parameters, that will be added or modified.
*
* // TODO
*/
customFields?: unknown[];
/** The list of card favro attachment that will be added to the card.*/
addFavroAttachments?: DataFavroCardFavroAttachment[];
/**
* The list of cardCommonId and widgetCommonId of card
* favro attachment, that will be removed from the card.
*
* @note Presumably this is the `itemCommonId` field value
*/
removeFavroAttachmentIds?: string[];
/** Archive or unarchive card.*/
archive: boolean;
}
157 changes: 157 additions & 0 deletions src/types/FavroCardUpdateTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import type {
DataFavroCardFieldNumber,
DataFavroCardFieldText,
DataFavroCardFieldStatus,
DataFavroCardFieldMultipleSelect,
DataFavroCardFieldCheckbox,
DataFavroCardFieldDate,
DataFavroCardFieldLink,
DataFavroCardFieldRating,
DataFavroCardFieldTimeline,
DataFavroCardFavroAttachment,
DataFavroCardFieldTimeUserReport,
} from './FavroCardTypes';

interface DataFavroCardFieldMembersUpdate {
/** The list of members, that will be added to the card custom field (array of userIds).*/
addUserIds: string[];
/** The list of members, that will be removed from card custom field (array of userIds).*/
removeUserIds: string[];
/** The list of card assignment, that will update their statuses on the custom field accordingly.*/
completeUsers: string[];
}
interface DataFavroCardFieldTagsUpdate {
/** The list of tag names or card tags that will be added to this card custom field. If the tag does not exist in the organization it will be created.*/
addTags: string[];
/** A list of tagIds that will be added to this card custom field.*/
addTagIds: string[];
/** The list of tag names, that will be removed from this card custom field.*/
removeTags: string[];
/** The list of tag IDs, that will be removed from this card custom field.*/
removeTagIds: string[];
}

interface DataFavroCardFieldTimeUpdate {
/** The user report to be added. See custom field time user reports. Optional. */
addUserReports: DataFavroCardFieldTimeUserReport;
/** The user report to be updated. See custom field time user reports. Optional. */
updateUserReports: DataFavroCardFieldTimeUserReport;
/** The user report to be removed. See custom field time user reports. Optional */
removeUserReports: DataFavroCardFieldTimeUserReport;
}

interface DataFavroCardFieldVoteUpdate {
/**
* The value to determine the field should be either voted or unvoted.
*
* @note It's unclear if this refers to the CURRENT user (the one who
* ownes the API token). Presumably it does?
*/
value: boolean;
}

/**
* These strongly overlap, but are not identical to, the CustomField
* object shapes returned by the API.
*
* {@link https://favro.com/developer/#card-custom-field-parameters}
*/
export type FavroApiParamsCardUpdateCustomField = { customFieldId: string } & (
| DataFavroCardFieldCheckbox
| DataFavroCardFieldDate
| DataFavroCardFieldLink
| DataFavroCardFieldMultipleSelect
| DataFavroCardFieldNumber
| DataFavroCardFieldRating
| DataFavroCardFieldStatus
| DataFavroCardFieldText
| DataFavroCardFieldTimeline
| DataFavroCardFieldMembersUpdate
| DataFavroCardFieldTagsUpdate
| DataFavroCardFieldTimeUpdate
| DataFavroCardFieldVoteUpdate
);

/**
* Body parameters for updating a Card.
*
* Note that `cardId` must be specified in the URL,
* and `descriptionFormat` should be set to `'markdown'`
* in the query params so that the returned result will
* have a Markdown body.
*
* {@link https://favro.com/developer/#update-a-card}
*/
export interface FavroApiParamsCardUpdate {
/** The name of the card. */
name?: string;
/** The detailed description of the card. Supports formatting. */
detailedDescription?: string;
/** The widgetCommonId to commit the card in (if adding to a Widget). */
widgetCommonId?: string;
/** The columnId to commit the card in. It must belong to the widget specified in the widgetCommonId parameter. */
columnId?: string;
/** The laneId to commit the card in. This is only applicable if creating the card on a widget that has lanes enabled. */
laneId?: string;
/** The id of the parent card in the card hierarchy (sheet or card list), where the card will be commited. It must belong to the widget specified in the widgetCommonId parameter. */
parentCardId?: string;
/** 'commit' to commit card, 'move' to move card. 'commit' by default. */
dragMode?: 'commit' | 'move';
/**
* @deprecated
* Mapped to listPosition for right-pane widgets, and to sheetPosition for left-pane widgets.
*/
position?: number;
/** New position of the card in a column on a Kanban board, or in a todo list. */
listPosition?: number;
/** New position of the card in a hierarchical view (sheet or card list).*/
sheetPosition?: number;
/** The list of assignments, that will be added to card (array of userIds).*/
addAssignmentIds?: string[];
/** The list of assignments, that will be removed from card (array of userIds).*/
removeAssignmentIds?: string[];
/** The list of card assignment, that will update their statuses accordingly.*/
completeAssignments?: string[];
/** The list of tag names or card tags that will be added to the card. If the tag does not exist in the organization it will be created.*/
addTags?: string[];
/** A list of tagIds that will be added to card.*/
addTagIds?: string[];
/** The list of tag names, that will be removed from card.*/
removeTags?: string[];
/** The list of tag IDs, that will be removed from card.*/
removeTagIds?: string[];
/** The start date of card. Format ISO-8601. If null, start date will be removed.*/
startDate?: string;
/** The due date of card. Format ISO-8601. If null, due date will be removed.*/
dueDate?: string;
/** The list of card tasklists, that will be added to card.*/
addTasklists?: {
name: string;
tasks: (string | { name: string; completed?: boolean })[];
}[];
/**
* The list of card attachments URLs, that will be removed from the card.
*
* @note Unclear what URL is being referenced here. Best guess is the
* `fileURL` field from an attachment object.
*/
removeAttachments?: string[];
/**
* The list of card custom field parameters, that will be added or modified.
*
* @note Value objects are VERY similar to those that appear in the same
* field upon fetching a Card, but there are some differences.
*/
customFields?: unknown[];
/** The list of card favro attachment that will be added to the card.*/
addFavroAttachments?: DataFavroCardFavroAttachment[];
/**
* The list of cardCommonId and widgetCommonId of card
* favro attachment, that will be removed from the card.
*
* @note Presumably this is the `itemCommonId` field value
*/
removeFavroAttachmentIds?: string[];
/** Archive or unarchive card.*/
archive: boolean;
}

0 comments on commit 47dbdd9

Please sign in to comment.