@bunnyapp/api-client
Version:
Node.js client for Bunny CRM
52 lines • 1.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = tenantCreate;
const query = `mutation tenantCreate ($attributes: TenantAttributes!, $subscriptionId: ID!) {
tenantCreate (attributes: $attributes, subscriptionId: $subscriptionId) {
tenant {
code
id
name
platform {
id
name
code
}
}
errors
}
}`;
/**
* Creates a new tenant with the specified attributes
* @param {string} name Account name of the tenant
* @param {string} code Unique code for the tenant
* @param {string} platformCode Code for the platform that the tenant is on
* @param {string} accountId Id of the account that the tenant is being created for
* @param {string} subscriptionId Id of the subscription that the tenant is being created for
* @returns {Promise<NonNullable<Mutation['tenantCreate']>['tenant']>} The created tenant
*/
async function tenantCreate(name, code, platformCode, accountId, subscriptionId) {
var _a;
const variables = {
attributes: {
name,
code,
accountId,
platformCode,
},
subscriptionId,
};
const res = await this.query(query, variables);
const tenantCreate = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.tenantCreate;
if (res === null || res === void 0 ? void 0 : res.errors) {
throw new Error(res.errors.map((e) => e.message).join());
}
if (tenantCreate === null || tenantCreate === void 0 ? void 0 : tenantCreate.errors) {
throw new Error(tenantCreate.errors.join());
}
if (!(tenantCreate === null || tenantCreate === void 0 ? void 0 : tenantCreate.tenant)) {
throw new Error('Tenant not created');
}
return tenantCreate.tenant;
}
//# sourceMappingURL=tenant-create.js.map