From 2723b5ccf11bcfcde55bcc19fbfd603a288b3fbb Mon Sep 17 00:00:00 2001 From: Siim Raud Date: Thu, 4 Sep 2025 09:21:32 +0300 Subject: [PATCH] fix: removing label without providing user --- .../services/ticket/ticket.service.spec.ts | 4 ++-- .../src/lib/services/ticket/ticket.ts | 21 +++++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/javascript-api/src/lib/services/ticket/ticket.service.spec.ts b/packages/javascript-api/src/lib/services/ticket/ticket.service.spec.ts index dfcb13da..47477b1c 100644 --- a/packages/javascript-api/src/lib/services/ticket/ticket.service.spec.ts +++ b/packages/javascript-api/src/lib/services/ticket/ticket.service.spec.ts @@ -1514,10 +1514,10 @@ describe('Ticket service', function () { expect(() => (TicketService.removeLabel as any)(12345)).toThrow(); }); - it('throws an error when the user is missing', function () { + it('does not throw an error when the user is missing', function () { expect(() => (TicketService.removeLabel as any)(12345, 'LABEL'), - ).toThrow(); + ).not.toThrow(); }); it('does not throw an error when the user is a number', function () { diff --git a/packages/javascript-api/src/lib/services/ticket/ticket.ts b/packages/javascript-api/src/lib/services/ticket/ticket.ts index 28e7fe70..0f4ff6a3 100644 --- a/packages/javascript-api/src/lib/services/ticket/ticket.ts +++ b/packages/javascript-api/src/lib/services/ticket/ticket.ts @@ -259,6 +259,11 @@ interface CallNextRequest extends TicketCallRequest { lines: string; } +interface LabelRemoveRequest { + value: string; + user?: string; +} + type TicketCreationResponse = Pick; export function search(search: TicketSearchCriteria): Promise> { @@ -548,10 +553,10 @@ export function setLabels( export function removeLabel( ticket: IdOrObject, label: string, - user: IdOrObject, + user?: IdOrObject, ): Promise<'success'> { const ticketId = extractId(ticket); - const userId = extractId(user); + const userId = user ? extractId(user) : undefined; if (!ticketId || typeof ticketId !== 'string') { throw new Error(ERROR_NO_TICKET_ID); @@ -561,17 +566,15 @@ export function removeLabel( throw new Error('No label given.'); } - if (!userId || typeof userId !== 'string') { - throw new Error('No user given'); - } - - const body = { + const requestBody: LabelRemoveRequest = { value: label, - user: userId, }; + if (userId) { + requestBody.user = userId; + } return ApiBase.request(`v1/tickets/${ticketId}/labels/remove`, { - body: body, + body: requestBody, method: 'POST', }).then((response: { result: 'success' }) => response.result); }