1
1
import 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' ;
4
4
import { Members } from './members' ;
5
5
6
6
export class Boards {
@@ -22,6 +22,7 @@ export class Boards {
22
22
}
23
23
24
24
async getAll ( ) {
25
+ // todo js doc
25
26
const boardsId = await this . membersClient . getBoards ( 'me' ) ;
26
27
27
28
const boards : Board [ ] = [ ] ;
@@ -55,13 +56,65 @@ export class Boards {
55
56
return this . client . sendRequest ( request ) ;
56
57
}
57
58
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
+
58
78
/** Get the Custom Field Definitions that exist on a board. */
59
- async getCustomFields ( boardId : TrelloId ) {
79
+ async getAllCustomFields ( boardId : TrelloId ) : Promise < CustomFields > {
60
80
const request : Request = {
61
81
url : `/boards/${ boardId } /customFields` ,
62
82
method : 'GET' ,
63
- }
83
+ } ;
64
84
65
85
return this . client . sendRequest ( request , customFieldsSchema ) ;
66
86
}
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
+ }
67
120
}
0 commit comments