From 287bd03248ee78ee60af0d39f908e3bcf2e0725e Mon Sep 17 00:00:00 2001 From: Jonathan Derrough Date: Thu, 12 Dec 2024 21:12:22 +0100 Subject: [PATCH] feat: Adds getTags --- src/client.test.ts | 11 +++++++++++ src/client.ts | 16 ++++++++++++++++ src/urls.ts | 11 +++++++++++ 3 files changed, 38 insertions(+) diff --git a/src/client.test.ts b/src/client.test.ts index d110f3e..5f01e94 100644 --- a/src/client.test.ts +++ b/src/client.test.ts @@ -11,6 +11,7 @@ import { ModelDocumentFolder, ModelInvoice, ModelPaymentMethod, + ModelTag, ModelUnity, } from "./interfaces.js"; @@ -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"); }; @@ -232,4 +239,8 @@ const assertIsPaymentMethod = (paymentMethod: ModelPaymentMethod) => { assert.is(paymentMethod.objectName, "PaymentMethod"); }; +const assertIsTag = (tag: ModelTag) => { + assert.is(tag.objectName, "Tag"); +}; + test.run(); diff --git a/src/client.ts b/src/client.ts index 6ebd50e..17b636f 100644 --- a/src/client.ts +++ b/src/client.ts @@ -8,6 +8,7 @@ import { ModelDocumentFolder, ModelInvoice, ModelPaymentMethod, + ModelTag, ModelUnity, } from "./interfaces.js"; import { SevDeskUrls } from "./urls.js"; @@ -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> }>(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 }) { diff --git a/src/urls.ts b/src/urls.ts index 3ccd3df..91ffd4d 100644 --- a/src/urls.ts +++ b/src/urls.ts @@ -131,4 +131,15 @@ export class SevDeskUrls { query, }); } + + // ------------------------------------------------------- + // Tag + // ------------------------------------------------------- + + apiGetTagsUrl({ ...query }: DefaultCollectionQuery & Query = {}) { + return this.apiUrl({ + path: `Tag`, + query, + }); + } }