feat: 增加模板版本回滚能力

This commit is contained in:
que01 committed 2026-09-20 22:38:31 +08:00
1 parent 74feb3579c
commit 4191ba8df5
3 files changed
+50

No files matched your search

+32
View File
@@ -420,6 +420,8 @@ export class AdminWorkspaceController {
currentVersion: installation.templateVersion,
latestVersion: template.version,
canUpgrade: installation.templateVersion !== template.version,
canRollback:
Array.isArray(installation.previousSnapshots) && installation.previousSnapshots.length > 0,
missingModules,
missingFields,
};
@@ -489,6 +491,36 @@ export class AdminWorkspaceController {
});
}
@Post("template/rollback")
async rollbackTemplate(@Req() request: FastifyRequest): Promise<unknown> {
this.requireAdmin(request);
const installation = await this.prisma.brandTemplateInstallation.findFirst({
where: { brandId: this.brandId() },
});
if (!installation) throw new BadRequestException("尚未安装行业模板");
const history = Array.isArray(installation.previousSnapshots)
? installation.previousSnapshots
: [];
const previous = history.at(-1);
if (!previous || typeof previous !== "object" || Array.isArray(previous))
throw new BadRequestException("没有可回滚的模板版本");
const previousVersion = (previous as { version?: unknown }).version;
if (typeof previousVersion !== "string") throw new BadRequestException("模板快照无效");
const remaining = history.slice(0, -1);
const updated = await this.prisma.brandTemplateInstallation.update({
where: { id: installation.id },
data: {
templateVersion: previousVersion,
configSnapshot: previous as Prisma.InputJsonValue,
previousSnapshots: remaining as Prisma.InputJsonValue,
},
});
return {
installation: updated,
note: "已回滚模板版本,现有模块、字段和业务内容未删除。",
};
}
@Patch("modules/:id")
async updateModule(
@Req() request: FastifyRequest,