|
|
@@ -93,6 +93,7 @@ export default yourEntityRoutes;
|
|
|
| `relations` | `string[]` | 关联查询配置,指定需要关联查询的关系 | 否 |
|
|
|
| `middleware` | `any[]` | 应用于所有CRUD路由的中间件数组 | 否 |
|
|
|
| `relationFields` | `RelationFieldOptions` | 多对多关联字段配置,支持通过ID数组操作关联关系 | 否 |
|
|
|
+| `readOnly` | `boolean` | 只读模式,只生成GET路由,默认false | 否 |
|
|
|
|
|
|
### 2.3 生成的路由
|
|
|
|
|
|
@@ -106,6 +107,34 @@ export default yourEntityRoutes;
|
|
|
| PUT | `/{id}` | 更新实体 |
|
|
|
| DELETE | `/{id}` | 删除实体 |
|
|
|
|
|
|
+#### 2.3.1 只读模式 (readOnly)
|
|
|
+
|
|
|
+通过设置 `readOnly: true` 可以创建只读路由,仅包含读取操作:
|
|
|
+
|
|
|
+| 方法 | 路径 | 描述 |
|
|
|
+|------|------|------|
|
|
|
+| GET | `/` | 获取实体列表(支持分页、搜索、排序、关联查询) |
|
|
|
+| GET | `/{id}` | 获取单个实体详情(支持关联查询) |
|
|
|
+
|
|
|
+**使用示例:**
|
|
|
+```typescript
|
|
|
+const readOnlyRoutes = createCrudRoutes({
|
|
|
+ entity: Advertisement,
|
|
|
+ createSchema: CreateAdvertisementDto,
|
|
|
+ updateSchema: UpdateAdvertisementDto,
|
|
|
+ getSchema: AdvertisementSchema,
|
|
|
+ listSchema: AdvertisementSchema,
|
|
|
+ readOnly: true, // 启用只读模式
|
|
|
+ searchFields: ['title', 'description'],
|
|
|
+ relations: ['imageFile'],
|
|
|
+});
|
|
|
+```
|
|
|
+
|
|
|
+**适用场景:**
|
|
|
+- 公开API接口(如游客访问的广告列表)
|
|
|
+- 只读数据展示
|
|
|
+- 需要限制修改操作的接口
|
|
|
+
|
|
|
### 2.4 路由注册
|
|
|
|
|
|
生成的路由需要在API入口文件中注册:
|