|
| 1 | +import { CONTACT_CATEGORIES } from "../../common/constants.mjs"; |
| 2 | +import sevdesk from "../../sevdesk.app.mjs"; |
| 3 | + |
| 4 | +export default { |
| 5 | + key: "sevdesk-create-contact", |
| 6 | + name: "Create Contact", |
| 7 | + description: "Create a new contact. [See the documentation](https://api.sevdesk.de/#tag/Contact/operation/createContact)", |
| 8 | + version: "0.0.1", |
| 9 | + type: "action", |
| 10 | + props: { |
| 11 | + sevdesk, |
| 12 | + category: { |
| 13 | + type: "integer", |
| 14 | + label: "Category", |
| 15 | + description: "Category of the contact", |
| 16 | + options: CONTACT_CATEGORIES, |
| 17 | + }, |
| 18 | + parent: { |
| 19 | + propDefinition: [ |
| 20 | + sevdesk, |
| 21 | + "contactId", |
| 22 | + ], |
| 23 | + label: "Parent Contact ID", |
| 24 | + description: "The parent contact to which this contact belongs. Must be an organization", |
| 25 | + optional: true, |
| 26 | + }, |
| 27 | + surename: { |
| 28 | + type: "string", |
| 29 | + label: "First Name", |
| 30 | + description: "The first name of the contact, if it is not an organization.", |
| 31 | + optional: true, |
| 32 | + }, |
| 33 | + familyname: { |
| 34 | + type: "string", |
| 35 | + label: "Last Name", |
| 36 | + description: "The last name of the contact, if it is not an organization.", |
| 37 | + optional: true, |
| 38 | + }, |
| 39 | + name: { |
| 40 | + type: "string", |
| 41 | + label: "Name (Organization)", |
| 42 | + description: "The name of the contact, if it is an organization.", |
| 43 | + optional: true, |
| 44 | + }, |
| 45 | + additionalOptions: { |
| 46 | + type: "object", |
| 47 | + label: "Additional Options", |
| 48 | + description: "Additional parameters to set for the contact. [See the documentation](https://api.sevdesk.de/#tag/Contact/operation/createContact) for all available parameters. Example: `{ \"description\": \"Contact description\" }`", |
| 49 | + optional: true, |
| 50 | + }, |
| 51 | + }, |
| 52 | + methods: { |
| 53 | + createContact(opts = {}) { |
| 54 | + return this.sevdesk._makeRequest({ |
| 55 | + method: "POST", |
| 56 | + path: "/Contact", |
| 57 | + ...opts, |
| 58 | + }); |
| 59 | + }, |
| 60 | + }, |
| 61 | + async run({ $ }) { |
| 62 | + const { objects: response } = await this.createContact({ |
| 63 | + $, |
| 64 | + data: { |
| 65 | + category: { |
| 66 | + id: this.category, |
| 67 | + objectName: "Category", |
| 68 | + }, |
| 69 | + parent: this.parent && { |
| 70 | + id: this.parent, |
| 71 | + objectName: "Contact", |
| 72 | + }, |
| 73 | + surename: this.surename, |
| 74 | + familyname: this.familyname, |
| 75 | + name: this.name, |
| 76 | + ...this.additionalOptions, |
| 77 | + }, |
| 78 | + }); |
| 79 | + |
| 80 | + $.export("$summary", `Successfully created contact (ID: ${response.id})`); |
| 81 | + return response; |
| 82 | + }, |
| 83 | +}; |
0 commit comments