Skip to content

Commit

Permalink
feat: adding contact update
Browse files Browse the repository at this point in the history
  • Loading branch information
JannikZed committed May 22, 2023
1 parent 5f2efb0 commit 5c51edd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const zoho = new Zoho(
|Entity|Functions|
|---|---|
|bankaccount|`list`|
|contact|`create`, `get`, `delete`, `list`, `addAddress`,`updateAddress`, `listContactPersons`|
|contact|`create`, `get`, `update`, `delete`, `list`, `addAddress`,`updateAddress`, `listContactPersons`|
|contactperson|`create`, `get`, `delete`, `list`|
|invoice|`create`, `get`, `delete`, `list`, `createFromSalesOrder`, `sent`|
|item|`create`, `get`, `delete`, `list`, `createGroup`, `deleteGroup`, `getComposite`|
Expand Down
9 changes: 9 additions & 0 deletions src/service/contact.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ describe("Contact Tests", () => {
expect(response.length).toBeGreaterThan(0);
});

test("It should work to update a contact", async () => {
const updateContact = {
contact_id: contactIds[0],
contact_name: "Neuer Name"
}
const response = await zoho.contact.update(updateContact);
expect(response.contact_name).toBe("Neuer Name")
});

test("It should work to delete a contact", async () => {
await zoho.contact.delete(contactIds);
});
Expand Down
21 changes: 20 additions & 1 deletion src/service/contact.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { Contact, CreateContact, GetContact } from "../types/contact";
import {
Contact,
CreateContact,
GetContact,
UpdateContact,
} from "../types/contact";
import { ZohoApiClient } from "../client/client";
import { CreateAddress } from "../types/address";
import { sleep } from "../util/retry";
Expand Down Expand Up @@ -29,6 +34,20 @@ export class ContactHandler {
return res.contact;
}

/**
* Update a contact. User the contact_person array to add first name and last name to the contact
* @param contact
* @returns
*/
public async update(contact: UpdateContact): Promise<GetContact> {
const res = await this.client.put<{ contact: GetContact }>({
path: ["contacts", contact.contact_id.toString()],
body: contact,
});

return res.contact;
}

public async get(id: string): Promise<GetContact | null> {
const res = await this.client.get<{ contact?: GetContact }>({
path: ["contacts", id],
Expand Down
2 changes: 1 addition & 1 deletion src/types/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export type UpdateContact =
/**
* Required fields
*/
Pick<Contact, "contact_name"> &
Pick<Contact, "contact_id"> &
/**
* Optional fields
*/
Expand Down

0 comments on commit 5c51edd

Please sign in to comment.