feat: 增加模板版本回滚能力
This commit is contained in:
1 parent
74feb3579c
commit
4191ba8df5
3 files changed
+50
No files matched your search
@@ -73,6 +73,14 @@ export function WorkspacePage() {
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-template-preview"] });
|
||||
},
|
||||
});
|
||||
const rollback = useMutation({
|
||||
mutationFn: () => client.rollbackAdminTemplate(),
|
||||
onSuccess: () => {
|
||||
message.success("模板版本已回滚,现有内容未删除");
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-workspace"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-template-preview"] });
|
||||
},
|
||||
});
|
||||
const createForm = useMutation({
|
||||
mutationFn: (values: { name: string; fieldsSnapshot: unknown[] }) =>
|
||||
client.createAdminInquiryForm(values),
|
||||
@@ -162,8 +170,14 @@ export function WorkspacePage() {
|
||||
) : (
|
||||
<Tag color="green">已是最新版本</Tag>
|
||||
)}
|
||||
{templatePreview.data?.canRollback && (
|
||||
<Button danger onClick={() => rollback.mutate()} loading={rollback.isPending}>
|
||||
回滚到上一版本
|
||||
</Button>
|
||||
)}
|
||||
<MutationError error={templatePreview.error} />
|
||||
<MutationError error={upgrade.error} />
|
||||
<MutationError error={rollback.error} />
|
||||
</Space>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -349,6 +349,7 @@ export class ApiClient {
|
||||
currentVersion: string;
|
||||
latestVersion: string;
|
||||
canUpgrade: boolean;
|
||||
canRollback: boolean;
|
||||
missingModules: unknown[];
|
||||
missingFields: unknown[];
|
||||
}> {
|
||||
@@ -357,6 +358,9 @@ export class ApiClient {
|
||||
upgradeAdminTemplate(): Promise<unknown> {
|
||||
return this.request("/admin/workspace/template/upgrade", { method: "POST" });
|
||||
}
|
||||
rollbackAdminTemplate(): Promise<unknown> {
|
||||
return this.request("/admin/workspace/template/rollback", { method: "POST" });
|
||||
}
|
||||
updateAdminModule(id: string, body: Partial<BrandModule>): Promise<BrandModule> {
|
||||
return this.request(`/admin/workspace/modules/${encodeURIComponent(id)}`, {
|
||||
method: "PATCH",
|
||||
|
||||
Reference in new issue
Block a user