Skip to content

Commit fda9e6c

Browse files
authored
fix: removing label without providing user (#804)
1 parent 5dd2092 commit fda9e6c

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

packages/javascript-api/src/lib/services/ticket/ticket.service.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,10 +1514,10 @@ describe('Ticket service', function () {
15141514
expect(() => (TicketService.removeLabel as any)(12345)).toThrow();
15151515
});
15161516

1517-
it('throws an error when the user is missing', function () {
1517+
it('does not throw an error when the user is missing', function () {
15181518
expect(() =>
15191519
(TicketService.removeLabel as any)(12345, 'LABEL'),
1520-
).toThrow();
1520+
).not.toThrow();
15211521
});
15221522

15231523
it('does not throw an error when the user is a number', function () {

packages/javascript-api/src/lib/services/ticket/ticket.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,11 @@ interface CallNextRequest extends TicketCallRequest {
259259
lines: string;
260260
}
261261

262+
interface LabelRemoveRequest {
263+
value: string;
264+
user?: string;
265+
}
266+
262267
type TicketCreationResponse = Pick<Ticket, 'id'>;
263268

264269
export function search(search: TicketSearchCriteria): Promise<Array<Ticket>> {
@@ -548,10 +553,10 @@ export function setLabels(
548553
export function removeLabel(
549554
ticket: IdOrObject<Ticket>,
550555
label: string,
551-
user: IdOrObject<User>,
556+
user?: IdOrObject<User>,
552557
): Promise<'success'> {
553558
const ticketId = extractId(ticket);
554-
const userId = extractId(user);
559+
const userId = user ? extractId(user) : undefined;
555560

556561
if (!ticketId || typeof ticketId !== 'string') {
557562
throw new Error(ERROR_NO_TICKET_ID);
@@ -561,17 +566,15 @@ export function removeLabel(
561566
throw new Error('No label given.');
562567
}
563568

564-
if (!userId || typeof userId !== 'string') {
565-
throw new Error('No user given');
566-
}
567-
568-
const body = {
569+
const requestBody: LabelRemoveRequest = {
569570
value: label,
570-
user: userId,
571571
};
572+
if (userId) {
573+
requestBody.user = userId;
574+
}
572575

573576
return ApiBase.request(`v1/tickets/${ticketId}/labels/remove`, {
574-
body: body,
577+
body: requestBody,
575578
method: 'POST',
576579
}).then((response: { result: 'success' }) => response.result);
577580
}

0 commit comments

Comments
 (0)