DTO、工具与通用服务

1.PaginationDto

分页 DTO 基类:
export class PaginationDto { page?: number = 1; pageSize?: number = 15;
}

2.buildWhere

用于忽略undefined条件,简化列表查询:
const where = buildWhere<Article>({ status, categoryId, title: title ? Like(`%${title}%`) : undefined,
});

3.DictService

适合存放平台配置、运营配置、页面配置。
读取:
const config = await this.dictService.get("home_config", {}, "website");
带文件 URL 恢复:
const config = await this.dictService.get("hero", {}, "website", { restoreFileUrlFields: ["cover", "items.*.icon"],
});
写入:
await this.dictService.set("home_config", payload, { group: "website", normalizeFileUrlFields: ["cover", "items.*.icon"],
});

4.FileStorageService

负责物理落盘:
提交 Multer 文件
提交 Buffer
提交远程文件
按类型/日期生成目录

5.FileUrlService

负责相对路径与完整 URL 互转:
set(url):完整 URL 入库前转相对路径
get(path):读取时补完整域名

6.SecretService

用于管理结构化密钥配置,适合:
AI Provider 密钥
支付密钥
第三方 API Key / Secret
如果是敏感密钥配置,优先考虑SecretService,不要直接扔进普通字典。

319 篇文档 · 内容同步自官方帮助中心