Interface (Resource)
120031. Configure in the database resource table

2. Explanation of configuration fields
In the Jianghu framework, APIs can be configured directly via the project database _resource table:
| Field | Description |
|---|---|
| accessControlTable | Data rule control table |
| resourceHook | Pre- and post-operation service methods for the protocol (see hook) |
| pageId | Primary name of the API |
| actionId | Secondary name of the API. Together with pageId, it uniquely identifies an API |
| desc | Description of the API/protocol |
| resourceType | Protocol type. - sql: handles simple CRUD operations - service: use a custom service for complex logic |
| appDataSchema | Schema validation for the appData parameter structure |
| resourceData | Specific implementation details of the protocol |
| requestDemo | Request demo (for developer reference only) |
| responseDemo | Response demo (for developer reference only) |
| operation | Operation type; e.g., softInsert, softUpdate, softDelete, select |
3. resourceHook
The resourceHook allows execution of pre and post service methods around operations defined in the _resource table’s resourceData.
This enables you to run business logic before or after the database operation.
3.1 Example
{"before": [{ "service": "service文件名", "serviceFunction": "service方法名" }],"after": [{ "service": "service文件名", "serviceFunction": "service方法名" }]}
before: executed before the SQL operation. The framework middlewarehttpResourceHook.jsreads and calls the specifiedservicemethod.after: executed after the SQL operation. The framework middlewarehttpResourceHook.jsreads and calls the specifiedservicemethod.
3.2 Implementation Logic
if (beforeHooks) {for (const beforeHook of beforeHooks) {const { service, serviceFunction } = beforeHook;checkServiceFunction(service, serviceFunction);await ctx.service[service][serviceFunction](ctx.request.body.appData.actionData, ctx);}}if (afterHooks) {for (const afterHook of afterHooks) {const { service, serviceFunction } = afterHook;checkServiceFunction(service, serviceFunction);await ctx.service[service][serviceFunction](ctx.request.body.appData.actionData, ctx);}}