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 Organization extends BaseResource { static readonly TYPE = 'organization' as const; /** * List organizations * * @throws {ApiError} * @throws {TimeoutError} */ list(queryParams?: ApiTypes.OrganizationInstancesHrefSchema) { return this.rawList(queryParams).then((body) => Utils.deserializeResponseBody( body, ), ); } /** * List organizations * * @throws {ApiError} * @throws {TimeoutError} */ rawList( queryParams?: RawApiTypes.OrganizationInstancesHrefSchema, ): Promise { return this.client.request({ method: 'GET', url: '/organizations', queryParams, }); } /** * Retrieve an organization * * @throws {ApiError} * @throws {TimeoutError} */ find( organizationId: string | ApiTypes.OrganizationData, queryParams?: ApiTypes.OrganizationSelfHrefSchema, ) { return this.rawFind(Utils.toId(organizationId), queryParams).then((body) => Utils.deserializeResponseBody( body, ), ); } /** * Retrieve an organization * * @throws {ApiError} * @throws {TimeoutError} */ rawFind( organizationId: string, queryParams?: RawApiTypes.OrganizationSelfHrefSchema, ): Promise { return this.client.request({ method: 'GET', url: `/organizations/${organizationId}`, queryParams, }); } /** * Create a new organization * * @throws {ApiError} * @throws {TimeoutError} */ create(body: ApiTypes.OrganizationCreateSchema) { return this.rawCreate( Utils.serializeRequestBody(body, { type: 'organization', attributes: ['name'], relationships: [], }), ).then((body) => Utils.deserializeResponseBody( body, ), ); } /** * Create a new organization * * @throws {ApiError} * @throws {TimeoutError} */ rawCreate( body: RawApiTypes.OrganizationCreateSchema, ): Promise { return this.client.request({ method: 'POST', url: '/organizations', body, }); } /** * Update an organization * * @throws {ApiError} * @throws {TimeoutError} */ update( organizationId: string | ApiTypes.OrganizationData, body: ApiTypes.OrganizationUpdateSchema, ) { return this.rawUpdate( Utils.toId(organizationId), Utils.serializeRequestBody(body, { id: Utils.toId(organizationId), type: 'organization', attributes: ['name'], relationships: [], }), ).then((body) => Utils.deserializeResponseBody( body, ), ); } /** * Update an organization * * @throws {ApiError} * @throws {TimeoutError} */ rawUpdate( organizationId: string, body: RawApiTypes.OrganizationUpdateSchema, ): Promise { return this.client.request({ method: 'PUT', url: `/organizations/${organizationId}`, body, }); } /** * Destroy an organization * * @throws {ApiError} * @throws {TimeoutError} */ destroy( organizationId: string | ApiTypes.OrganizationData, body: ApiTypes.OrganizationDestroySchema, ) { return this.rawDestroy( Utils.toId(organizationId), Utils.serializeRequestBody(body, { type: 'organization_destroy_request', attributes: ['otp_code', 'password'], relationships: [], }), ).then((body) => Utils.deserializeResponseBody( body, ), ); } /** * Destroy an organization * * @throws {ApiError} * @throws {TimeoutError} */ rawDestroy( organizationId: string, body: RawApiTypes.OrganizationDestroySchema, ): Promise { return this.client.request({ method: 'POST', url: `/organizations/${organizationId}/destroy`, body, }); } }