Skip to content

Commit

Permalink
feat: Adds getTags
Browse files Browse the repository at this point in the history
  • Loading branch information
jondewoo committed Dec 12, 2024
1 parent 7d9b8a9 commit 287bd03
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ModelDocumentFolder,
ModelInvoice,
ModelPaymentMethod,
ModelTag,
ModelUnity,
} from "./interfaces.js";

Expand Down Expand Up @@ -204,6 +205,12 @@ test("Get payment methods", async () => {
paymentMethods.forEach(assertIsPaymentMethod);
});

test("Get tags", async () => {
const { objects: tags } = await sevDeskClient.getTags();

assert.is(tags.length > 0, true);
tags.forEach(assertIsTag);
});
const assertIsInvoice = (invoice: ModelInvoice) => {
assert.is(invoice.objectName, "Invoice");
};
Expand Down Expand Up @@ -232,4 +239,8 @@ const assertIsPaymentMethod = (paymentMethod: ModelPaymentMethod) => {
assert.is(paymentMethod.objectName, "PaymentMethod");
};

const assertIsTag = (tag: ModelTag) => {
assert.is(tag.objectName, "Tag");
};

test.run();
16 changes: 16 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ModelDocumentFolder,
ModelInvoice,
ModelPaymentMethod,
ModelTag,
ModelUnity,
} from "./interfaces.js";
import { SevDeskUrls } from "./urls.js";
Expand Down Expand Up @@ -261,6 +262,21 @@ export class SevDeskClient {
});
}

// -------------------------------------------------------
// Tag
// -------------------------------------------------------

/**
* Get an overview of all tags
*/
async getTags(params: UrlParamsFor<"apiGetTagsUrl"> = {}) {
const url = this.urls.apiGetTagsUrl(params);

return this.request<{ objects: Array<Required<ModelTag>> }>(url, {
method: "GET",
});
}

// // pending invoices from sevdesk includes also outstanding / due invoices
// // we remove them with a filter but you could also include the if you only need everything pending
// async getPendingInvoices(options = { includeOutstanding: false }) {
Expand Down
11 changes: 11 additions & 0 deletions src/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,15 @@ export class SevDeskUrls {
query,
});
}

// -------------------------------------------------------
// Tag
// -------------------------------------------------------

apiGetTagsUrl({ ...query }: DefaultCollectionQuery & Query = {}) {
return this.apiUrl({
path: `Tag`,
query,
});
}
}

0 comments on commit 287bd03

Please sign in to comment.