import * as Utils from '@datocms/rest-client-utils'; import BaseResource from '../../BaseResource.js'; import type * as ApiTypes from '../ApiTypes.js'; import type * as RawApiTypes from '../RawApiTypes.js'; export default class OrganizationMandate extends BaseResource { static readonly TYPE = 'organization_mandate' as const; /** * Update an organization mandate * * @throws {ApiError} * @throws {TimeoutError} */ update( organizationMandateId: string | ApiTypes.OrganizationMandateData, body: ApiTypes.OrganizationMandateUpdateSchema, ) { return this.rawUpdate( Utils.toId(organizationMandateId), Utils.serializeRequestBody( body, { id: Utils.toId(organizationMandateId), type: 'organization_mandate', attributes: [], relationships: ['additional_enabled_plans'], }, ), ).then((body) => Utils.deserializeResponseBody( body, ), ); } /** * Update an organization mandate * * @throws {ApiError} * @throws {TimeoutError} */ rawUpdate( organizationMandateId: string, body: RawApiTypes.OrganizationMandateUpdateSchema, ): Promise { return this.client.request( { method: 'PUT', url: `/organization-mandates/${organizationMandateId}`, body, }, ); } /** * List all mandates that the organization has approved * * @throws {ApiError} * @throws {TimeoutError} */ approvedList() { return this.rawApprovedList().then((body) => Utils.deserializeResponseBody( body, ), ); } /** * List all mandates that the organization has approved * * @throws {ApiError} * @throws {TimeoutError} */ rawApprovedList(): Promise { return this.client.request( { method: 'GET', url: '/organization-mandates/approved', }, ); } /** * List all mandates that the organization has been given * * @throws {ApiError} * @throws {TimeoutError} */ givenList( queryParams?: ApiTypes.OrganizationMandateGivenInstancesHrefSchema, ) { return this.rawGivenList(queryParams).then((body) => Utils.deserializeResponseBody( body, ), ); } /** * List all mandates that the organization has been given * * @throws {ApiError} * @throws {TimeoutError} */ rawGivenList( queryParams?: RawApiTypes.OrganizationMandateGivenInstancesHrefSchema, ): Promise { return this.client.request( { method: 'GET', url: '/organization-mandates/given', queryParams, }, ); } /** * Cancel an organization mandate * * @throws {ApiError} * @throws {TimeoutError} */ destroy(organizationMandateId: string | ApiTypes.OrganizationMandateData) { return this.rawDestroy(Utils.toId(organizationMandateId)).then((body) => Utils.deserializeResponseBody( body, ), ); } /** * Cancel an organization mandate * * @throws {ApiError} * @throws {TimeoutError} */ rawDestroy( organizationMandateId: string, ): Promise { return this.client.request( { method: 'DELETE', url: `/organization-mandates/${organizationMandateId}`, }, ); } }