11import type { Client , Request } from '~/interfaces' ;
2- import { boardSchema , Board , CreateBoard } from '~/schemas/api/boards' ;
3- import { customFieldsSchema , TrelloId } from '~/schemas/common' ;
2+ import { boardSchema , Board , CreateBoard , CreateCustomField } from '~/schemas/api/boards' ;
3+ import { CustomField , CustomFields , customFieldSchema , customFieldsSchema , TrelloId } from '~/schemas/common' ;
44import { Members } from './members' ;
55
66export class Boards {
@@ -22,6 +22,7 @@ export class Boards {
2222 }
2323
2424 async getAll ( ) {
25+ // todo js doc
2526 const boardsId = await this . membersClient . getBoards ( 'me' ) ;
2627
2728 const boards : Board [ ] = [ ] ;
@@ -55,13 +56,65 @@ export class Boards {
5556 return this . client . sendRequest ( request ) ;
5657 }
5758
59+ /** Create a new Custom Field on a board. */
60+ async createCustomField ( customField : CreateCustomField ) : Promise < CustomField > {
61+ const request : Request = {
62+ url : '/customFields' ,
63+ method : 'POST' ,
64+ body : {
65+ idModel : customField . boardId ,
66+ modelType : 'board' ,
67+ name : customField . name ,
68+ type : customField . type ,
69+ options : '' , // todo
70+ pos : customField . pos ,
71+ display_cardFront : customField . cardFront ?? true ,
72+ } ,
73+ } ;
74+
75+ return this . client . sendRequest ( request , customFieldSchema ) ;
76+ }
77+
5878 /** Get the Custom Field Definitions that exist on a board. */
59- async getCustomFields ( boardId : TrelloId ) {
79+ async getAllCustomFields ( boardId : TrelloId ) : Promise < CustomFields > {
6080 const request : Request = {
6181 url : `/boards/${ boardId } /customFields` ,
6282 method : 'GET' ,
63- }
83+ } ;
6484
6585 return this . client . sendRequest ( request , customFieldsSchema ) ;
6686 }
87+
88+ async getCustomField ( customFieldId : TrelloId ) : Promise < CustomField > {
89+ const request : Request = {
90+ url : `/customFields/${ customFieldId } ` ,
91+ method : 'GET' ,
92+ } ;
93+
94+ return this . client . sendRequest ( request , customFieldSchema ) ;
95+ }
96+
97+ async updateCustomField ( customFieldId : TrelloId ) : Promise < CustomField > {
98+ const request : Request = {
99+ url : `/boards/${ customFieldId } ` ,
100+ method : 'PUT' ,
101+ body : {
102+ // todo
103+ name : '' ,
104+ pos : '' ,
105+ 'display/cardFront' : false ,
106+ } ,
107+ } ;
108+
109+ return this . client . sendRequest ( request , customFieldSchema ) ;
110+ }
111+
112+ async deleteCustomField ( customFieldId : TrelloId ) : Promise < void > {
113+ const request : Request = {
114+ url : `/customFields/${ customFieldId } ` ,
115+ method : 'DELETE' ,
116+ } ;
117+
118+ return this . client . sendRequest ( request ) ;
119+ }
67120}
0 commit comments