Bỏ qua, đến nội dung

API reference

App resource

app:getInfo

Trả về thông tin ứng dụng.

GET /api/app:getInfo

Response:

json
{
  "data": {
    "database": { "dialect": "postgres" },
    "version": "1.0.0",
    "lang": "vi-VN",
    "theme": "default",
    "enabledLanguages": ["vi-VN", "en-US"],
    "plugins": { "acl": true, "users": true }
  }
}

app:getLang

Lấy ngôn ngữ hiện tại và toàn bộ bản dịch.

GET /api/app:getLang?locale=vi-VN

Response:

json
{
  "data": {
    "lang": "vi-VN",
    "resources": {
      "client": { "Menu": "Menu", "Settings": "Cài đặt" }
    }
  }
}

app:clearCache

Xóa toàn bộ cache server (schema, ACL, i18n). Yêu cầu quyền admin.

POST /api/app:clearCache

app:restart

Restart toàn bộ ứng dụng. Yêu cầu quyền admin.

POST /api/app:restart

app:refresh

Refresh app state (reload plugin, clear internal state) mà không restart process.

POST /api/app:refresh

Desktop Routes

desktopRoutes:list

Danh sách tất cả desktop routes (không lọc ACL).

GET /api/desktopRoutes:list?paginate=false

desktopRoutes:listAccessible

Danh sách routes mà user hiện tại được phép truy cập (đã lọc qua ACL + role binding).

GET /api/desktopRoutes:listAccessible

Response chỉ trả về các route có trong rolesDesktopRoutes của role hiện tại, kèm tree structure.

desktopRoutes:getAccessible

Chi tiết 1 route accessible theo filter key.

GET /api/desktopRoutes:getAccessible?filterByTk=<routeId>

desktopRoutes:create

Tạo menu mới (phiên bản cơ bản).

POST /api/desktopRoutes:create
Body: {
  "title": "Đơn hàng",
  "type": "page",
  "parentId": null,
  "icon": "ShoppingCartOutlined",
  "schemaUid": "uid_xxx"
}

desktopRoutes:createV2

Tạo menu mới kèm cascade tạo uiSchema và uiWidget qua UiWidgetRepository.ensureModel.

POST /api/desktopRoutes:createV2
Body: {
  "title": "Đơn hàng",
  "type": "page",
  "parentId": null,
  "enableTabs": true,
  "menuSchemaUid": "menu_uid",
  "tabSchemaName": "tab_name"
}

Sau khi tạo, tự động gán vào tất cả role có allowNewMenu: true.

desktopRoutes:update

Cập nhật thông tin menu.

PUT /api/desktopRoutes:update?filterByTk=<routeId>
Body: {
  "title": "Đơn hàng (cập nhật)",
  "hideInMenu": false,
  "enableHeader": true
}

desktopRoutes:destroy

Xóa menu (phiên bản cơ bản, chỉ xóa record).

DELETE /api/desktopRoutes:destroy?filterByTk=<routeId>

desktopRoutes:destroyV2

Xóa menu kèm cascade xóa uiSchemas (qua schemaUid) và uiWidgets (qua tabSchemaName).

DELETE /api/desktopRoutes:destroyV2?filterByTk=<routeId>

desktopRoutes:move

Di chuyển menu trong cây (thay đổi parentId và sort).

POST /api/desktopRoutes:move
Body: {
  "sourceId": 10,
  "targetId": 5,
  "targetScope": { "parentId": null },
  "method": "insertAfter"
}
ParamMô tả
sourceIdID menu cần di chuyển
targetIdID menu đích
targetScopeScope mới (parentId)
methodinsertBefore, insertAfter, prepend, append

Roles-Desktop Routes

roles.desktopRoutes:set

Gán danh sách desktop routes cho một role cụ thể. Thay thế toàn bộ binding cũ.

POST /api/roles/<roleName>/desktopRoutes:set
Body: {
  "desktopRouteIds": [1, 2, 5, 10]
}

Ví dụ sử dụng

Tạo menu page mới với tabs

typescript
const response = await agent.resource('desktopRoutes').createV2({
  values: {
    title: 'Quản lý đơn hàng',
    type: 'page',
    icon: 'ShoppingCartOutlined',
    enableTabs: true,
    enableHeader: true,
    displayTitle: true,
  },
});

const routeId = response.body.data.id;

Gán menu cho role

typescript
await agent.resource('roles.desktopRoutes', 'member').set({
  values: [routeId, existingRouteId],
});

Lấy menu accessible cho user hiện tại

typescript
const response = await agent.resource('desktopRoutes').listAccessible();
const menuTree = response.body.data;