Skip to content

Commit

Permalink
feat: Adds getSevUsers
Browse files Browse the repository at this point in the history
  • Loading branch information
jondewoo committed Dec 19, 2024
1 parent 287bd03 commit 033de13
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
19 changes: 14 additions & 5 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,
ModelSevUser,
ModelTag,
ModelUnity,
} from "./interfaces.js";
Expand Down Expand Up @@ -49,10 +50,7 @@ test("Get next invoice number", async () => {
});

test("Create a new invoice", async () => {
const { objects: invoiceNumber } = await sevDeskClient.getNextInvoiceNumber({
invoiceType: "RE",
useNextNumber: true,
});
const invoiceNumber = `TEST-${new Date().toISOString()}`;
const { objects: contacts } = await sevDeskClient.getContacts();

const {
Expand Down Expand Up @@ -147,7 +145,6 @@ test("Create a new invoice", async () => {
discountDelete: null,
});

console.log(invoice);
assertIsInvoice(invoice);
});

Expand Down Expand Up @@ -211,6 +208,14 @@ test("Get tags", async () => {
assert.is(tags.length > 0, true);
tags.forEach(assertIsTag);
});

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

assert.is(users.length > 0, true);
users.forEach(assertIsSevUser);
});

const assertIsInvoice = (invoice: ModelInvoice) => {
assert.is(invoice.objectName, "Invoice");
};
Expand Down Expand Up @@ -243,4 +248,8 @@ const assertIsTag = (tag: ModelTag) => {
assert.is(tag.objectName, "Tag");
};

const assertIsSevUser = (user: ModelSevUser) => {
assert.is(user.objectName, "SevUser");
};

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,
ModelSevUser,
ModelTag,
ModelUnity,
} from "./interfaces.js";
Expand Down Expand Up @@ -277,6 +278,21 @@ export class SevDeskClient {
});
}

// -------------------------------------------------------
// SevUser
// -------------------------------------------------------

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

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

// -------------------------------------------------------
// SevUser
// -------------------------------------------------------

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

0 comments on commit 033de13

Please # to comment.