Skip to content

Commit

Permalink
feat: Adds getParts
Browse files Browse the repository at this point in the history
  • Loading branch information
jondewoo committed Dec 19, 2024
1 parent 202eeaa commit f0bbb2d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ModelDocument,
ModelDocumentFolder,
ModelInvoice,
ModelPart,
ModelPaymentMethod,
ModelSevUser,
ModelStaticCountry,
Expand Down Expand Up @@ -243,6 +244,13 @@ test("Get static countries", async () => {
countries.forEach(assertIsStaticCountry);
});

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

assert.is(parts.length > 0, true);
parts.forEach(assertIsPart);
});

const assertIsInvoice = (invoice: ModelInvoice) => {
assert.is(invoice.objectName, "Invoice");
};
Expand Down Expand Up @@ -287,4 +295,8 @@ const assertIsStaticCountry = (user: ModelStaticCountry) => {
assert.is(user.objectName, "StaticCountry");
};

const assertIsPart = (part: ModelPart) => {
assert.is(part.objectName, "Part");
};

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 {
ModelDocument,
ModelDocumentFolder,
ModelInvoice,
ModelPart,
ModelPaymentMethod,
ModelSevUser,
ModelStaticCountry,
Expand Down Expand Up @@ -332,6 +333,21 @@ export class SevDeskClient {
});
}

// -------------------------------------------------------
// Part
// -------------------------------------------------------

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

return this.request<{ objects: Array<Required<ModelPart>> }>(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 @@ -185,4 +185,15 @@ export class SevDeskUrls {
query,
});
}

// -------------------------------------------------------
// Part
// -------------------------------------------------------

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

0 comments on commit f0bbb2d

Please # to comment.