restaurant/static/js/api.js
Padreug b7fa1aec4a refactor(http): drop categories/subcategories shim
Remove the transitional layer added in commits 1+2:

models.py
  - Drop Category, Subcategory, CreateCategory, CreateSubcategory.

crud.py
  - Drop create_category / update_category / get_category /
    get_categories / delete_category and the subcategory variants
    along with the _node_row_to_category / _node_row_to_subcategory
    helpers. Tree state is owned exclusively by menu_node CRUD now.

views_api.py
  - Remove old endpoints:
      GET    /api/v1/restaurants/{id}/categories
      POST   /api/v1/categories
      DELETE /api/v1/categories/{id}
      GET    /api/v1/categories/{id}/subcategories
      POST   /api/v1/subcategories
      DELETE /api/v1/subcategories/{id}
    Hits return 404 now.
  - GET /api/v1/restaurants/{id}/menu loses the synthetic
    'categories' projection. Response is {restaurant, tree, items}.

static/js/api.js
  - Drop listCategories / createCategory / deleteCategory and the
    subcategory wrappers.

The CMS menu builder is broken between this commit and commit 4.
The plan acknowledged this trade-off: keeping commits revertible
beats the cost of an unshipped UI page rendering a stale empty
sidebar for one commit's lifetime.
2026-05-09 07:11:06 +02:00

91 lines
3.7 KiB
JavaScript

/*
* Thin REST client for the restaurant extension CMS.
*
* Exposes window.RestaurantAPI with one method per resource.
* Every call is gated by the calling wallet's admin or invoice key
* pulled from g.user.wallets[0] (or a wallet passed in explicitly).
*/
;(function () {
const baseUrl = '/restaurant/api/v1'
function call(adminkey, method, path, body) {
return LNbits.api.request(method, baseUrl + path, adminkey, body)
}
window.RestaurantAPI = {
// Restaurants
listRestaurants: (key, allWallets = false) =>
call(key, 'GET', `/restaurants?all_wallets=${allWallets}`),
getRestaurant: (id) => call(null, 'GET', `/restaurants/${id}`),
createRestaurant: (key, data) => call(key, 'POST', '/restaurants', data),
updateRestaurant: (key, id, data) =>
call(key, 'PUT', `/restaurants/${id}`, data),
deleteRestaurant: (key, id) =>
call(key, 'DELETE', `/restaurants/${id}`),
// Menu nodes (the tree)
listMenuNodes: (restaurantId) =>
call(null, 'GET', `/restaurants/${restaurantId}/menu_nodes`),
getMenuNode: (id) => call(null, 'GET', `/menu_nodes/${id}`),
createMenuNode: (key, data) => call(key, 'POST', '/menu_nodes', data),
updateMenuNode: (key, id, data) =>
call(key, 'PUT', `/menu_nodes/${id}`, data),
moveMenuNode: (key, id, newParentId) =>
call(key, 'PUT', `/menu_nodes/${id}/move`, {new_parent_id: newParentId}),
deleteMenuNode: (key, id, cascade = false) =>
call(key, 'DELETE', `/menu_nodes/${id}?cascade=${cascade ? 'true' : 'false'}`),
// Menu items
getMenu: (id) => call(null, 'GET', `/restaurants/${id}/menu`),
getMenuItem: (id) => call(null, 'GET', `/menu_items/${id}`),
createMenuItem: (key, data) => call(key, 'POST', '/menu_items', data),
updateMenuItem: (key, id, data) =>
call(key, 'PUT', `/menu_items/${id}`, data),
deleteMenuItem: (key, id) => call(key, 'DELETE', `/menu_items/${id}`),
// Modifier groups + modifiers
listModifierGroups: (itemId) =>
call(null, 'GET', `/menu_items/${itemId}/modifier_groups`),
createModifierGroup: (key, data) =>
call(key, 'POST', '/modifier_groups', data),
deleteModifierGroup: (key, id) =>
call(key, 'DELETE', `/modifier_groups/${id}`),
listModifiers: (groupId) =>
call(null, 'GET', `/modifier_groups/${groupId}/modifiers`),
createModifier: (key, data) => call(key, 'POST', '/modifiers', data),
deleteModifier: (key, id) => call(key, 'DELETE', `/modifiers/${id}`),
// Availability windows
listAvailability: (itemId) =>
call(null, 'GET', `/menu_items/${itemId}/availability_windows`),
createAvailability: (key, data) =>
call(key, 'POST', '/availability_windows', data),
deleteAvailability: (key, id) =>
call(key, 'DELETE', `/availability_windows/${id}`),
// Orders
listOrders: (key, restaurantId, statuses, limit = 200) => {
const qs = new URLSearchParams({limit})
;(statuses || []).forEach((s) => qs.append('statuses', s))
return call(key, 'GET', `/restaurants/${restaurantId}/orders?${qs}`)
},
getOrder: (id) => call(null, 'GET', `/orders/${id}`),
placeOrder: (data) => call(null, 'POST', '/orders', data),
quoteOrder: (items) => call(null, 'POST', '/orders/quote', items),
transitionOrder: (key, id, newStatus) =>
call(key, 'PUT', `/orders/${id}/status/${newStatus}`),
// Print jobs
listPrintJobs: (key, restaurantId, status) =>
call(
key,
'GET',
`/restaurants/${restaurantId}/print_jobs${status ? `?status=${status}` : ''}`
),
ackPrintJob: (key, id) => call(key, 'PUT', `/print_jobs/${id}/ack`),
// Settings
getSettings: (key) => call(key, 'GET', '/settings'),
updateSettings: (key, data) => call(key, 'PUT', '/settings', data)
}
})()