@datocms/cma-client
Version:
JS client for DatoCMS REST Content Management API
177 lines • 5.37 kB
JavaScript
import * as Utils from '@datocms/rest-client-utils';
import BaseResource from '../../BaseResource';
export default class MenuItem extends BaseResource {
/**
* Create a new menu item
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/menu-item/create
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
create(body) {
return this.rawCreate(Utils.serializeRequestBody(body, {
type: 'menu_item',
attributes: ['label', 'external_url', 'position', 'open_in_new_tab'],
relationships: ['item_type', 'item_type_filter', 'parent'],
})).then((body) => Utils.deserializeResponseBody(body));
}
/**
* Create a new menu item
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/menu-item/create
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawCreate(body) {
return this.client.request({
method: 'POST',
url: '/menu-items',
body,
});
}
/**
* Update a menu item
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/menu-item/update
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
update(menuItemId, body) {
return this.rawUpdate(Utils.toId(menuItemId), Utils.serializeRequestBody(body, {
id: Utils.toId(menuItemId),
type: 'menu_item',
attributes: ['label', 'external_url', 'position', 'open_in_new_tab'],
relationships: ['item_type', 'item_type_filter', 'parent'],
})).then((body) => Utils.deserializeResponseBody(body));
}
/**
* Update a menu item
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/menu-item/update
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawUpdate(menuItemId, body) {
return this.client.request({
method: 'PUT',
url: `/menu-items/${menuItemId}`,
body,
});
}
/**
* List all menu items
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/menu-item/instances
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
list(queryParams) {
return this.rawList(queryParams).then((body) => Utils.deserializeResponseBody(body));
}
/**
* List all menu items
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/menu-item/instances
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawList(queryParams) {
return this.client.request({
method: 'GET',
url: '/menu-items',
queryParams,
});
}
/**
* Retrieve a menu item
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/menu-item/self
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
find(menuItemId) {
return this.rawFind(Utils.toId(menuItemId)).then((body) => Utils.deserializeResponseBody(body));
}
/**
* Retrieve a menu item
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/menu-item/self
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawFind(menuItemId) {
return this.client.request({
method: 'GET',
url: `/menu-items/${menuItemId}`,
});
}
/**
* Delete a menu item
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/menu-item/destroy
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
destroy(menuItemId) {
return this.rawDestroy(Utils.toId(menuItemId)).then((body) => Utils.deserializeResponseBody(body));
}
/**
* Delete a menu item
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/menu-item/destroy
*
* @throws {ApiError}
* @throws {TimeoutError}
*/
rawDestroy(menuItemId) {
return this.client.request({
method: 'DELETE',
url: `/menu-items/${menuItemId}`,
});
}
/**
* Reorders a set of menu items
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/menu-item/reorder
*
* @throws {ApiError}
* @throws {TimeoutError}
*
* @deprecated This API call is to be considered private and might change without notice
*/
reorder(body) {
return this.rawReorder(Utils.serializeRequestBody(body, {
type: 'menu_item',
attributes: ['position'],
relationships: ['parent'],
})).then((body) => Utils.deserializeResponseBody(body));
}
/**
* Reorders a set of menu items
*
* Read more: https://www.datocms.com/docs/content-management-api/resources/menu-item/reorder
*
* @throws {ApiError}
* @throws {TimeoutError}
*
* @deprecated This API call is to be considered private and might change without notice
*/
rawReorder(body) {
return this.client.request({
method: 'POST',
url: '/menu-items/reorder',
body,
});
}
}
MenuItem.TYPE = 'menu_item';
//# sourceMappingURL=MenuItem.js.map