Skip to content

Commit 1db8a96

Browse files
committed
updates
1 parent fffb23e commit 1db8a96

File tree

5 files changed

+85
-7
lines changed

5 files changed

+85
-7
lines changed

src/api/boards.ts

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
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';
44
import { Members } from './members';
55

66
export 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
}

src/interfaces/request.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
export interface Request<T = never> {
1+
export interface Request {
22
url: string;
33
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
44
headers?: Record<string, string | number>;
55
query?: Record<string, string | number>;
6-
body?: T;
6+
body?: object;
77
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { z } from 'zod';
2+
import { trelloIdSchema } from '~/schemas/common/trelloIdSchema';
3+
4+
export const createCustomFieldSchema = z.object({
5+
6+
boardId: trelloIdSchema,
7+
/**
8+
* The name of the Custom Field
9+
*/
10+
name: z.string(),
11+
/**
12+
* The type of Custom Field to create.
13+
*/
14+
type: z.enum(['checkbox', 'list', 'number', 'text', 'date']),
15+
pos: z.union([z.string(), z.number()]),
16+
/**
17+
* Whether this Custom Field should be shown on the front of Cards
18+
*
19+
* @default true
20+
*/
21+
cardFront: z.boolean().optional(),
22+
}).strict();
23+
24+
export type CreateCustomField = z.infer<typeof createCustomFieldSchema>;

src/schemas/api/boards/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './boardSchema';
22
export * from './createBoardSchema';
3+
export * from './createCustomFieldSchema';

tests/integration/api/boards.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('Boards Service Integration Tests', () => {
2626
});
2727

2828
it('should successfully get custom fields', async () => {
29-
const customFields = await trelloClient.boards.getCustomFields('639cdbf9f5557e00df01180d'); // todo
29+
const customFields = await trelloClient.boards.getAllCustomFields('639cdbf9f5557e00df01180d'); // todo
3030

3131
console.log(customFields);
3232
})

0 commit comments

Comments
 (0)