Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
21 changes: 12 additions & 9 deletions packages/javascript-api/src/lib/services/ticket/ticket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ interface CallNextRequest extends TicketCallRequest {
lines: string;
}

interface LabelRemoveRequest {
value: string;
user?: string;
}

type TicketCreationResponse = Pick<Ticket, 'id'>;

export function search(search: TicketSearchCriteria): Promise<Array<Ticket>> {
Expand Down Expand Up @@ -548,10 +553,10 @@ export function setLabels(
export function removeLabel(
ticket: IdOrObject<Ticket>,
label: string,
user: IdOrObject<User>,
user?: IdOrObject<User>,
): 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);
Expand All @@ -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);
}
Expand Down
Loading