Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
ISSUE-7985: The topics for the "Company User" mutations have been cre…
Browse files Browse the repository at this point in the history
…ated
  • Loading branch information
andrewbess authored and Andrii Beziazychnyi committed Oct 21, 2020
1 parent 2f1dd22 commit 9b7229d
Show file tree
Hide file tree
Showing 4 changed files with 441 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/_data/toc/graphql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ pages:
edition: b2b-only
exclude_versions: ["2.3"]

- label: createCompanyUser mutation
url: /graphql/mutations/create-company-user.html
edition: b2b-only
exclude_versions: ["2.3"]

- label: createCustomer mutation
url: /graphql/mutations/create-customer.html

Expand Down Expand Up @@ -260,6 +265,11 @@ pages:
edition: b2b-only
exclude_versions: ["2.3"]

- label: deleteCompanyUser mutation
url: /graphql/mutations/delete-company-user.html
edition: b2b-only
exclude_versions: ["2.3"]

- label: deleteCustomerAddress mutation
url: /graphql/mutations/delete-customer-address.html

Expand Down Expand Up @@ -377,6 +387,11 @@ pages:
edition: b2b-only
exclude_versions: ["2.3"]

- label: updateCompanyUser mutation
url: /graphql/mutations/update-company-user.html
edition: b2b-only
exclude_versions: ["2.3"]

- label: updateCustomer mutation
url: /graphql/mutations/update-customer.html

Expand Down
179 changes: 179 additions & 0 deletions src/guides/v2.4/graphql/mutations/create-company-user.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
---
group: graphql
title: createCompanyUser mutation
contributor_name: Atwix
contributor_link: https://www.atwix.com/
b2b_only: true
---

Use the `createCompanyUser` mutation to create a new company user or add a user from the existing customer for your company.

The `target_id` input attribute allows you to specify which node in the company structure will be the parent node of the company user. If you do not specify a value, the user will be assigned to the top-level (root) node of the company structure.

You can get the `target_id` and the `role_id` with the [`company`]({{page.baseurl}}/graphql/queries/company.html) query.

## Syntax

```graphql
mutation {
createCompanyUser(
input: CompanyUserCreateInput!
) {
CreateCompanyUserOutput
}
}
```

## Example usage

The following example shows the minimal payload for adding a new customer to a customer's company.

**Request:**

```graphql
mutation {
createCompanyUser(
input: {
email: "[email protected]"
firstname: "John"
lastname: "Doe"
job_title: "User"
role_id: "MQ=="
status: ACTIVE
telephone: "1234567890"
}
) {
user {
created_at
email
}
}
}
```

**Response:**

```json
{
"data": {
"createCompanyUser": {
"user": {
"created_at": "2020-10-15 23:33:49",
"email": "[email protected]"
}
}
}
}
```

This example creates a new company user of the parent company team specified in the `target_id` field.

**Request:**

```graphql
mutation {
createCompanyUser(
input: {
email: "[email protected]"
firstname: "Jane"
lastname: "Doe3"
job_title: "User"
role_id: "NTc="
status: ACTIVE
telephone: "1234567890"
target_id: "OA=="
}
) {
user {
created_at
email
firstname
lastname
job_title
role {
id
name
}
team {
id
name
structure_id
}
status
telephone
}
}
}
```

**Response:**

```json
{
"data": {
"createCompanyUser": {
"user": {
"created_at": "2020-10-15 23:39:11",
"email": "[email protected]",
"firstname": "Jane",
"lastname": "Doe",
"job_title": "User",
"role": {
"id": "NTc=",
"name": "Default User"
},
"team": {
"id": "MQ==",
"name": "Test Team",
"structure_id": "Mg=="
},
"status": "ACTIVE",
"telephone": "1234567890"
}
}
}
}
```

## Input attributes

The `CompanyUserCreateInput` input object defines the company user data.

### CompanyUserCreateInput attributes {#CompanyUserCreateInput}

The `CompanyUserCreateInput` object contains the following attributes:

Attribute | Data Type | Description
--- | --- | ---
`email` | String! | Company user's email address
`firstname` | String! | Company user's first name
`lastname` | String! | Company user's last name
`job_title` | String! | Company user's job title
`role_id` | ID! | Company user's role ID
`status` | CompanyUserStatusEnum! | Indicates whether the company user is ACTIVE or INACTIVE
`telephone` | String! | Company user's phone number
`target_id` | ID | The ID of a node within a company's structure. This ID will be the parent of the created company user

## Output attributes

The `CreateCompanyUserOutput` output object contains the following attribute:

Attribute | Data Type | Description
--- | --- | ---
`user` | Customer! | Contains company user data

### Customer attributes {#Customer}

{% include graphql/customer-output-24.md %}

## Errors

Error | Description
--- | ---
`Invitation was sent to an existing customer, they will be added to your organization once they accept the invitation.` | The customer with email provided in the `input`.`email` argument belongs to an existing customer. The invitation was sent to an existing customer. The customer will assign to the company after accepting the invitation.
`A customer with the same email already assigned to company.` | The email provided in the `input`.`email` argument belongs to an existing customer and the customer has already assigned to the company.
`"Email" is not a valid email address.` | The value provided in the `input`.`email` argument has an invalid format.
`Field "createCompanyUser" argument "input" requires type String!, found xxx.` | The value specified in the one of the `input` arguments has an invalid type.
`Field "xxx" is not defined by type CompanyUserCreateInput.` | The `input`.`xxx` argument is undefined.
`Required parameters are missing: xxx` | The `input`.`xxx` argument was omitted or contains an empty value.
`No such entity with roleId = xxx` | The company role with ID `xxx` doesn't exist.
76 changes: 76 additions & 0 deletions src/guides/v2.4/graphql/mutations/delete-company-user.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
group: graphql
title: deleteCompanyUser mutation
contributor_name: Atwix
contributor_link: https://www.atwix.com/
b2b_only: true
---

Use the `deleteCompanyUser` mutation to deactivate a company user by ID.

You can get the user ID with the [`company`]({{page.baseurl}}/graphql/queries/company.html) query.

## Syntax

```graphql
mutation {
deleteCompanyUser(
id: ID!
) {
DeleteCompanyUserOutput
}
}
```

## Example usage

The following example deactivates the user specified in ID.

**Request:**

```graphql
mutation {
deleteCompanyUser(
id: "Mg=="
) {
success
}
}
```

**Response:**

```json
{
"data": {
"deleteCompanyUser": {
"success": true
}
}
}
```

## Input attributes

The `deleteCompanyUser` mutation requires the following input:

Attribute | Data Type | Description
--- | --- | ---
`id` | ID! | The encoded user ID to deactivate

## Output attributes

The `deleteCompanyUser` mutation returns a Boolean value that indicates whether the operation was successful.

Attribute | Data Type | Description
--- | --- | ---
`success` | Boolean! | A value of `true` indicates the company user has been deactivated successfully, otherwise a value returns `false`

## Errors

Error | Description
--- | ---
`You do not have authorization to perform this action.` | The user with ID provided in the `input`.`id` argument not available to your company or you have no permissions for this operation.
`You cannot delete yourself.` | You have no a possibility to deactivate yourself.
`A customer with the same email address already exists in an associated website` | The email provided in the `input`.`email` argument has already exist to another user.
`The user XXX is the company admin and cannot be set to inactive. You must set another user as the company admin first.` | The company owner cannot be deactivated. You must set another user as the company admin first.
Loading

0 comments on commit 9b7229d

Please sign in to comment.