Skip to content

Commit

Permalink
Merge pull request #410 from mike-hoyle/fix-membership-create
Browse files Browse the repository at this point in the history
Fix Organization membership creation
  • Loading branch information
blakmatrix authored Apr 4, 2024
2 parents 36eca1d + f120d36 commit 130c23a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
4 changes: 3 additions & 1 deletion .xo-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@
"custom_role",
"http_method",
"request_format",
"client_id"
"client_id",
"organization_membership",
"organization_memberships"
]
}
]
Expand Down
25 changes: 13 additions & 12 deletions src/clients/core/organizationmemberships.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,32 +87,34 @@ class OrganizationMemberships extends Client {

/**
* Create a new organization membership.
* @param {object} organizationMembership - The organization membership data.
* @returns {Promise<object>} A promise resolving to the created organization membership.
* @param {OrganizationMembership} organizationMembership - The organization membership data.
* @returns {Promise<OrganizationMembership>} A promise resolving to the created organization membership.
* @async
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organization_memberships/#create-membership}
* @example
* const newMembership = await client.organizationmemberships.create({ user_id: 123, organization_id: 456 });
*/
async create(organizationMembership) {
return this.put(['organization_memberships'], organizationMembership);
return this.post(['organization_memberships'], {
organization_membership: organizationMembership,
});
}

/**
* Create a new organization membership for a specific user.
* @param {number} userID - The user ID.
* @param {object} organizationMembership - The organization membership data.
* @returns {Promise<object>} A promise resolving to the created organization membership.
* @param {number} organizationMembership.organization_id - The organization id of the membership.
* @returns {Promise<OrganizationMembership>} A promise resolving to the created organization membership.
* @async
* @see {@link https://developer.zendesk.com/api-reference/ticketing/organizations/organization_memberships/#create-membership}
* @example
* const newMembership = await client.organizationmemberships.createByUser(123, { organization_id: 456 });
*/
async createByUser(userID, organizationMembership) {
return this.put(
['users', userID, 'organization_memberships'],
organizationMembership,
);
return this.post(['users', userID, 'organization_memberships'], {
organization_membership: organizationMembership,
});
}

/**
Expand All @@ -133,10 +135,9 @@ class OrganizationMemberships extends Client {
* const jobStatus = await client.organizationmemberships.createMany([{ user_id: 123, organization_id: 456 }, ...]);
*/
async createMany(organizationMemberships) {
return this.post(
['organization_memberships', 'create_many'],
organizationMemberships,
);
return this.post(['organization_memberships', 'create_many'], {
organization_memberships: organizationMemberships,
});
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/clients/core/tickets.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
const {Client} = require('../client');

/**
* @typedef {T extends object ? { [K in keyof T]?: RecursivePartial<T[K]> } : T} RecursivePartial
* @typedef {object} RecursivePartial
* @template T
* @property {T[P]} [P] - The property of the object.
*/

/**
Expand Down

0 comments on commit 130c23a

Please sign in to comment.