1
0
Fork 0
mirror of synced 2024-09-21 20:01:32 +12:00
budibase/packages/frontend-core/src/api/viewsV2.js

75 lines
1.5 KiB
JavaScript
Raw Normal View History

2023-07-19 20:15:05 +12:00
export const buildViewV2Endpoints = API => ({
/**
2023-08-31 02:47:29 +12:00
* Fetches the definition of a view
* @param viewId the ID of the view to fetch
*/
fetchDefinition: async viewId => {
return await API.get({
2023-11-11 04:16:54 +13:00
url: `/api/v2/views/${encodeURIComponent(viewId)}`,
})
},
2023-07-19 20:15:05 +12:00
/**
2023-07-20 03:18:29 +12:00
* Create a new view
* @param view the view object
2023-07-19 20:15:05 +12:00
*/
2023-07-20 09:06:08 +12:00
create: async view => {
2023-07-20 03:18:29 +12:00
return await API.post({
2023-07-20 09:06:08 +12:00
url: `/api/v2/views`,
2023-07-20 03:18:29 +12:00
body: view,
})
2023-07-19 20:15:05 +12:00
},
/**
* Updates a view
* @param view the view object
*/
update: async view => {
return await API.put({
2023-11-11 04:16:54 +13:00
url: `/api/v2/views/${encodeURIComponent(view.id)}`,
body: view,
})
},
2023-07-19 20:15:05 +12:00
/**
2023-07-20 03:18:29 +12:00
* Fetches all rows in a view
* @param viewId the id of the view
* @param query the search query
2023-08-09 00:13:27 +12:00
* @param paginate whether to paginate or not
* @param limit page size
* @param bookmark pagination cursor
* @param sort sort column
* @param sortOrder sort order
* @param sortType sort type (text or numeric)
2023-07-19 20:15:05 +12:00
*/
2023-08-09 00:13:27 +12:00
fetch: async ({
viewId,
query,
2023-08-09 00:13:27 +12:00
paginate,
limit,
bookmark,
sort,
sortOrder,
sortType,
}) => {
return await API.post({
2023-11-11 04:16:54 +13:00
url: `/api/v2/views/${encodeURIComponent(viewId)}/search`,
2023-08-09 00:13:27 +12:00
body: {
query,
2023-08-09 00:13:27 +12:00
paginate,
limit,
bookmark,
sort,
sortOrder,
sortType,
},
})
2023-07-19 20:15:05 +12:00
},
2023-07-19 22:20:19 +12:00
/**
* Delete a view
2023-07-20 03:18:29 +12:00
* @param viewId the id of the view
2023-07-19 22:20:19 +12:00
*/
2023-07-20 09:07:40 +12:00
delete: async viewId => {
2023-11-11 04:16:54 +13:00
return await API.delete({
url: `/api/v2/views/${encodeURIComponent(viewId)}`,
})
2023-07-19 22:20:19 +12:00
},
2023-07-19 20:15:05 +12:00
})